mirror of
https://github.com/zulip/zulip.git
synced 2026-07-15 21:03:26 +08:00
Add a "General" tab to the /activity summary report.
It shows domains and how many active users they have. A user is consider active if they have done something at least as active as updating their pointer in the last day. Domains with no meaningful activity in the last two weeks are excluded from the report. (imported from commit 700cecfc7f1732e9ac3ea590177da18f75b01303)
This commit is contained in:
parent
6b5d569888
commit
430aee6f87
30
templates/zerver/realm_summary_table.html
Normal file
30
templates/zerver/realm_summary_table.html
Normal file
@ -0,0 +1,30 @@
|
||||
<table class="table sortable table-striped table-bordered">
|
||||
|
||||
<thead class="activity_head">
|
||||
<tr>
|
||||
<th>Domain</th>
|
||||
<th>Active User Count</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{% for row in rows %}
|
||||
<tr>
|
||||
|
||||
{# Domain #}
|
||||
<td>
|
||||
<a href="?realm={{ row.domain }}">
|
||||
{{ row.domain }}
|
||||
</a>
|
||||
</td>
|
||||
|
||||
{# Active User Count #}
|
||||
<td class="number">
|
||||
{{ row.active_user_count }}
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
@ -1834,6 +1834,67 @@ class ActivityTable(object):
|
||||
def content(self):
|
||||
return loader.render_to_string('zerver/activity_table.html', dict(table=self))
|
||||
|
||||
|
||||
def dictfetchall(cursor):
|
||||
"Returns all rows from a cursor as a dict"
|
||||
desc = cursor.description
|
||||
return [
|
||||
dict(zip([col[0] for col in desc], row))
|
||||
for row in cursor.fetchall()
|
||||
]
|
||||
|
||||
def realm_summary_table():
|
||||
query = '''
|
||||
SELECT
|
||||
realm.domain,
|
||||
coalesce(user_counts.active_user_count, 0) active_user_count
|
||||
FROM zerver_realm realm
|
||||
LEFT OUTER JOIN
|
||||
(
|
||||
SELECT
|
||||
up.realm_id realm_id,
|
||||
count(distinct(ua.user_profile_id)) active_user_count
|
||||
FROM zerver_useractivity ua
|
||||
JOIN zerver_userprofile up
|
||||
ON up.id = ua.user_profile_id
|
||||
WHERE
|
||||
query in (
|
||||
'/json/send_message',
|
||||
'/json/update_pointer'
|
||||
)
|
||||
AND
|
||||
last_visit > now() - interval '1 day'
|
||||
GROUP BY realm_id
|
||||
) user_counts
|
||||
ON user_counts.realm_id = realm.id
|
||||
WHERE EXISTS (
|
||||
SELECT *
|
||||
FROM zerver_useractivity ua
|
||||
JOIN zerver_userprofile up
|
||||
ON up.id = ua.user_profile_id
|
||||
WHERE
|
||||
query in (
|
||||
'/json/send_message',
|
||||
'/json/update_pointer'
|
||||
)
|
||||
AND
|
||||
up.realm_id = realm.id
|
||||
AND
|
||||
last_visit > now() - interval '2 week'
|
||||
)
|
||||
ORDER BY active_user_count DESC, domain ASC
|
||||
'''
|
||||
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(query)
|
||||
rows = dictfetchall(cursor)
|
||||
cursor.close()
|
||||
content = loader.render_to_string(
|
||||
'zerver/realm_summary_table.html',
|
||||
dict(rows=rows)
|
||||
)
|
||||
return dict(content=content)
|
||||
|
||||
def can_view_activity(request):
|
||||
return request.user.realm.domain == 'zulip.com'
|
||||
|
||||
@ -1854,7 +1915,12 @@ def get_activity(request, realm=REQ(default=None)):
|
||||
("send_message", ["/api/v1/send_message"]),
|
||||
)
|
||||
|
||||
data = [
|
||||
data = []
|
||||
|
||||
if realm is None:
|
||||
data.append(('General', realm_summary_table()))
|
||||
|
||||
data += [
|
||||
('Website', ActivityTable(realm, 'website', web_queries)),
|
||||
('Mirror', ActivityTable(realm, 'zephyr_mirror', api_queries)),
|
||||
('Desktop', ActivityTable(realm, 'desktop', api_queries)),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user