Beispiel #1
0
def generate_statistics(i, versions, channels, year):
    year = year

    if i % 100 == 0:
        print(('=> %s' % i))
    version = random.choice(versions)
    platform = version.platform.name if getattr(version, 'platform',
                                                None) else 'mac'
    channel = random.choice(channels)
    if platform != 'mac':
        app = create_app_xml(appid=version.app.id,
                             version=str(version.version),
                             tag=channel.name,
                             events=[random.choice(events)])
        app_list = [app]
    else:
        app_list = dict(appid=version.app.id,
                        version=str(version.short_version),
                        tag=version.channel)
    month = random.choice(list(range(1, 13)))
    day = random.choice(list(range(1, 28)))
    date = datetime(year, month, day)
    userid = get_random_uuid(platform)
    if platform == 'mac':
        mac_userid_counting(userid, app_list, platform, now=date)
    else:
        userid_counting(userid, app_list, platform, now=date)
def generate_statistics(i, versions, channels, year):
    year = year

    if i % 100 == 0:
        print('=> %s' % i)
    version = random.choice(versions)
    platform = version.platform.name if getattr(version, 'platform', None) else 'mac'
    channel = random.choice(channels)
    if platform == 'win':
        app_list = [dict(
            appid=version.app.id,
            version=str(version.version),
            tag=channel,
        )]
    else:
        app_list = [dict(
            appid=version.app.id,
            version=str(version.short_version),
            tag=version.channel
        )]
    month = random.choice(range(1, 13))
    day = random.choice(range(1, 28))
    date = datetime(year, month, day)
    userid = get_random_uuid(platform)
    userid_counting(userid, app_list, platform, now=date)
Beispiel #3
0
    def test_live_statistics_updatecheck(self):
        request = parse_request(fixtures.request_update_check)
        apps = request.findall('app')
        app = apps[0]
        channel = DEFAULT_CHANNEL
        now = datetime.utcnow()
        userid = 1
        platform = 'win'

        appid = app.get('appid')
        version = app.get('version')

        events_appid_version = HourEvents(
            'request:{}:{}'.format(appid, version), now.year, now.month,
            now.day, now.hour)
        events_appid_platform_version = HourEvents(
            'request:{}:{}:{}'.format(appid, platform, version), now.year,
            now.month, now.day, now.hour)
        events_appid_platform_channel_version = HourEvents(
            'request:{}:{}:{}:{}'.format(appid, platform, channel, version),
            now.year, now.month, now.day, now.hour)

        self.assertEqual(len(events_appid_version), 0)
        self.assertEqual(len(events_appid_platform_version), 0)
        self.assertEqual(len(events_appid_platform_channel_version), 0)

        userid_counting(userid, apps, platform)

        self.assertEqual(len(events_appid_version), 1)
        self.assertEqual(len(events_appid_platform_version), 1)
        self.assertEqual(len(events_appid_platform_channel_version), 1)
    def test_live_statistics_updatecheck(self):
        request = parse_request(fixtures.request_update_check)
        apps = request.findall('app')
        app = apps[0]
        channel = DEFAULT_CHANNEL
        now = datetime.utcnow()
        userid = 1
        platform = 'win'

        appid = app.get('appid')
        version = app.get('version')

        events_appid_version = HourEvents('request:{}:{}'.format(appid, version), now.year, now.month, now.day, now.hour)
        events_appid_platform_version = HourEvents('request:{}:{}:{}'.format(appid, platform, version), now.year, now.month, now.day, now.hour)
        events_appid_platform_channel_version = HourEvents(
            'request:{}:{}:{}:{}'.format(appid, platform, channel, version), now.year, now.month, now.day, now.hour)

        self.assertEqual(len(events_appid_version), 0)
        self.assertEqual(len(events_appid_platform_version), 0)
        self.assertEqual(len(events_appid_platform_channel_version), 0)

        userid_counting(userid, apps, platform)

        self.assertEqual(len(events_appid_version), 1)
        self.assertEqual(len(events_appid_platform_version), 1)
        self.assertEqual(len(events_appid_platform_channel_version), 1)
def generate_statistics(i, versions, channels, year):
    year = year

    if i % 100 == 0:
        print(('=> %s' % i))
    version = random.choice(versions)
    platform = version.platform.name if getattr(version, 'platform', None) else 'mac'
    channel = random.choice(channels)
    if platform != 'mac':
        app = create_app_xml(appid=version.app.id,
                       version=str(version.version),
                       tag=channel.name,
                       events=[random.choice(events)])
        app_list = [app]
    else:
        app_list = dict(
            appid=version.app.id,
            version=str(version.short_version),
            tag=version.channel
        )
    month = random.choice(list(range(1, 13)))
    day = random.choice(list(range(1, 28)))
    date = datetime(year, month, day)
    userid = get_random_uuid(platform)
    if platform == 'mac':
        mac_userid_counting(userid, app_list, platform, now=date)
    else:
        userid_counting(userid, app_list, platform, now=date)
Beispiel #6
0
def generate_statistics(i, versions, channels, year):
    year = year

    if i % 100 == 0:
        print('=> %s' % i)
    version = random.choice(versions)
    platform = version.platform.name if getattr(version, 'platform',
                                                None) else 'mac'
    channel = random.choice(channels)
    if platform == 'win':
        app_list = [
            dict(
                appid=version.app.id,
                version=str(version.version),
                tag=channel,
            )
        ]
    else:
        app_list = [
            dict(appid=version.app.id,
                 version=str(version.short_version),
                 tag=version.channel)
        ]
    month = random.choice(range(1, 13))
    day = random.choice(range(1, 28))
    date = datetime(year, month, day)
    userid = get_random_uuid(platform)
    userid_counting(userid, app_list, platform, now=date)
Beispiel #7
0
def collect_statistics(request, appid, channel):
    deviceID = request.GET.get('deviceID')
    version = request.GET.get('appVersionShort')
    if not deviceID or not version:
        return
    app = dict(appid=appid, version=version, tag=channel)

    userid_counting(deviceID, [app], 'mac')
    update_live_statistics(deviceID, appid, version)
Beispiel #8
0
    def _generate_fake_statistics(self):
        now = datetime.now()
        year = now.year

        for i in range(1, 13):
            date = datetime(year=year, month=i, day=1)
            for id in range(1, i + 1):
                user_id = UUID(int=id)
                userid_counting(user_id, self.app_list, self.platform.name, now=date)
Beispiel #9
0
def collect_statistics(request, appid, channel):
    deviceID = request.GET.get('deviceID')
    version = request.GET.get('appVersionShort')
    if not deviceID or not version:
        return
    app = dict(appid=appid,
               version=version,
               tag=channel)

    userid_counting(deviceID, [app], 'mac')
    update_live_statistics(deviceID, appid, version)
Beispiel #10
0
    def _generate_fake_statistics(self):
        now = datetime.now()
        year = now.year
        n_users = 12

        for i in range(1, n_users+1):
            date = datetime(year=year, month=i, day=10)
            for id in range(1, i + 1):
                user_id = UUID(int=id)
                userid_counting(user_id, self.app_list, self.platform.name, now=date)
                user_id = UUID(int=n_users + id)
                userid_counting(user_id, [self.mac_app], 'mac', now=date)
Beispiel #11
0
    def _generate_fake_statistics(self):
        now = datetime.now()
        year = now.year

        for i in range(1, 13):
            date = datetime(year=year, month=i, day=1)
            for id in range(1, i + 1):
                user_id = UUID(int=id)
                userid_counting(user_id,
                                self.app_list,
                                self.platform.name,
                                now=date)
Beispiel #12
0
    def _generate_fake_statistics(self):
        now = datetime.now()
        prev_year = now.year - 1

        for i in range(1, 13):
            date = datetime(year=prev_year, month=i, day=10)
            for id in range(1, i + 1):
                user_id = UUID(int=id)
                userid_counting(user_id,
                                self.install_app_list,
                                self.platform.name,
                                now=date)
                user_id = UUID(int=1000 + id)
                mac_userid_counting(user_id, self.mac_app, 'mac', now=date)
            userid_counting(UUID(int=i),
                            self.uninstall_app_list,
                            self.platform.name,
                            now=date)

        user_id = UUID(int=13)
        userid_counting(user_id,
                        self.install_app_list,
                        self.platform.name,
                        now=datetime(year=now.year, month=1, day=1))
        userid_counting(user_id,
                        self.uninstall_app_list,
                        self.platform.name,
                        now=datetime(year=now.year, month=1, day=1))
        user_id = UUID(int=1013)
        mac_userid_counting(user_id,
                            self.mac_app,
                            'mac',
                            now=datetime(year=now.year, month=1, day=1))
def generate_statistics(i, versions):
    now = timezone.now()
    year = now.year

    if i % 100 == 0:
        print('=> %s' % i)
    version = random.choice(versions)
    platform = version.platform.name
    app_list = [dict(
        appid=version.app.id,
        version=str(version.version),
    )]
    month = random.choice(range(1, 13))
    day = random.choice(range(1, 28))
    date = datetime(year, month, day)
    userid = UUID(int=i)
    userid_counting(userid, app_list, platform, now=date)
Beispiel #14
0
def generate_statistics(i, versions):
    now = timezone.now()
    year = now.year

    if i % 100 == 0:
        print('=> %s' % i)
    version = random.choice(versions)
    platform = version.platform.name
    app_list = [dict(
        appid=version.app.id,
        version=str(version.version),
    )]
    month = random.choice(range(1, 13))
    day = random.choice(range(1, 28))
    date = datetime(year, month, day)
    userid = UUID(int=i)
    userid_counting(userid, app_list, platform, now=date)
