Fakultas Ilmu Komputer UI

Commit 2c890830 authored by Jonathan Christopher Jakub's avatar Jonathan Christopher Jakub
Browse files

[GREEN] Change approach to use annotate (distinct not supported by test database)

parent a2826f71
Pipeline #47433 passed with stages
in 3 minutes and 14 seconds
from django.http import JsonResponse
from django.db.models import Max
from rest_framework import status
from rest_framework.views import APIView
......@@ -31,14 +32,19 @@ class StatisticsView(APIView):
def get(self, request, format=None):
case_subjects = CaseSubject.objects.all()
investigation_case_subjects = InvestigationCase.objects \
.order_by("case_subject__id", "-created_at") \
.distinct("case_subject")
investigation_cases = (
InvestigationCase.objects
.values("case_subject")
.annotate(latest_investigation_case=Max("created_at"))
.order_by()
.values("case_subject__id", "is_positive")
)
outcomes = {}
for investigation_case_subject in investigation_case_subjects:
related_case_subject_id = investigation_case_subject.case_subject.id
outcomes[related_case_subject_id] = investigation_case_subject.is_positive
for investigation_case in investigation_cases:
related_case_subject_id = investigation_case["case_subject__id"]
outcomes[related_case_subject_id] = investigation_case["is_positive"]
age_groups, sex_groups, district_groups = generate_initial_groups()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment