Example #1
0
def test_event_analysis(redis):
    analytics = Analytics(redis)
    period = hourrange(-4)
    event_ids = [('active', [1, 4, 5, 6, 7, 20]), ('played', [1, 5, 7])]
    for m in period:
        for key, ids in event_ids:
            for id in ids:
                analytics.event(key, id, time=m.dt)

    events = analytics.events

    analysis = events('active') & events('played')
    out = list(analysis(period))
    assert out == [set([1, 5, 7]), set([1, 5, 7]), set([1, 5, 7]), set([1, 5, 7])]
Example #2
0
def test_counter_analysis(redis):
    analytics = Analytics(redis)
    period = hourrange(-4)
    counter_data = [('active', [2, 4, 0, 3]), ('played', [3, 4, 0, 1])]
    for key, ids in counter_data:
        for i, m in enumerate(period):
            for j in range(ids[i]):
                analytics.count(key, 1, time=m.dt)

    active = analytics.counters('active')
    assert list(active(period)) == [{'1': 2}, {'1': 4}, {}, {'1': 3}]

    played = analytics.counters('played')
    assert list(played(period)) == [{'1': 3}, {'1': 4}, {}, {'1': 1}]
Example #3
0
def test_hourrange():
    start = datetime(2013, 1, 1, 0, 0)
    end = datetime(2013, 1, 1, 4, 0)
    assert map(str, hourrange(start, end)) == ['2013010100', '2013010101', '2013010102', '2013010103']
    assert len(list(hourrange(-4))) == 4