mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 19:31:58 +00:00
stats.js: Move name_map computation to the backend.
This commit is contained in:
@@ -47,7 +47,7 @@ class Command(BaseCommand):
|
|||||||
do_drop_all_analytics_tables()
|
do_drop_all_analytics_tables()
|
||||||
# I believe this also deletes any objects with this realm as a foreign key
|
# I believe this also deletes any objects with this realm as a foreign key
|
||||||
Realm.objects.filter(string_id='analytics').delete()
|
Realm.objects.filter(string_id='analytics').delete()
|
||||||
Client.objects.filter(name__endswith='_').delete()
|
Client.objects.filter(name__startswith='_').delete()
|
||||||
|
|
||||||
installation_time = timezone.now() - timedelta(days=self.DAYS_OF_DATA)
|
installation_time = timezone.now() - timedelta(days=self.DAYS_OF_DATA)
|
||||||
last_end_time = floor_to_day(timezone.now())
|
last_end_time = floor_to_day(timezone.now())
|
||||||
@@ -101,29 +101,33 @@ class Command(BaseCommand):
|
|||||||
FillState.objects.create(property=stat.property, end_time=last_end_time,
|
FillState.objects.create(property=stat.property, end_time=last_end_time,
|
||||||
state=FillState.DONE)
|
state=FillState.DONE)
|
||||||
|
|
||||||
website_ = Client.objects.create(name='website_')
|
# We use client names that start with _ to make it easy to
|
||||||
API_ = Client.objects.create(name='API_')
|
# drop just these data manually without affecting other data.
|
||||||
android_ = Client.objects.create(name='android_')
|
website = Client.objects.create(name='_Website')
|
||||||
iOS_ = Client.objects.create(name='iOS_')
|
old_desktop = Client.objects.create(name='_Old desktop app')
|
||||||
react_native_ = Client.objects.create(name='react_native_')
|
android = Client.objects.create(name='_Android app')
|
||||||
electron_ = Client.objects.create(name='electron_')
|
iOS = Client.objects.create(name='_Old iOS app')
|
||||||
barnowl_ = Client.objects.create(name='barnowl_')
|
react_native = Client.objects.create(name='_New iOS app')
|
||||||
plan9_ = Client.objects.create(name='plan9_')
|
API = Client.objects.create(name='_Python API')
|
||||||
|
barnowl = Client.objects.create(name='_Barnowl')
|
||||||
|
unused = Client.objects.create(name='_Unused webhook')
|
||||||
|
long_webhook = Client.objects.create(name='_Webhook with loooooooong name')
|
||||||
|
|
||||||
stat = COUNT_STATS['messages_sent:client:day']
|
stat = COUNT_STATS['messages_sent:client:day']
|
||||||
user_data = {
|
user_data = {
|
||||||
website_.id: self.generate_fixture_data(stat, 2, 1, 1.5, .6, 8),
|
website.id: self.generate_fixture_data(stat, 2, 1, 1.5, .6, 8),
|
||||||
barnowl_.id: self.generate_fixture_data(stat, 0, .3, 1.5, .6, 8)}
|
barnowl.id: self.generate_fixture_data(stat, 0, .3, 1.5, .6, 8)}
|
||||||
insert_fixture_data(stat, user_data, UserCount)
|
insert_fixture_data(stat, user_data, UserCount)
|
||||||
realm_data = {
|
realm_data = {
|
||||||
website_.id: self.generate_fixture_data(stat, 30, 20, 5, .6, 3),
|
website.id: self.generate_fixture_data(stat, 30, 20, 5, .6, 3),
|
||||||
API_.id: self.generate_fixture_data(stat, 5, 5, 5, .6, 3),
|
old_desktop.id: self.generate_fixture_data(stat, 5, 3, 8, .6, 3),
|
||||||
android_.id: self.generate_fixture_data(stat, 5, 5, 2, .6, 3),
|
android.id: self.generate_fixture_data(stat, 5, 5, 2, .6, 3),
|
||||||
iOS_.id: self.generate_fixture_data(stat, 5, 5, 2, .6, 3),
|
iOS.id: self.generate_fixture_data(stat, 5, 5, 2, .6, 3),
|
||||||
react_native_.id: self.generate_fixture_data(stat, 5, 5, 10, .6, 3),
|
react_native.id: self.generate_fixture_data(stat, 5, 5, 10, .6, 3),
|
||||||
electron_.id: self.generate_fixture_data(stat, 5, 3, 8, .6, 3),
|
API.id: self.generate_fixture_data(stat, 5, 5, 5, .6, 3),
|
||||||
barnowl_.id: self.generate_fixture_data(stat, 1, 1, 3, .6, 3),
|
barnowl.id: self.generate_fixture_data(stat, 1, 1, 3, .6, 3),
|
||||||
plan9_.id: self.generate_fixture_data(stat, 0, 0, 0, 0, 0, 0)}
|
unused.id: self.generate_fixture_data(stat, 0, 0, 0, 0, 0),
|
||||||
|
long_webhook.id: self.generate_fixture_data(stat, 5, 5, 2, .6, 3)}
|
||||||
insert_fixture_data(stat, realm_data, RealmCount)
|
insert_fixture_data(stat, realm_data, RealmCount)
|
||||||
FillState.objects.create(property=stat.property, end_time=last_end_time,
|
FillState.objects.create(property=stat.property, end_time=last_end_time,
|
||||||
state=FillState.DONE)
|
state=FillState.DONE)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from __future__ import absolute_import, division
|
from __future__ import absolute_import, division
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.core import urlresolvers
|
from django.core import urlresolvers
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.db.models import Sum
|
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']
|
stat = COUNT_STATS['messages_sent:message_type:day']
|
||||||
tables = [RealmCount, UserCount]
|
tables = [RealmCount, UserCount]
|
||||||
subgroups = ['public_stream', 'private_stream', 'private_message']
|
subgroups = ['public_stream', 'private_stream', 'private_message']
|
||||||
labels = None
|
labels = ['Public Streams', 'Private Streams', 'Private Messages']
|
||||||
include_empty_subgroups = True
|
include_empty_subgroups = True
|
||||||
elif chart_name == 'messages_sent_by_client':
|
elif chart_name == 'messages_sent_by_client':
|
||||||
stat = COUNT_STATS['messages_sent:client:day']
|
stat = COUNT_STATS['messages_sent:client:day']
|
||||||
tables = [RealmCount, UserCount]
|
tables = [RealmCount, UserCount]
|
||||||
subgroups = [str(x) for x in Client.objects.values_list('id', flat=True).order_by('id')]
|
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'))
|
labels = list(Client.objects.values_list('name', flat=True).order_by('id'))
|
||||||
include_empty_subgroups = False
|
include_empty_subgroups = False
|
||||||
else:
|
else:
|
||||||
@@ -134,6 +136,10 @@ def client_label_map(name):
|
|||||||
return "Python API"
|
return "Python API"
|
||||||
if name.startswith("Zulip") and name.endswith("Webhook"):
|
if name.startswith("Zulip") and name.endswith("Webhook"):
|
||||||
return name[len("Zulip"):-len("Webhook")] + " 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
|
return name
|
||||||
|
|
||||||
def rewrite_client_arrays(value_arrays):
|
def rewrite_client_arrays(value_arrays):
|
||||||
|
|||||||
@@ -349,7 +349,7 @@ function make_pie_trace(values, labels, text) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function compute_pie_chart_data(name_map, time_series_data, num_steps) {
|
function compute_pie_chart_data(time_series_data, num_steps) {
|
||||||
var data = [];
|
var data = [];
|
||||||
for (var key in time_series_data) {
|
for (var key in time_series_data) {
|
||||||
if (time_series_data[key].length < num_steps) {
|
if (time_series_data[key].length < num_steps) {
|
||||||
@@ -362,7 +362,7 @@ function compute_pie_chart_data(name_map, time_series_data, num_steps) {
|
|||||||
if (sum > 0) {
|
if (sum > 0) {
|
||||||
data.push({
|
data.push({
|
||||||
value: sum,
|
value: sum,
|
||||||
label: word_wrap(name_map.hasOwnProperty(key) ? name_map[key] : key, 18),
|
label: word_wrap(key, 18),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -397,17 +397,6 @@ function compute_pie_chart_data(name_map, time_series_data, num_steps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function populate_messages_sent_by_client(data) {
|
function populate_messages_sent_by_client(data) {
|
||||||
// Hardcoded names in the development environment
|
|
||||||
var name_map = {
|
|
||||||
electron_: "Electron",
|
|
||||||
barnowl_: "BarnOwl",
|
|
||||||
website_: "Website",
|
|
||||||
API_: "API",
|
|
||||||
android_: "Android",
|
|
||||||
iOS_: "iOS",
|
|
||||||
react_native_: "React Native",
|
|
||||||
};
|
|
||||||
|
|
||||||
var layout = {
|
var layout = {
|
||||||
margin: { l: 90, r: 0, b: 0, t: 0 },
|
margin: { l: 90, r: 0, b: 0, t: 0 },
|
||||||
width: 450,
|
width: 450,
|
||||||
@@ -417,14 +406,14 @@ function populate_messages_sent_by_client(data) {
|
|||||||
|
|
||||||
var chart_data = {
|
var chart_data = {
|
||||||
realm: {
|
realm: {
|
||||||
cumulative: compute_pie_chart_data(name_map, data.realm, data.end_times.length),
|
cumulative: compute_pie_chart_data(data.realm, data.end_times.length),
|
||||||
thirty: compute_pie_chart_data(name_map, data.realm, 30),
|
thirty: compute_pie_chart_data(data.realm, 30),
|
||||||
ten: compute_pie_chart_data(name_map, data.realm, 10),
|
ten: compute_pie_chart_data(data.realm, 10),
|
||||||
},
|
},
|
||||||
user: {
|
user: {
|
||||||
cumulative: compute_pie_chart_data(name_map, data.user, data.end_times.length),
|
cumulative: compute_pie_chart_data(data.user, data.end_times.length),
|
||||||
thirty: compute_pie_chart_data(name_map, data.user, 30),
|
thirty: compute_pie_chart_data(data.user, 30),
|
||||||
ten: compute_pie_chart_data(name_map, data.user, 10),
|
ten: compute_pie_chart_data(data.user, 10),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -515,12 +504,6 @@ $.get({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function populate_messages_sent_by_message_type(data) {
|
function populate_messages_sent_by_message_type(data) {
|
||||||
var name_map = {
|
|
||||||
public_stream: "Public Stream",
|
|
||||||
private_stream: "Private Stream",
|
|
||||||
private_message: "Private Message",
|
|
||||||
};
|
|
||||||
|
|
||||||
var layout = {
|
var layout = {
|
||||||
margin: { l: 90, r: 0, b: 0, t: 0 },
|
margin: { l: 90, r: 0, b: 0, t: 0 },
|
||||||
width: 465,
|
width: 465,
|
||||||
@@ -530,14 +513,14 @@ function populate_messages_sent_by_message_type(data) {
|
|||||||
|
|
||||||
var chart_data = {
|
var chart_data = {
|
||||||
realm: {
|
realm: {
|
||||||
cumulative: compute_pie_chart_data(name_map, data.realm, data.end_times.length),
|
cumulative: compute_pie_chart_data(data.realm, data.end_times.length),
|
||||||
thirty: compute_pie_chart_data(name_map, data.realm, 30),
|
thirty: compute_pie_chart_data(data.realm, 30),
|
||||||
ten: compute_pie_chart_data(name_map, data.realm, 10),
|
ten: compute_pie_chart_data(data.realm, 10),
|
||||||
},
|
},
|
||||||
user: {
|
user: {
|
||||||
cumulative: compute_pie_chart_data(name_map, data.user, data.end_times.length),
|
cumulative: compute_pie_chart_data(data.user, data.end_times.length),
|
||||||
thirty: compute_pie_chart_data(name_map, data.user, 30),
|
thirty: compute_pie_chart_data(data.user, 30),
|
||||||
ten: compute_pie_chart_data(name_map, data.user, 10),
|
ten: compute_pie_chart_data(data.user, 10),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user