Exemplo n.º 1
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}]
Exemplo n.º 2
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])]