Fix aggregation to analytics summary tables.

There are a number of different stats that need to be propagated from
UserCount and StreamCount to RealmCount, and from RealmCount to
InstallationCount. Stats with hour intervals also need to have their day
values propagated. This commit fixes a bug in the summary table aggregation
logic so that for a given interval on a CountStat object we pull the correct
counts for the interval as well as do the day aggregation if required. We Also
ensure that any aggregation then done from the realmcount
table to the installationcount table follows the same aggregation logic
for intervals.
This commit is contained in:
umkay
2016-10-05 15:39:35 -07:00
committed by Tim Abbott
parent ff4d059595
commit 01324f2afe

View File

@@ -3,7 +3,7 @@ from datetime import timedelta, datetime
from analytics.models import InstallationCount, RealmCount, \ from analytics.models import InstallationCount, RealmCount, \
UserCount, StreamCount, HuddleCount, BaseCount UserCount, StreamCount, HuddleCount, BaseCount
from analytics.lib.interval import TimeInterval, timeinterval_range from analytics.lib.interval import TimeInterval, timeinterval_range, subintervals
from zerver.models import Realm, UserProfile, Message, Stream, models from zerver.models import Realm, UserProfile, Message, Stream, models
from typing import Any, Optional, Type from typing import Any, Optional, Type
@@ -39,11 +39,10 @@ def process_count_stat(stat, range_start, range_end):
# aggregate to summary tables # aggregate to summary tables
for interval in ['hour', 'day', 'gauge']: for interval in ['hour', 'day', 'gauge']:
for frequency in ['hour', 'day']: for time_interval in timeinterval_range(range_start, range_end, interval, stat.frequency):
for time_interval in timeinterval_range(range_start, range_end, interval, frequency): analytics_table = stat.zerver_count_query.analytics_table
analytics_table = stat.zerver_count_query.analytics_table if stat.smallest_interval in subintervals(interval):
if stat.smallest_interval <= interval and stat.frequency == frequency and \ if analytics_table in (UserCount, StreamCount):
analytics_table in (UserCount, StreamCount):
do_aggregate_to_summary_table(stat, time_interval, analytics_table, RealmCount) do_aggregate_to_summary_table(stat, time_interval, analytics_table, RealmCount)
do_aggregate_to_summary_table(stat, time_interval, RealmCount, InstallationCount) do_aggregate_to_summary_table(stat, time_interval, RealmCount, InstallationCount)