Beispiel #15
0
    def _generate_fake_statistics(self):
        now = datetime.now()
        prev_year = now.year - 1

        for i in range(1, 13):
            date = datetime(year=prev_year, month=i, day=10)
            for id in range(1, i + 1):
                user_id = UUID(int=id)
                userid_counting(user_id, self.app_list, self.platform.name, now=date)
                user_id = UUID(int=1000 + id)
                userid_counting(user_id, [self.mac_app], 'mac', now=date)

        user_id = UUID(int=13)
        userid_counting(user_id, self.app_list, self.platform.name, now=datetime(year=now.year, month=1, day=1))
        user_id = UUID(int=1013)
        userid_counting(user_id, [self.mac_app], 'mac', now=datetime(year=now.year, month=1, day=1))
 def generate_version(self, is_enabled):
     app = Application.objects.create(id='{D0AB2EBC-931B-4013-9FEB-C9C4C2225C8C}', name='app')
     platform = Platform.objects.create(name='win')
     channel = Channel.objects.create(name='stable')
     userid = 1
     Version.objects.create(
         is_enabled=is_enabled,
         app=app,
         platform=platform,
         channel=channel,
         version='0.0.0.2',
         file=SimpleUploadedFile('./chrome_installer.exe', False))
     start = timezone.now() - timedelta(3)
     end = timezone.now()
     request = parse_request(fixtures.request_event_uninstall_success)
     apps = request.findall('app')
     userid_counting(userid, apps, platform)
     return get_users_live_versions(
         app_id=app.pk,
         channel=channel,
         start=start,
         end=end,
     )
Beispiel #17
0
    def test_live_statistics_install(self):
        request = parse_request(fixtures.request_event_install_success)
        apps = request.findall('app')
        app = apps[0]
        channel = DEFAULT_CHANNEL
        now = datetime.utcnow()
        userid = 1
        platform = 'win'

        appid = app.get('appid')
        version_1 = '0.0.0.1'
        version_2 = '0.0.0.2'

        events_appid_version = lambda version: HourEvents(
            'request:{}:{}'.format(appid, version), now.year, now.month, now.
            day, now.hour)
        events_appid_platform_version = lambda version: HourEvents(
            'request:{}:{}:{}'.format(appid, platform, version), now.year, now.
            month, now.day, now.hour)
        events_appid_platform_channel_version = lambda version: HourEvents(
            'request:{}:{}:{}:{}'.format(appid, platform, channel, version),
            now.year, now.month, now.day, now.hour)

        self.assertEqual(len(events_appid_version(version_1)), 0)
        self.assertEqual(len(events_appid_platform_version(version_1)), 0)
        self.assertEqual(len(events_appid_platform_channel_version(version_1)),
                         0)
        userid_counting(userid, apps, platform)

        self.assertEqual(len(events_appid_version(version_1)), 1)
        self.assertEqual(len(events_appid_platform_version(version_1)), 1)
        self.assertEqual(len(events_appid_platform_channel_version(version_1)),
                         1)

        request = parse_request(fixtures.request_event_update_success)
        apps = request.findall('app')

        userid_counting(userid, apps, platform)

        self.assertEqual(len(events_appid_version(version_1)), 0)
        self.assertEqual(len(events_appid_platform_version(version_1)), 0)
        self.assertEqual(len(events_appid_platform_channel_version(version_1)),
                         0)
        self.assertEqual(len(events_appid_version(version_2)), 1)
        self.assertEqual(len(events_appid_platform_version(version_2)), 1)
        self.assertEqual(len(events_appid_platform_channel_version(version_2)),
                         1)

        request = parse_request(fixtures.request_event_uninstall_success)
        apps = request.findall('app')

        userid_counting(userid, apps, platform)

        self.assertEqual(len(events_appid_version(version_2)), 1)
        self.assertEqual(len(events_appid_platform_version(version_2)), 1)
        self.assertEqual(len(events_appid_platform_channel_version(version_2)),
                         1)
