def test_mark_with_diff_days(): delete_all_events() mark_event('active', 123, track_hourly=True) now = datetime.utcnow() # Month assert 123 in MonthEvents('active', now.year, now.month) assert 124 not in MonthEvents('active', now.year, now.month) # Week assert 123 in WeekEvents('active', now.year, now.isocalendar()[1]) assert 124 not in WeekEvents('active', now.year, now.isocalendar()[1]) # Day assert 123 in DayEvents('active', now.year, now.month, now.day) assert 124 not in DayEvents('active', now.year, now.month, now.day) # Hour assert 123 in HourEvents('active', now.year, now.month, now.day, now.hour) assert 124 not in HourEvents('active', now.year, now.month, now.day, now.hour) assert 124 not in HourEvents('active', now.year, now.month, now.day, now.hour - 1)
def get_users_statistics_weeks(app_id=None): now = timezone.now() event_name = 'request:%s' % app_id if app_id else 'request' year = now.year current_week = now.isocalendar()[1] previous_week = (now - timedelta(weeks=1)).isocalendar()[1] yesterday = now - timedelta(days=1) data = [ ('Previous week', len(WeekEvents(event_name, year, previous_week))), ('Current week', len(WeekEvents(event_name, year, current_week))), ('Yesterday', len(DayEvents(event_name, year, yesterday.month, yesterday.day))), ('Today', len(DayEvents(event_name, year, now.month, now.day))), ] return data
def get_channel_statistics(app_id): now = timezone.now() event_name = 'request:{}:{}' week = now.isocalendar()[1] channels = [c.name for c in Channel.objects.all()] data = [(channel, len(WeekEvents(event_name.format(app_id, channel), now.year, week))) for channel in channels] return data
def get_users_versions(app_id): now = timezone.now() event_name = 'request:{}:{}' week = now.isocalendar()[1] versions = [ str(v.version) for v in Version.objects.filter_by_enabled(app__id=app_id) ] data = [(v, len(WeekEvents(event_name.format(app_id, v), now.year, week))) for v in versions] return data
def _(period, userid): return get_id(userid) in WeekEvents.from_date('request', timezone.now())
def _weeks_events_fn(key, date, system): return WeekEvents(key, date.year, date.isocalendar()[1], system=system)