Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
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
2c890830
Commit
2c890830
authored
May 18, 2020
by
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
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/exportables/views.py
View file @
2c890830
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
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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