mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 14:35:27 +00:00
analytics: Add backend for messages read over time graph.
This commit includes changes in the api /json/analytics/chart_data to send data for the newly added graph, as well as tests.
This commit is contained in:
@@ -181,6 +181,23 @@ class TestGetChartData(ZulipTestCase):
|
|||||||
'result': 'success',
|
'result': 'success',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def test_messages_read_over_time(self) -> None:
|
||||||
|
stat = COUNT_STATS['messages_read::hour']
|
||||||
|
self.insert_data(stat, [None], [])
|
||||||
|
result = self.client_get('/json/analytics/chart_data',
|
||||||
|
{'chart_name': 'messages_read_over_time'})
|
||||||
|
self.assert_json_success(result)
|
||||||
|
data = result.json()
|
||||||
|
self.assertEqual(data, {
|
||||||
|
'msg': '',
|
||||||
|
'end_times': [datetime_to_timestamp(dt) for dt in self.end_times_hour],
|
||||||
|
'frequency': CountStat.HOUR,
|
||||||
|
'everyone': {'read': self.data(100)},
|
||||||
|
'user': {'read': self.data(0)},
|
||||||
|
'display_order': None,
|
||||||
|
'result': 'success',
|
||||||
|
})
|
||||||
|
|
||||||
def test_include_empty_subgroups(self) -> None:
|
def test_include_empty_subgroups(self) -> None:
|
||||||
FillState.objects.create(
|
FillState.objects.create(
|
||||||
property='realm_active_humans::day', end_time=self.end_times_day[0],
|
property='realm_active_humans::day', end_time=self.end_times_day[0],
|
||||||
|
|||||||
@@ -236,6 +236,12 @@ def get_chart_data(request: HttpRequest, user_profile: UserProfile, chart_name:
|
|||||||
{str(id): name for id, name in Client.objects.values_list('id', 'name')}}
|
{str(id): name for id, name in Client.objects.values_list('id', 'name')}}
|
||||||
labels_sort_function = sort_client_labels
|
labels_sort_function = sort_client_labels
|
||||||
include_empty_subgroups = False
|
include_empty_subgroups = False
|
||||||
|
elif chart_name == 'messages_read_over_time':
|
||||||
|
stats = [COUNT_STATS['messages_read::hour']]
|
||||||
|
tables = [aggregate_table, UserCount]
|
||||||
|
subgroup_to_label = {stats[0]: {None: 'read'}}
|
||||||
|
labels_sort_function = None
|
||||||
|
include_empty_subgroups = True
|
||||||
else:
|
else:
|
||||||
raise JsonableError(_("Unknown chart name: %s") % (chart_name,))
|
raise JsonableError(_("Unknown chart name: %s") % (chart_name,))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user