示例#1
0
def test_mark_unmark():
    now = datetime.utcnow()

    mark_event('active', 125)
    assert 125 in MonthEvents('active', now.year, now.month)

    unmark_event('active', 125)
    assert 125 not in MonthEvents('active', now.year, now.month)
示例#2
0
def test_mark_unmark():
    now = datetime.utcnow()

    mark_event('active', 125)
    assert 125 in MonthEvents('active', now.year, now.month)

    unmark_event('active', 125)
    assert 125 not in MonthEvents('active', now.year, now.month)
示例#3
0
def add_app_statistics(userid, platform, app, now=None):
    mark = partial(mark_event, now=now)
    if not now:
        now = timezone.now()
    appid = app.get('appid')
    version = app.get('version')
    channel = parser.get_channel(app)
    events = app.findall('event')
    nextversion = app.get('nextversion')

    err_events = filter(lambda x: x.get('eventresult') not in ['1', '2', '3'], events)
    if err_events:
        return

    install_event = filter(lambda x: x.get('eventtype') == '2', events)
    if is_new_install(appid, userid):
        if install_event:
            mark('new_install:%s' % appid, userid)
            mark('new_install:{}:{}'.format(appid, platform), userid)
            redis.setbit("known_users:%s" % appid, userid, 1)
            mark('request:{}:{}'.format(appid, nextversion), userid, track_hourly=True)
            mark('request:{}:{}:{}'.format(appid, platform, nextversion), userid, track_hourly=True)
            mark('request:{}:{}:{}:{}'.format(appid, platform, channel, nextversion), userid, track_hourly=True)
            mark('request:{}:{}'.format(appid, channel), userid)
            return

    elif userid not in MonthEvents('new_install:{}:{}'.format(appid, platform), year=now.year, month=now.month):
        mark('request:%s' % appid, userid)
        mark('request:{}:{}'.format(appid, platform), userid)
        if nextversion:
            mark('request:{}:{}'.format(appid, nextversion), userid, track_hourly=True)
            mark('request:{}:{}:{}'.format(appid, platform, nextversion), userid, track_hourly=True)
            mark('request:{}:{}:{}:{}'.format(appid, platform, channel, nextversion), userid, track_hourly=True)

    uninstall_event = filter(lambda x: x.get('eventtype') == '4', events)
    if uninstall_event:
        mark('uninstall:%s' % appid, userid)
        mark('uninstall:{}:{}'.format(appid, platform), userid)
    update_event = filter(lambda x: x.get('eventtype') == '3', events)
    if update_event:
        unmark_event('request:{}:{}'.format(appid, version), userid, track_hourly=True)
        unmark_event('request:{}:{}:{}'.format(appid, platform, version), userid, track_hourly=True)
        unmark_event('request:{}:{}:{}:{}'.format(appid, platform, channel, version), userid, track_hourly=True)
        mark('request:{}:{}'.format(appid, nextversion), userid, track_hourly=True)
        mark('request:{}:{}:{}'.format(appid, platform, nextversion), userid, track_hourly=True)
        mark('request:{}:{}:{}:{}'.format(appid, platform, channel, nextversion), userid, track_hourly=True)
    else:
        mark('request:{}:{}'.format(appid, version), userid, track_hourly=True)
        mark('request:{}:{}:{}'.format(appid, platform, version), userid, track_hourly=True)
        mark('request:{}:{}:{}:{}'.format(appid, platform, channel, version), userid, track_hourly=True)
    mark('request:{}:{}'.format(appid, channel), userid)