Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

activity: Add totals row as sticky footer to activity charts.

Lauryn Menardbfd9eec4b35e
diff --git a/analytics/views/activity_common.py b/analytics/views/activity_common.py
index 1b10d7e3cd2..60a1c4c02c0 100644
--- a/analytics/views/activity_common.py
+++ b/analytics/views/activity_common.py
@@ -31,6 +31,8 @@ def make_table(
title: str,
cols: Sequence[str],
rows: Sequence[Any],
+ *,
+ totals: Optional[Any] = None,
stats_link: Optional[Markup] = None,
has_row_class: bool = False,
) -> str:
@@ -41,7 +43,7 @@ def make_table(
rows = list(map(fix_row, rows))
- data = dict(title=title, cols=cols, rows=rows, stats_link=stats_link)
+ data = dict(title=title, cols=cols, rows=rows, totals=totals, stats_link=stats_link)
content = loader.render_to_string(
"analytics/ad_hoc_query.html",
diff --git a/analytics/views/installation_activity.py b/analytics/views/installation_activity.py
index 58f4aabc360..56cdaf4e37e 100644
--- a/analytics/views/installation_activity.py
+++ b/analytics/views/installation_activity.py
@@ -23,6 +23,7 @@ from analytics.views.activity_common import (
realm_url_link,
)
from analytics.views.support import get_plan_type_string
+from corporate.lib.stripe import cents_to_dollar_string
from zerver.decorator import require_server_admin
from zerver.lib.request import has_request_variables
from zerver.models import Realm
@@ -210,7 +211,7 @@ def realm_summary_table() -> str:
string_id = row["string_id"]
if string_id in estimated_arrs:
- row["arr"] = estimated_arrs[string_id]
+ row["arr"] = f"${cents_to_dollar_string(estimated_arrs[string_id])}"
if row["plan_type"] in [Realm.PLAN_TYPE_STANDARD, Realm.PLAN_TYPE_PLUS]:
row["effective_rate"] = 100 - int(realms_with_default_discount.get(string_id, 0))
@@ -250,28 +251,34 @@ def realm_summary_table() -> str:
total_bot_count += int(row["bot_count"])
total_wau_count += int(row["wau_count"])
- total_row = dict(
- string_id="Total",
- plan_type_string="",
- org_type_string="",
- effective_rate="",
- arr=total_arr,
- realm_url="",
- stats_link="",
- support_link="",
- date_created_day="",
- dau_count=total_dau_count,
- user_profile_count=total_user_profile_count,
- bot_count=total_bot_count,
- wau_count=total_wau_count,
- )
-
- rows.insert(0, total_row)
+ total_row = [
+ "Total",
+ "",
+ "",
+ "",
+ f"${cents_to_dollar_string(total_arr)}",
+ "",
+ "",
+ total_dau_count,
+ total_wau_count,
+ total_user_profile_count,
+ total_bot_count,
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ ]
content = loader.render_to_string(
"analytics/realm_summary_table.html",
dict(
rows=rows,
+ totals=total_row,
num_active_sites=num_active_sites,
utctime=now.strftime("%Y-%m-%d %H:%M %Z"),
billing_enabled=settings.BILLING_ENABLED,
diff --git a/analytics/views/realm_activity.py b/analytics/views/realm_activity.py
index 9301a459e02..948b9500d38 100644
--- a/analytics/views/realm_activity.py
+++ b/analytics/views/realm_activity.py
@@ -145,7 +145,7 @@ def realm_user_summary_table(
return row["cells"][4]
rows = sorted(rows, key=by_last_heard_from, reverse=True)
- content = make_table(title, cols, rows, stats_link, has_row_class=True)
+ content = make_table(title, cols, rows, stats_link=stats_link, has_row_class=True)
return content
diff --git a/analytics/views/remote_activity.py b/analytics/views/remote_activity.py
index a90151364d4..0dac8d2f54e 100644
--- a/analytics/views/remote_activity.py
+++ b/analytics/views/remote_activity.py
@@ -214,9 +214,8 @@ def get_remote_server_activity(request: HttpRequest) -> HttpResponse:
total_row.append(str(sum(row[i] for row in rows if row[i] is not None)))
else:
total_row.append("")
- rows.insert(0, total_row)
- content = make_table(title, cols, rows)
+ content = make_table(title, cols, rows, totals=total_row)
return render(
request,
"analytics/activity_details_template.html",
diff --git a/corporate/lib/analytics.py b/corporate/lib/analytics.py
index 7a885324519..c006edf25d9 100644
--- a/corporate/lib/analytics.py
+++ b/corporate/lib/analytics.py
@@ -70,7 +70,7 @@ def estimate_annual_recurring_revenue_by_realm() -> Dict[str, int]: # nocoverag
).get_customer_plan_renewal_amount(plan, latest_ledger_entry)
if plan.billing_schedule == CustomerPlan.BILLING_SCHEDULE_MONTHLY:
renewal_cents *= 12
- annual_revenue[plan.customer.realm.string_id] = int(renewal_cents / 100)
+ annual_revenue[plan.customer.realm.string_id] = renewal_cents
return annual_revenue
diff --git a/templates/analytics/ad_hoc_query.html b/templates/analytics/ad_hoc_query.html
index da86d953f45..9aba0b81cc5 100644
--- a/templates/analytics/ad_hoc_query.html
+++ b/templates/analytics/ad_hoc_query.html
@@ -23,4 +23,11 @@
</tr>
{% endfor %}
</tbody>
+ {% if data.totals %}
+ <tfoot class="activity-foot">
+ {% for total in data.totals %}
+ <td>{{ total }}</td>
+ {% endfor %}
+ </tfoot>
+ {% endif %}
</table>
diff --git a/templates/analytics/realm_summary_table.html b/templates/analytics/realm_summary_table.html
index c013ce4cfa7..fc671ec5109 100644
--- a/templates/analytics/realm_summary_table.html
+++ b/templates/analytics/realm_summary_table.html
@@ -121,5 +121,9 @@
</tr>
{% endfor %}
</tbody>
-
+ <tfoot class="activity-foot">
+ {% for total in totals %}
+ <td>{{ total }}</td>
+ {% endfor %}
+ </tfoot>
</table>
diff --git a/web/styles/portico/activity.css b/web/styles/portico/activity.css
index c5b109c1536..ea34d8ced05 100644
--- a/web/styles/portico/activity.css
+++ b/web/styles/portico/activity.css
@@ -12,6 +12,13 @@
}
}
+.activity-foot {
+ background-color: hsl(208deg 100% 97%);
+ font-weight: 700;
+ position: sticky;
+ bottom: 0;
+}
+
.table-striped {
& tr.recently_active {
& td {