forked from shaba/openuds
fixed pools usage summary report
This commit is contained in:
parent
222ed0e9b0
commit
aa3744094b
@ -60,32 +60,39 @@ class PoolsUsageSummary(UsageByPool):
|
||||
totalTime: int = 0
|
||||
totalCount: int = 0
|
||||
|
||||
uniqueUsers = set()
|
||||
|
||||
for v in orig:
|
||||
uuid = v['pool']
|
||||
if uuid not in pools:
|
||||
pools[uuid] = {
|
||||
'name': v['pool_name'],
|
||||
'time': 0,
|
||||
'count': 0
|
||||
'count': 0,
|
||||
'users': set()
|
||||
}
|
||||
logger.debug('V: %s', v)
|
||||
pools[uuid]['time'] += v['time']
|
||||
pools[uuid]['count'] += 1
|
||||
# Now add user id to pool
|
||||
pools[uuid]['users'].add(v['name'])
|
||||
uniqueUsers.add(v['name'])
|
||||
|
||||
totalTime += v['time']
|
||||
totalCount += 1
|
||||
|
||||
logger.debug('Pools: \n%s\n', pools)
|
||||
logger.debug('Pools %s', pools)
|
||||
# Remove unique users, and keep only counts...
|
||||
for pn in pools:
|
||||
pools[pn]['users'] = len(pools[pn]['users'])
|
||||
|
||||
return pools.values(), totalTime, totalCount
|
||||
return pools.values(), totalTime, totalCount, len(uniqueUsers)
|
||||
|
||||
def generate(self):
|
||||
pools, totalTime, totalCount = self.getData()
|
||||
pools, totalTime, totalCount, uniqueUsers = self.getData()
|
||||
|
||||
start = self.startDate.value
|
||||
end = self.endDate.value
|
||||
|
||||
|
||||
logger.debug('Pools: %s --- %s --- %s', pools, totalTime, totalCount)
|
||||
|
||||
return self.templateAsPDF(
|
||||
@ -95,12 +102,14 @@ class PoolsUsageSummary(UsageByPool):
|
||||
{
|
||||
'name': p['name'],
|
||||
'time': str(datetime.timedelta(seconds=p['time'])),
|
||||
'count': p['count']
|
||||
'count': p['count'],
|
||||
'users': p['users']
|
||||
}
|
||||
for p in pools
|
||||
),
|
||||
'time': str(datetime.timedelta(seconds=totalTime)),
|
||||
'count': totalCount,
|
||||
'users': uniqueUsers,
|
||||
'start': start,
|
||||
'end': end,
|
||||
},
|
||||
@ -123,13 +132,13 @@ class PoolsUsageSummaryCSV(PoolsUsageSummary):
|
||||
output = io.StringIO()
|
||||
writer = csv.writer(output)
|
||||
|
||||
reportData, totalTime, totalCount = self.getData()
|
||||
reportData, totalTime, totalCount, totalUsers = self.getData()
|
||||
|
||||
writer.writerow([ugettext('Pool'), ugettext('Total Time (seconds)'), ugettext('Total Accesses')])
|
||||
|
||||
for v in reportData:
|
||||
writer.writerow([v['name'], v['time'], v['count']])
|
||||
writer.writerow([v['name'], v['time'], v['count'], v['users']])
|
||||
|
||||
writer.writerow([ugettext('Total'), totalTime, totalCount])
|
||||
writer.writerow([ugettext('Total'), totalTime, totalCount, totalUsers])
|
||||
|
||||
return output.getvalue()
|
||||
|
@ -11,9 +11,10 @@
|
||||
<table style="width: 100%; font-size: 0.8em;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 20%">{% trans 'Pool' %}</th>
|
||||
<th style="width: 15%">{% trans 'Total time' %}</th>
|
||||
<th style="width: 25%">{% trans 'Total accesses' %}</th>
|
||||
<th style="width: 40%">{% trans 'Pool' %}</th>
|
||||
<th style="width: 20%">{% trans 'Total time' %}</th>
|
||||
<th style="width: 20%">{% trans 'Total accesses' %}</th>
|
||||
<th style="width: 20%">{% trans 'Unique users' %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -22,12 +23,14 @@
|
||||
<td>{{ pool.name }}</td>
|
||||
<td>{{ pool.time }}</td>
|
||||
<td>{{ pool.count }}</td>
|
||||
<td>{{ pool.users }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
<td>{% trans 'Total' %}</td>
|
||||
<td>{{ time }}</td>
|
||||
<td>{{ count }}</td>
|
||||
<td>{{ users }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
Loading…
Reference in New Issue
Block a user