analytics: Convert datetime to UNIX timestamp before JSON serialization.

datetime objects are not ordinarily JSON serializable.  While both
ujson and orjson have special cases to serialize datetime objects,
they do it in different ways.  So we want to do this explicitly.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-08-06 23:21:19 -07:00 committed by Tim Abbott
parent 219fc36051
commit 02fcb75ded
1 changed files with 4 additions and 1 deletions

View File

@ -301,7 +301,10 @@ def get_chart_data(request: HttpRequest, user_profile: UserProfile, chart_name:
assert len({stat.frequency for stat in stats}) == 1 assert len({stat.frequency for stat in stats}) == 1
end_times = time_range(start, end, stats[0].frequency, min_length) end_times = time_range(start, end, stats[0].frequency, min_length)
data: Dict[str, Any] = {'end_times': end_times, 'frequency': stats[0].frequency} data: Dict[str, Any] = {
'end_times': [int(end_time.timestamp()) for end_time in end_times],
'frequency': stats[0].frequency,
}
aggregation_level = { aggregation_level = {
InstallationCount: 'everyone', InstallationCount: 'everyone',