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') 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 and install_event[0].get('eventresult') in ['1', '2', '3']: mark('new_install:%s' % appid, userid) mark('new_install:{}:{}'.format(appid, platform), userid) redis.setbit("known_users:%s" % appid, userid, 1) 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) uninstall_event = filter(lambda x: x.get('eventtype') == '4', events) if uninstall_event and uninstall_event[0].get('eventresult') in ['1', '2', '3']: mark('uninstall:%s' % appid, userid) mark('uninstall:{}:{}'.format(appid, platform), userid) mark('request:{}:{}'.format(appid, version), userid) mark('request:{}:{}'.format(appid, channel), userid) mark('request:{}:{}:{}'.format(appid, platform, version), userid)
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 = [x for x in events if x.get('eventresult') not in ['1', '2', '3']] if err_events: return install_event = [x for x in events if x.get('eventtype') == '2'] 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 = [x for x in events if x.get('eventtype') == '4'] if uninstall_event: mark('uninstall:%s' % appid, userid) mark('uninstall:{}:{}'.format(appid, platform), userid) update_event = [x for x in events if x.get('eventtype') == '3'] 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)
def parse_apps(apps, request): app_list = [] for app in apps: events = app.findall('event') if not events: continue kwargs = get_kwargs_for_model(AppRequest, app, exclude=['request', 'version', 'nextversion', 'id']) kwargs['version'] = app.get('version') or None kwargs['nextversion'] = app.get('nextversion') or None kwargs['tag'] = parser.get_channel(app) app_req = AppRequest.objects.create(request=request, **kwargs) event_list = parse_events(events) app_req.events.add(*event_list) app_list.append(app_req) return app_list
def on_app(apps_list, app, os, userid): app_id = app.get('appid') version = app.get('version') platform = os.get('platform') channel = parser.get_channel(app) ping = bool(app.findall('ping')) events = reduce(on_event, app.findall('event'), []) build_app = partial(App, app_id, status='ok', ping=ping, events=events) updatecheck = app.findall('updatecheck') try: version = get_version(app_id, platform, channel, version, userid) except Version.DoesNotExist: apps_list.append( build_app( updatecheck=Updatecheck_negative() if updatecheck else None)) return apps_list data_list = reduce(partial(on_data, version=version), app.findall('data'), []) build_app = partial(build_app, data_list=data_list) if updatecheck: actions = reduce(on_action, version.actions.all(), []) updatecheck = Updatecheck_positive( urls=[version.file_url], manifest=Manifest( version=str(version.version), packages=Packages([ Package( name=version.file_package_name, required='true', size=str(version.file_size), hash=version.file_hash, ) ]), actions=Actions(actions) if actions else None, )) apps_list.append(build_app(updatecheck=updatecheck)) else: apps_list.append(build_app()) return apps_list
def on_app(apps_list, app, os, userid): app_id = app.get('appid') version = app.get('version') platform = os.get('platform') channel = parser.get_channel(app) ping = bool(app.findall('ping')) events = reduce(on_event, app.findall('event'), []) build_app = partial(App, app_id, status='ok', ping=ping, events=events) updatecheck = app.findall('updatecheck') try: version = get_version(app_id, platform, channel, version, userid) except Version.DoesNotExist: apps_list.append( build_app(updatecheck=Updatecheck_negative() if updatecheck else None)) return apps_list data_list = reduce(partial(on_data, version=version), app.findall('data'), []) build_app = partial(build_app, data_list=data_list) if updatecheck: actions = reduce(on_action, version.actions.all(), []) updatecheck = Updatecheck_positive( urls=[version.file_url], manifest=Manifest( version=str(version.version), packages=Packages([Package( name=version.file_package_name, required='true', size=str(version.file_size), hash=version.file_hash, )]), actions=Actions(actions) if actions else None, ) ) apps_list.append(build_app(updatecheck=updatecheck)) else: apps_list.append(build_app()) return apps_list