stats.js: Move name_map computation to the backend.

This commit is contained in:
Rishi Gupta
2017-02-08 17:55:18 -08:00
committed by Tim Abbott
parent 8ad7c96382
commit ce89c64f43
3 changed files with 44 additions and 51 deletions

View File

@@ -1,5 +1,6 @@
from __future__ import absolute_import, division
from django.conf import settings
from django.core import urlresolvers
from django.db import connection
from django.db.models import Sum
@@ -65,12 +66,13 @@ def get_chart_data(request, user_profile, chart_name=REQ(),
stat = COUNT_STATS['messages_sent:message_type:day']
tables = [RealmCount, UserCount]
subgroups = ['public_stream', 'private_stream', 'private_message']
labels = None
labels = ['Public Streams', 'Private Streams', 'Private Messages']
include_empty_subgroups = True
elif chart_name == 'messages_sent_by_client':
stat = COUNT_STATS['messages_sent:client:day']
tables = [RealmCount, UserCount]
subgroups = [str(x) for x in Client.objects.values_list('id', flat=True).order_by('id')]
# these are further re-written by client_label_map
labels = list(Client.objects.values_list('name', flat=True).order_by('id'))
include_empty_subgroups = False
else:
@@ -134,6 +136,10 @@ def client_label_map(name):
return "Python API"
if name.startswith("Zulip") and name.endswith("Webhook"):
return name[len("Zulip"):-len("Webhook")] + " webhook"
# Clients in dev environment autogenerated data start with _ so
# that it's easy to manually drop without affecting other data.
if settings.DEVELOPMENT and name.startswith("_"):
return name[1:]
return name
def rewrite_client_arrays(value_arrays):