Fakultas Ilmu Komputer UI

Commit c3445c57 authored by Jonathan Christopher Jakub's avatar Jonathan Christopher Jakub
Browse files

[REFACTOR] Tidy up comments and improve namings

parent 2c890830
Pipeline #47434 passed with stages
in 3 minutes and 5 seconds
# District
DISTRICTS = (
"Beji",
"Bojongsari",
......@@ -12,11 +14,23 @@ DISTRICTS = (
"Tapos",
)
DISTRICT = "district"
# Age
AGE = "age"
# Sex
SEX = "sex"
FEMALE = "female"
MALE = "male"
# Outcome
POSITIVE = "positive"
NEGATIVE = "negative"
UNDERTERMINED = "undetermined"
# Total
TOTAL = "total_count"
from django.urls import path
from apps.exportables.views import StatisticsView
from apps.exportables.views import CaseCountsView
urlpatterns = [
path("", StatisticsView.as_view()),
path("", CaseCountsView.as_view()),
]
......@@ -19,7 +19,7 @@ def generate_initial_counts():
}
def generate_initial_groups():
def generate_initial_group_counts():
age_groups = {}
sex_groups = {
MALE: generate_initial_counts(),
......@@ -32,7 +32,7 @@ def generate_initial_groups():
return [age_groups, sex_groups, district_groups]
def map_outcome(outcome):
def map_outcome_value(outcome):
if outcome is None:
return UNDERTERMINED
if outcome:
......@@ -41,7 +41,7 @@ def map_outcome(outcome):
return NEGATIVE
def map_sex(sex):
def map_sex_value(sex):
if sex:
return MALE
return FEMALE
......@@ -21,19 +21,18 @@ from apps.exportables.constants import (
)
from apps.exportables.utils import (
generate_initial_counts,
generate_initial_groups,
map_outcome,
map_sex,
generate_initial_group_counts,
map_outcome_value,
map_sex_value,
)
class StatisticsView(APIView):
class CaseCountsView(APIView):
def get(self, request, format=None):
case_subjects = CaseSubject.objects.all()
investigation_cases = (
InvestigationCase.objects
investigation_cases = (InvestigationCase.objects
.values("case_subject")
.annotate(latest_investigation_case=Max("created_at"))
.order_by()
......@@ -46,13 +45,13 @@ class StatisticsView(APIView):
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()
age_groups, sex_groups, district_groups = generate_initial_group_counts()
for case_subject in case_subjects:
outcome = outcomes.get(case_subject.id)
outcome = map_outcome(outcome)
outcome = map_outcome_value(outcome)
# Age Group
# Age-based grouping
subject_age = str(case_subject.age)
if age_groups.get(subject_age) is None:
age_groups[subject_age] = generate_initial_counts()
......@@ -60,7 +59,7 @@ class StatisticsView(APIView):
age_groups[subject_age][outcome] += 1
age_groups[subject_age][TOTAL] += 1
# District Group
# District-based grouping
subject_district = case_subject.district
if district_groups.get(subject_district) is None:
district_groups[subject_district] = generate_initial_counts()
......@@ -68,9 +67,9 @@ class StatisticsView(APIView):
district_groups[subject_district][outcome] += 1
district_groups[subject_district][TOTAL] += 1
# Sex Group
# Sex-based grouping
subject_sex = case_subject.is_male
subject_sex = map_sex(subject_sex)
subject_sex = map_sex_value(subject_sex)
sex_groups[subject_sex][outcome] += 1
sex_groups[subject_sex][TOTAL] += 1
......
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