Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2020
PPL-C
PPTI-Mobile Apps Monitoring Wabah Tuberkolosis
Neza-Backend
Commits
c3445c57
Commit
c3445c57
authored
May 18, 2020
by
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
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/exportables/constants.py
View file @
c3445c57
# 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"
apps/exportables/urls.py
View file @
c3445c57
from
django.urls
import
path
from
apps.exportables.views
import
Statistic
sView
from
apps.exportables.views
import
CaseCount
sView
urlpatterns
=
[
path
(
""
,
Statistic
sView
.
as_view
()),
path
(
""
,
CaseCount
sView
.
as_view
()),
]
apps/exportables/utils.py
View file @
c3445c57
...
...
@@ -19,7 +19,7 @@ def generate_initial_counts():
}
def
generate_initial_groups
():
def
generate_initial_group
_count
s
():
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
apps/exportables/views.py
View file @
c3445c57
...
...
@@ -21,23 +21,22 @@ from apps.exportables.constants import (
)
from
apps.exportables.utils
import
(
generate_initial_counts
,
generate_initial_groups
,
map_outcome
,
map_sex
,
generate_initial_group
_count
s
,
map_outcome
_value
,
map_sex
_value
,
)
class
Statistic
sView
(
APIView
):
class
CaseCount
sView
(
APIView
):
def
get
(
self
,
request
,
format
=
None
):
case_subjects
=
CaseSubject
.
objects
.
all
()
investigation_cases
=
(
InvestigationCase
.
objects
.
values
(
"case_subject"
)
.
annotate
(
latest_investigation_case
=
Max
(
"created_at"
))
.
order_by
()
.
values
(
"case_subject__id"
,
"is_positive"
)
investigation_cases
=
(
InvestigationCase
.
objects
.
values
(
"case_subject"
)
.
annotate
(
latest_investigation_case
=
Max
(
"created_at"
))
.
order_by
()
.
values
(
"case_subject__id"
,
"is_positive"
)
)
outcomes
=
{}
...
...
@@ -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
_count
s
()
for
case_subject
in
case_subjects
:
outcome
=
outcomes
.
get
(
case_subject
.
id
)
outcome
=
map_outcome
(
outcome
)
outcome
=
map_outcome
_value
(
outcome
)
# Age
G
roup
# Age
-based g
roup
ing
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
G
roup
# District
-based g
roup
ing
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
G
roup
# Sex
-based g
roup
ing
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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment