in treeherder/webapp/api/intermittents_view.py [0:0]
def list(self, request):
query_params = FailuresQueryParamsSerializer(data=request.query_params)
if not query_params.is_valid():
return Response(data=query_params.errors, status=HTTP_400_BAD_REQUEST)
startday = query_params.validated_data["startday"]
endday = get_end_of_day(query_params.validated_data["endday"])
repo = query_params.validated_data["tree"]
bugzilla_id = query_params.validated_data["bug"]
push_query = (
Push.failures.filter(time__range=(startday, endday))
.by_repo(repo, False)
.annotate(date=TruncDate("time"))
.values("date")
.annotate(test_runs=Count("author"))
.values("date", "test_runs")
.order_by("date")
)
if bugzilla_id:
job_query = (
BugJobMap.failures.by_date(startday, endday)
.by_repo(repo)
.by_bug(bugzilla_id)
.annotate(date=TruncDate("job__push__time"))
.values("date")
.annotate(failure_count=Count("id"))
.values("date", "failure_count")
)
else:
job_query = (
Job.failures.filter(
push__time__range=(startday, endday), failure_classification_id=4
)
.by_repo(repo, False)
.select_related("push")
.annotate(date=TruncDate("push__time"))
.values("date")
.annotate(failure_count=Count("id"))
.values("date", "failure_count")
)
# merges the push_query and job_query results into a list; if a date is found in both queries,
# update the job_query with the test_run count, if a date is in push_query but not job_query,
# add a new object with push_query data and a default for failure_count
self.queryset = []
for push in push_query:
match = [job for job in job_query if push["date"] == job["date"]]
if match:
match[0]["test_runs"] = push["test_runs"]
self.queryset.append(match[0])
else:
self.queryset.append(
{"date": push["date"], "test_runs": push["test_runs"], "failure_count": 0}
)
serializer = self.get_serializer(self.queryset, many=True)
return Response(serializer.data)