From d4c0334b3b5e1280bf8b4ec410afcc261910194b Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Thu, 14 Nov 2013 13:50:32 -0500 Subject: [PATCH] Show counts of at-risk users on Activity page. (imported from commit 4ce1ecf47259f3a95ddf9cbbc356fa0247044e0f) --- analytics/views.py | 31 ++++++++++++++++++++ templates/analytics/realm_summary_table.html | 6 ++++ 2 files changed, 37 insertions(+) diff --git a/analytics/views.py b/analytics/views.py index c99efe30ef..bbdaac34e0 100644 --- a/analytics/views.py +++ b/analytics/views.py @@ -37,6 +37,7 @@ def realm_summary_table(realm_minutes): SELECT realm.domain, coalesce(user_counts.active_user_count, 0) active_user_count, + coalesce(at_risk_counts.at_risk_count, 0) at_risk_count, ( SELECT count(*) @@ -75,6 +76,36 @@ def realm_summary_table(realm_minutes): GROUP BY realm_id ) user_counts ON user_counts.realm_id = realm.id + LEFT OUTER JOIN + ( + SELECT + realm_id, + count(*) at_risk_count + FROM ( + SELECT + realm.id as realm_id, + up.email + FROM zerver_useractivity ua + JOIN zerver_userprofile up + ON up.id = ua.user_profile_id + JOIN zerver_realm realm + ON realm.id = up.realm_id + WHERE up.is_active + AND (not up.is_bot) + AND + ua.query in ( + '/json/send_message', + 'send_message_backend', + '/json/update_pointer' + ) + GROUP by realm.id, up.email + HAVING max(last_visit) between + now() - interval '7 day' and + now() - interval '1 day' + ) as at_risk_users + GROUP BY realm_id + ) at_risk_counts + ON at_risk_counts.realm_id = realm.id WHERE realm.domain not in ('zulip.com', 'customer4.invalid', 'wdaher.com') AND EXISTS ( diff --git a/templates/analytics/realm_summary_table.html b/templates/analytics/realm_summary_table.html index 935480b2d1..a121a1ce8b 100644 --- a/templates/analytics/realm_summary_table.html +++ b/templates/analytics/realm_summary_table.html @@ -6,6 +6,7 @@ Domain Active users + At-risk users Total users Bots Hours per user @@ -27,6 +28,11 @@ {{ row.active_user_count }} + {# At risk users #} + + {{ row.at_risk_count }} + + {# Total users #} {{ row.user_profile_count }}