Skip to content

Commit

Permalink
analytics: Move time computation to later in get_chart_data.
Browse files Browse the repository at this point in the history
  • Loading branch information
rishig authored and timabbott committed Feb 10, 2017
1 parent b22e9a0 commit 6ab31d1
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions analytics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ def get_chart_data(request, user_profile, chart_name=REQ(),
start=REQ(converter=to_utc_datetime, default=None),
end=REQ(converter=to_utc_datetime, default=None)):
# type: (HttpRequest, UserProfile, Text, Optional[int], Optional[datetime], Optional[datetime]) -> HttpResponse
realm = user_profile.realm
# These are implicitly relying on realm.date_created and timezone.now being in UTC.
if start is None:
start = realm.date_created
if end is None:
end = timezone.now()
if start > end:
raise JsonableError(_("Start time is later than end time. Start: %(start)s, End: %(end)s") %
{'start': start, 'end': end})

if chart_name == 'number_of_humans':
stat = COUNT_STATS['active_users:is_bot:day']
tables = [RealmCount]
Expand Down Expand Up @@ -85,6 +75,16 @@ def get_chart_data(request, user_profile, chart_name=REQ(),
else:
raise JsonableError(_("Unknown chart name: %s") % (chart_name,))

realm = user_profile.realm
# These are implicitly relying on realm.date_created and timezone.now being in UTC.
if start is None:
start = realm.date_created
if end is None:
end = timezone.now()
if start > end:
raise JsonableError(_("Start time is later than end time. Start: %(start)s, End: %(end)s") %
{'start': start, 'end': end})

end_times = time_range(start, end, stat.frequency, min_length)
data = {'end_times': end_times, 'frequency': stat.frequency, 'interval': stat.interval}
for table in tables:
Expand Down

0 comments on commit 6ab31d1

Please sign in to comment.