Coverage for CIResults/metrics_views.py: 100%

44 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-19 09:20 +0000

1from django.shortcuts import render 

2from django.http import JsonResponse 

3 

4from .models import Bug, Test, Machine, RunConfig, Issue, UnknownFailure, BugComment 

5 

6from .metrics import metrics_issues_over_time, metrics_bugs_over_time, metrics_issues_ttr, metrics_bugs_ttr 

7from .metrics import metrics_open_issues_age, metrics_open_bugs_age, metrics_failure_filing_delay 

8from .metrics import MetricPassRatePerRunconfig, MetricRuntimeHistory, Periodizer, metrics_comments_over_time 

9from .metrics import MetricPassRatePerTest 

10 

11from .filtering import QueryCreator 

12 

13 

14def api_metrics(request): 

15 metrics = { 

16 "issues": Issue.objects.filter(archived_on=None).count(), 

17 "machine": Machine.objects.all().count(), 

18 "suppressed_tests": Test.objects.filter(vetted_on=None).exclude(first_runconfig=None).count(), 

19 "suppressed_machines": Machine.objects.filter(vetted_on=None).count(), 

20 "tests": Test.objects.all().count(), 

21 "unknown_failures": UnknownFailure.objects.filter(result__ts_run__runconfig__temporary=False).count(), 

22 "version": 1, 

23 } 

24 

25 return JsonResponse(metrics) 

26 

27 

28def metrics_generic_history(request, History, history_kwargs, template_path, **kwargs): 

29 # Default to a sane query if no query has been made 

30 runconfigs = RunConfig.objects.filter(temporary=False).order_by('-id')[:3] 

31 runconfigs_str = ','.join(["'{}'".format(r.name) for r in runconfigs]) 

32 default_query = "runconfig_name IS IN [{}]".format(runconfigs_str) 

33 

34 user_query = QueryCreator(request, History.filtering_model, 

35 default_query_parameters={'query': default_query}).request_to_query() 

36 

37 context = { 

38 'history': History(user_query, **history_kwargs), 

39 } 

40 return render(request, template_path, context) 

41 

42 

43def metrics_passrate_per_runconfig(request, **kwargs): 

44 return metrics_generic_history(request, MetricPassRatePerRunconfig, {}, 

45 'CIResults/metrics_passrate_runconfig.html', **kwargs) 

46 

47 

48def metrics_passrate_per_test(request, **kwargs): 

49 return metrics_generic_history(request, MetricPassRatePerTest, {}, 

50 'CIResults/metrics_passrate_test.html', **kwargs) 

51 

52 

53def metrics_runtime_history(request, **kwargs): 

54 return metrics_generic_history(request, MetricRuntimeHistory, 

55 {"average_per_machine": request.GET.get('average', '0') == '1'}, 

56 'CIResults/metrics_runtime.html', **kwargs) 

57 

58 

59def metrics_issues(request, **kwargs): 

60 period = request.GET.get("period", None) 

61 periodizer = None if period is None else Periodizer.from_json(period) 

62 

63 user_query = QueryCreator(request, Issue).request_to_query() 

64 

65 context = { 

66 "issues_weekly": metrics_issues_over_time(user_query, periodizer=periodizer).stats, 

67 "issues_ttr": metrics_issues_ttr().stats, 

68 "issues_age": metrics_open_issues_age().stats, 

69 "failure_filing_delay": metrics_failure_filing_delay().stats, 

70 

71 'filters_model': Issue, 

72 'query': user_query, 

73 } 

74 return render(request, 'CIResults/metrics_issues.html', context) 

75 

76 

77def metrics_bugs(request, **kwargs): 

78 period = request.GET.get("period", None) 

79 periodizer = None if period is None else Periodizer.from_json(period) 

80 

81 user_query = QueryCreator(request, Bug).request_to_query() 

82 

83 bugs_trend, comments_trend = metrics_bugs_over_time(user_query, periodizer=periodizer) 

84 context = { 

85 "bugs_trend": bugs_trend.stats, 

86 "comments_trend": comments_trend.stats, 

87 "bugs_ttr": metrics_bugs_ttr(user_query).stats, 

88 "bugs_age": metrics_open_bugs_age(user_query).stats, 

89 

90 'filters_model': Bug, 

91 'query': user_query, 

92 } 

93 return render(request, 'CIResults/metrics_bugs.html', context) 

94 

95 

96def metrics_comments(request, **kwargs): 

97 period = request.GET.get("period", None) 

98 periodizer = None if period is None else Periodizer.from_json(period) 

99 

100 user_query = QueryCreator(request, BugComment).request_to_query() 

101 

102 comments_trend, per_account_periods = metrics_comments_over_time(user_query, periodizer=periodizer) 

103 context = { 

104 "verbose": request.GET.get("verbose", None) is not None, 

105 "comments_trend": comments_trend.stats, 

106 "per_account_periods": per_account_periods, 

107 

108 'filters_model': BugComment, 

109 'query': user_query, 

110 } 

111 return render(request, 'CIResults/metrics_comments.html', context)