def get_users_live_versions(app_id, start, end, channel, tz='UTC'): import logging logging.info("Getting active versions from DB") platforms = [x.name for x in get_platforms_by_appid(app_id)] versions = {} for platform in platforms: if platform == 'mac': platform_data = [str(v) for v in SparkleVersion.objects.filter(app_id=app_id).values_list('short_version', flat=True)] else: platform_data = [str(v) for v in Version.objects.filter(app__id=app_id, platform__name=platform).values_list('version', flat=True)] versions.update({platform: platform_data}) logging.info("Getting statistics from Redis") if start < timezone.now() - timedelta(days=7): n_days = (end-start).days data = dict() for platform in platforms: platform_data = get_daily_data_by_platform(app_id, end, n_days, versions[platform], platform, channel) data.update({platform: platform_data}) else: tmp_hours = divmod((end - start).total_seconds(), 60 * 60) n_hours = tmp_hours[0] + 1 n_hours = int(n_hours) data = dict() for platform in platforms: platform_data = get_hourly_data_by_platform(app_id, end, n_hours, versions[platform], platform, channel, tz=tz) data.update({platform: platform_data}) return data
def test_without_mac_versions(self): self.assertEqual(Platform.objects.count(), 4) self.assertEqual(Version.objects.count(), 2) self.assertEqual(SparkleVersion.objects.filter(app=self.app).count(), 0) platforms = get_platforms_by_appid(self.app) self.assertEqual(len(platforms), 2) assert self.a_platform in platforms assert self.b_platform in platforms assert self.mac_platform not in platforms assert self.empty_platform not in platforms
def get_context_data(self, **kwargs): context = super(LiveStatisticsView, self).get_context_data(**kwargs) app = self.object context['app_name'] = app.name platforms = list(get_platforms_by_appid(app)) context['platforms'] = platforms context['platforms_list'] = json.dumps([p.name for p in platforms]) return context
def test_without_mac_versions(self): self.assertEqual(Platform.objects.count(), 4) self.assertEqual(Version.objects.count(), 2) self.assertEqual( SparkleVersion.objects.filter(app=self.app).count(), 0) platforms = get_platforms_by_appid(self.app) self.assertEqual(len(platforms), 2) assert self.a_platform in platforms assert self.b_platform in platforms assert self.mac_platform not in platforms assert self.empty_platform not in platforms
def get_context_data(self, **kwargs): context = super(StatisticsDetailView, self).get_context_data(**kwargs) app = self.object first_omaha_version = Version.objects.all().filter(app=app).order_by('created').first() omaha_start_date = getattr(first_omaha_version, 'created', datetime.datetime(1970, 1, 1, tzinfo=pytz.UTC)) first_mac_version = SparkleVersion.objects.all().filter(app=app).order_by('created').first() mac_start_date = getattr(first_mac_version, 'created', datetime.datetime(1970, 1, 1, tzinfo=pytz.UTC)) context['start_date'] = min(omaha_start_date, mac_start_date).isoformat() platforms = list(get_platforms_by_appid(app)) context['platforms'] = platforms context['platforms_list'] = json.dumps([p.name for p in platforms]) return context
def get_users_live_versions(app_id, start, end, channel, tz='UTC'): import logging logging.info("Getting active versions from DB") platforms = [x.name for x in get_platforms_by_appid(app_id)] versions = {} for platform in platforms: if platform == 'mac': platform_data = [ str(v) for v in SparkleVersion.objects.filter( app_id=app_id).values_list('short_version', flat=True) ] else: platform_data = [ str(v) for v in Version.objects.filter( app__id=app_id, platform__name=platform).values_list( 'version', flat=True) ] versions.update({platform: platform_data}) logging.info("Getting statistics from Redis") if start < timezone.now() - timedelta(days=7): n_days = (end - start).days data = dict() for platform in platforms: platform_data = get_daily_data_by_platform(app_id, end, n_days, versions[platform], platform, channel) data.update({platform: platform_data}) else: tmp_hours = divmod((end - start).total_seconds(), 60 * 60) n_hours = tmp_hours[0] + 1 n_hours = int(n_hours) data = dict() for platform in platforms: platform_data = get_hourly_data_by_platform(app_id, end, n_hours, versions[platform], platform, channel, tz=tz) data.update({platform: platform_data}) return data