analytics: Fix uses of 'interval' in arguments and variable names.

interval refers to a time interval, and frequency refers to something that
semantically means something closer to 'hourly' or 'daily'.

Currently, interval can have values 'hour', 'day', or 'gauge', and frequency
can only have values 'hour' and 'day'.
This commit is contained in:
Rishi Gupta
2017-01-06 18:53:08 -08:00
committed by Tim Abbott
parent f5899dd14b
commit f8962d521d
2 changed files with 9 additions and 8 deletions

View File

@@ -8,16 +8,16 @@ from typing import List, Optional
# If min_length is greater than 0, pads the list to the left.
# So informally, time_range(Sep 20, Sep 22, day, None) returns [Sep 20, Sep 21, Sep 22],
# and time_range(Sep 20, Sep 22, day, 5) returns [Sep 18, Sep 19, Sep 20, Sep 21, Sep 22]
def time_range(start, end, interval, min_length):
def time_range(start, end, frequency, min_length):
# type: (datetime, datetime, str, Optional[int]) -> List[datetime]
if interval == CountStat.HOUR:
if frequency == CountStat.HOUR:
end = ceiling_to_hour(end)
step = timedelta(hours=1)
elif interval == CountStat.DAY:
elif frequency == CountStat.DAY:
end = ceiling_to_day(end)
step = timedelta(days=1)
else:
raise ValueError(_("Unknown interval."))
raise ValueError("Unknown frequency: %s" % (frequency,))
times = []
if min_length is not None:

View File

@@ -60,14 +60,14 @@ def get_messages_sent_to_realm(realm, min_length=None, start=None, end=None):
if start > end:
raise JsonableError(_("Start time is later than end time. Start: %(start)s, End: %(end)s") %
{'start': start, 'end': end})
interval = CountStat.DAY
end_times = time_range(start, end, interval, min_length)
frequency = CountStat.DAY
end_times = time_range(start, end, frequency, min_length)
indices = {}
for i, end_time in enumerate(end_times):
indices[end_time] = i
filter_set = RealmCount.objects.filter(
realm=realm, property='messages_sent:is_bot', interval=interval) \
realm=realm, property='messages_sent:is_bot', interval=frequency) \
.values_list('end_time', 'value')
humans = [0]*len(end_times)
for end_time, value in filter_set.filter(subgroup=False):
@@ -76,7 +76,8 @@ def get_messages_sent_to_realm(realm, min_length=None, start=None, end=None):
for end_time, value in filter_set.filter(subgroup=True):
bots[indices[end_time]] = value
return {'end_times': end_times, 'humans': humans, 'bots': bots, 'interval': interval}
return {'end_times': end_times, 'humans': humans, 'bots': bots,
'frequency': frequency, 'interval': frequency}
eastern_tz = pytz.timezone('US/Eastern')