Skip to content

Commit

Permalink
analytics: Add backend for messages read over time graph.
Browse files Browse the repository at this point in the history
This commit includes changes in the api /json/analytics/chart_data to
send data for the newly added graph, as well as tests.
  • Loading branch information
arpit551 authored and timabbott committed Jun 15, 2020
1 parent a4b857b commit aa70bab
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions analytics/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ def test_messages_sent_by_client(self) -> None:
'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:
FillState.objects.create(
property='realm_active_humans::day', end_time=self.end_times_day[0],
Expand Down
6 changes: 6 additions & 0 deletions analytics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')}}
labels_sort_function = sort_client_labels
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:
raise JsonableError(_("Unknown chart name: %s") % (chart_name,))

Expand Down

0 comments on commit aa70bab

Please sign in to comment.