Beispiel #18
0
    def test_userid_counting(self, mock_add_app_statistics):
        now = datetime.utcnow()

        userid1 = '{F07B3878-CD6F-4B96-B52F-95C4D23077E0}'
        user1_id = get_id(userid1)

        userid2 = '{EC4C5647-F798-4BCA-83DA-926CD448A1D5}'
        user2_id = get_id(userid2)

        app_list = [
            dict(appid='{F97917B1-19AB-48C1-9802-CEF305B10804}'),
            dict(appid='{555B8D18-076D-4576-9579-1FD7F0399EAE}')
        ]

        request_events = DayEvents('request', now.year, now.month, now.day)

        self.assertFalse(user1_id in request_events)
        self.assertEqual(len(request_events), 0)

        userid_counting(userid1, app_list, 'win')

        for app in app_list:
            mock_add_app_statistics.assert_any_call(user1_id,
                                                    'win',
                                                    app,
                                                    now=None)

        self.assertEqual(len(request_events), 1)
        self.assertTrue(user1_id in request_events)

        userid_counting(userid1, app_list, 'win')

        for app in app_list:
            mock_add_app_statistics.assert_any_call(user1_id,
                                                    'win',
                                                    app,
                                                    now=None)

        self.assertEqual(len(request_events), 1)

        self.assertFalse(user2_id in request_events)
        userid_counting(userid2, app_list[:1], 'win')
        self.assertTrue(user2_id in request_events)
        for app in app_list[:1]:
            mock_add_app_statistics.assert_any_call(user2_id,
                                                    'win',
                                                    app,
                                                    now=None)

        self.assertEqual(len(request_events), 2)
Beispiel #19
0
    def test_live_statistics_install(self):
        request = parse_request(fixtures.request_event_install_success)
        apps = request.findall('app')
        app = apps[0]
        channel = DEFAULT_CHANNEL
        now = datetime.utcnow()
        userid = 1
        platform = 'win'

        appid = app.get('appid')
        version_1 = '0.0.0.1'
        version_2 = '0.0.0.2'
        events_appid_version = lambda version: HourEvents('request:{}:{}'.format(appid, version), now.year, now.month, now.day, now.hour)
        events_appid_platform_version = lambda version: HourEvents('request:{}:{}:{}'.format(appid, platform, version), now.year, now.month, now.day, now.hour)
        events_appid_platform_channel_version = lambda version: HourEvents(
            'request:{}:{}:{}:{}'.format(appid, platform, channel, version), now.year, now.month, now.day, now.hour)

        self.assertEqual(len(events_appid_version(version_1)), 0)
        self.assertEqual(len(events_appid_platform_version(version_1)), 0)
        self.assertEqual(len(events_appid_platform_channel_version(version_1)), 0)
        userid_counting(userid, apps, platform)
        self.assertEqual(len(events_appid_version(version_1)), 1)
        self.assertEqual(len(events_appid_platform_version(version_1)), 1)
        self.assertEqual(len(events_appid_platform_channel_version(version_1)), 1)

        request = parse_request(fixtures.request_event_update_success)
        apps = request.findall('app')

        userid_counting(userid, apps, platform)

        self.assertEqual(len(events_appid_version(version_1)), 0)
        self.assertEqual(len(events_appid_platform_version(version_1)), 0)
        self.assertEqual(len(events_appid_platform_channel_version(version_1)), 0)
        self.assertEqual(len(events_appid_version(version_2)), 1)
        self.assertEqual(len(events_appid_platform_version(version_2)), 1)
        self.assertEqual(len(events_appid_platform_channel_version(version_2)), 1)

        request = parse_request(fixtures.request_event_uninstall_success)
        apps = request.findall('app')

        userid_counting(userid, apps, platform)

        self.assertEqual(len(events_appid_version(version_2)), 1)
        self.assertEqual(len(events_appid_platform_version(version_2)), 1)
        self.assertEqual(len(events_appid_platform_channel_version(version_2)), 1)
    def test_userid_counting(self, mock_add_app_statistics):
        now = datetime.utcnow()

        userid1 = "{F07B3878-CD6F-4B96-B52F-95C4D23077E0}"
        user1_id = get_id(userid1)

        userid2 = "{EC4C5647-F798-4BCA-83DA-926CD448A1D5}"
        user2_id = get_id(userid2)

        app_list = [
            dict(appid="{F97917B1-19AB-48C1-9802-CEF305B10804}"),
            dict(appid="{555B8D18-076D-4576-9579-1FD7F0399EAE}"),
        ]

        request_events = DayEvents("request", now.year, now.month, now.day)

        self.assertFalse(user1_id in request_events)
        self.assertEqual(len(request_events), 0)

        userid_counting(userid1, app_list, "win")

        for app in app_list:
            mock_add_app_statistics.assert_any_call(user1_id, "win", app, now=None)

        self.assertEqual(len(request_events), 1)
        self.assertTrue(user1_id in request_events)

        userid_counting(userid1, app_list, "win")

        for app in app_list:
            mock_add_app_statistics.assert_any_call(user1_id, "win", app, now=None)

        self.assertEqual(len(request_events), 1)

        self.assertFalse(user2_id in request_events)
        userid_counting(userid2, app_list[:1], "win")
        self.assertTrue(user2_id in request_events)
        for app in app_list[:1]:
            mock_add_app_statistics.assert_any_call(user2_id, "win", app, now=None)

        self.assertEqual(len(request_events), 2)