def merge_top_scores(self, day=None): """ Merges daily top scores into monthly and monthly into yearly top scores for this group for the given day and the 365 days before it. If `day` is `None`, defaults to today. """ if not day: day = Services.time.today() # Merge today + last 365 days days = [day - datetime.timedelta(n) for n in range(366)] months = defaultdict(list) for day in days: months[(day.year, day.month)].append(day) years = defaultdict(list) for (year, month) in months.keys(): years[year].append(month) for (year, month), days in months.iteritems(): dest = self.top.month(datetime.date(year, month, 1)) source_keys = [self.top.day(day).key for day in days] redis.zunionstore(dest.key, source_keys, aggregate='max') dest.truncate(2) for year, year_months in years.iteritems(): dest = self.top.year(datetime.date(year, 1, 1)) source_keys = [self.top.month(datetime.date(year, month, 1)).key for month in year_months] redis.zunionstore(dest.key, source_keys, aggregate='max') dest.truncate(5)
def _get_aggregate_rlbb(groups, nav): groups = list(groups) if not groups: return [] else: rlbb = RedisLastBumpedBuffer(gen_temp_key(), size=None) buffers = [_get_buffer(group, nav).key for group in groups] redis.zunionstore(rlbb.key, buffers, aggregate='MAX') return rlbb