def channel_platform_summary(request): ''' Lists measures available for specified channel/platform combinations ''' platform_filter = [ platform.lower() for platform in request.GET.getlist('platform') ] channel_filter = [ channel.lower() for channel in request.GET.getlist('channel') ] platforms = Platform.objects.all() if platform_filter: platforms = platforms.filter(name__in=platform_filter) channels = Channel.objects.all() if channel_filter: channels = channels.filter(name__in=channel_filter) summaries = [] for channel in channels: for platform in platforms: measures = [] measure_name_map = { get_measure_summary_cache_key(platform.name, channel.name, measure_name): measure_name for measure_name in Measure.objects.filter( platform=platform).values_list('name', flat=True) } measure_summaries = cache.get_many(measure_name_map.keys()) for (measure_summary_cache_key, measure_summary) in measure_summaries.items(): measures.append({ 'name': measure_name_map[measure_summary_cache_key], **measure_summary, 'lastUpdated': (datetime_to_utc(measure_summary['lastUpdated']) if measure_summary.get('lastUpdated') else None) }) summaries.append({ 'channel': channel.name, 'platform': platform.name, 'measures': measures }) return JsonResponse(data={'summaries': summaries})
def test_measure_summary_incorporated(client, monkeypatch, prepopulated_version_cache, fake_measure_data): # create a summary from the fake data we added, verify it's there cache.set( get_measure_summary_cache_key('linux', 'release', 'main_crashes'), get_measure_summary('linux', 'release', 'main_crashes'), None) resp = client.get(reverse('channel-platform-summary'), { 'platform': 'linux', 'channel': 'release', 'measure': 'main_crashes' }) assert resp.status_code == 200 assert resp.json() == { 'summaries': [{ 'channel': 'release', 'platform': 'linux', 'measures': [{ 'lastUpdated': '2017-07-01T12:00:00Z', 'latest': { 'median': 625.0, 'stdev': 2562.754, 'usageHours': 56.0, 'version': '55.0.1' }, 'name': 'main_crashes', 'previous': { 'median': 625.0, 'stdev': 2562.754, 'usageHours': 56.0, 'version': None } }] }] }
def test_measure_summary_incorporated(client, monkeypatch, prepopulated_version_cache, fake_measure_data): # create a summary from the fake data we added, verify it's there cache.set( get_measure_summary_cache_key('firefox', 'linux', 'release', 'main_crashes'), get_measure_summary('firefox', 'linux', 'release', 'main_crashes'), None) resp = client.get(reverse('channel-platform-summary'), { 'platform': 'linux', 'channel': 'release' }) assert resp.status_code == 200 assert resp.json() == { 'summaries': [{ 'application': 'firefox', 'channel': 'release', 'platform': 'linux', 'latestVersionFieldDuration': 600, 'latestVersionSeen': '55.0.1', 'expectedMeasures': list( Measure.objects.filter( channels=Channel.objects.filter(name='release'), application__name='firefox', platform__name='linux').values_list('name', flat=True)), 'measures': [{ 'name': 'main_crashes', 'lastUpdated': '2017-07-01T12:00:00Z', 'versions': [{ 'adjustedCount': 120, 'adjustedRate': 2142.86, 'count': 120, 'fieldDuration': 600, 'rate': 2142.86, 'version': '55.0.1' }, { 'adjustedCount': 240, 'adjustedRate': 2142.86, 'count': 240, 'fieldDuration': 600, 'rate': 2142.86, 'version': '55' }] }] }] } # verify that the measure / summary disappears when we disable it Measure.objects.all().update(enabled=False) resp = client.get(reverse('channel-platform-summary'), { 'platform': 'linux', 'channel': 'release' }) assert resp.status_code == 200 assert resp.json() == {'summaries': []}
def channel_platform_summary(request): ''' Lists measures available for specified channel/platform combinations ''' application_filter = [application.lower() for application in request.GET.getlist('application')] platform_filter = [platform.lower() for platform in request.GET.getlist('platform')] channel_filter = [channel.lower() for channel in request.GET.getlist('channel')] try: only_crash_measures = bool(strtobool(request.GET.get('only_crash_measures') or '0')) except ValueError: only_crash_measures = False applications = Application.objects.all() if application_filter: applications = applications.filter(name__in=application_filter) platforms = Platform.objects.all() if platform_filter: platforms = platforms.filter(name__in=platform_filter) channels = Channel.objects.all() if channel_filter: channels = channels.filter(name__in=channel_filter) summaries = [] for application in applications: for channel in channels: for platform in platforms: measures = Measure.objects.filter( channels=channel, application=application, platform=platform, enabled=True) if only_crash_measures: measures = measures.filter(name__in=['main_crashes', 'content_crashes', 'content_shutdown_crashes']) if not measures.exists(): continue measure_names = measures.values_list('name', flat=True) measure_name_map = { get_measure_summary_cache_key(application.name, platform.name, channel.name, measure_name): measure_name for measure_name in measure_names } measure_summary_map = cache.get_many(measure_name_map.keys()) latest_version_seen = None latest_version_field_duration = None if measure_summary_map.values(): latest_version_seen = _sorted_version_list( [measure_summary['versions'][0]['version'] for measure_summary in measure_summary_map.values()])[0] latest_version_field_duration = max( [measure_summary['versions'][0]['fieldDuration'] for measure_summary in measure_summary_map.values() if measure_summary['versions'][0]['version'] == latest_version_seen]) summaries.append({ 'application': application.name, 'expectedMeasures': list(measure_names), 'latestVersionSeen': latest_version_seen, 'latestVersionFieldDuration': latest_version_field_duration, 'channel': channel.name, 'platform': platform.name, 'measures': [{ 'name': measure_name_map[measure_summary_cache_key], **measure_summary, 'lastUpdated': (datetime_to_utc(measure_summary['lastUpdated']) if measure_summary.get('lastUpdated') else None) } for (measure_summary_cache_key, measure_summary) in measure_summary_map.items()] }) return JsonResponse(data={'summaries': summaries})