Skip to content

Commit

Permalink
[#157] Simplify answer object for MapsDataResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Aug 9, 2023
1 parent 74d85a4 commit 5013fd9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 24 deletions.
4 changes: 1 addition & 3 deletions backend/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,5 @@ def check_indicator_query(
] if answers else []
for a in answers:
key = a.get('identifier')
del a['data']
del a['identifier']
answer_temp.update({key: a})
answer_temp.update({key: a.get('value')})
return answer_data_ids, answer_temp
9 changes: 4 additions & 5 deletions backend/models/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ class DataResponse(BaseModel):

class MapsData(BaseModel):
id: int
# TODO:: DELETE commented code
# school_information: dict
# year_conducted: int
# geo: List[float]
answer: Union[AnswerDict, dict]
# ** REMEMBER TO UPDATE if answer value updated
answer: Union[
int, float, str, bool, dict, List[str], List[int], List[float], None
]


class MapDataResponse(BaseModel):
Expand Down
7 changes: 2 additions & 5 deletions backend/routes/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def get_maps(
d["jmp_filter"] = None
data_id = str(d.get('identifier'))
if "jmp" not in str(indicator):
d["answer"] = answer_temp.get(data_id) or {}
d["answer"] = answer_temp.get(data_id) or None
if "jmp" in str(indicator):
# JMP indicator answer
find_jmp = next(
Expand All @@ -302,10 +302,7 @@ def get_maps(
jmp_res = group_by_category_output(data=dt)
level = jmp_res[0].get('options')[0].get('name')
d["jmp_filter"] = f"{jmp_name}|{level}"
d["answer"] = {
"question": f"{indicator}_{d['id']}",
"value": level
}
d["answer"] = level
# JMP filter: filter data by jmp filter value in jmp_query
if "jmp" in str(indicator) and jmp_query:
data = list(filter(
Expand Down
11 changes: 0 additions & 11 deletions backend/tests/test_100_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ async def test_get_maps_data(
'current', 'data', 'total', 'total_page'
]
assert list(res["data"][0]) == ['id', 'answer']
assert list(res["data"][0]["answer"]) == ['question', 'value']
assert res["data"][0]["answer"]["question"] == indicator_id
# TODO:: delete
# assert res["data"][0] == {
# 'id': 649130936,
Expand Down Expand Up @@ -253,7 +251,6 @@ async def test_get_maps_data(
'current', 'data', 'total', 'total_page'
]
assert list(res["data"][0]) == ['id', 'answer']
assert list(res["data"][0]["answer"]) == ['question', 'value']
# TODO:: Delete
# assert res["data"] == [{
# 'id': 649130936,
Expand Down Expand Up @@ -287,8 +284,6 @@ async def test_get_maps_data(
'current', 'data', 'total', 'total_page'
]
assert list(res["data"][0]) == ['id', 'answer']
assert list(res["data"][0]["answer"]) == ['question', 'value']
assert res["data"][0]["answer"]["question"] == indicator_id
# TODO: Delete
# assert res["data"][0] == {
# 'id': 649130936,
Expand Down Expand Up @@ -324,8 +319,6 @@ async def test_get_maps_data(
'current', 'data', 'total', 'total_page'
]
assert list(res["data"][0]) == ['id', 'answer']
assert list(res["data"][0]["answer"]) == ['question', 'value']
assert res["data"][0]["answer"]["question"] == indicator_id
# TODO: Delete
# assert res["data"][0] == {
# 'id': 649130936,
Expand Down Expand Up @@ -465,8 +458,6 @@ async def test_get_maps_data(
'current', 'data', 'total', 'total_page'
]
assert list(res["data"][0]) == ['id', 'answer']
assert list(res["data"][0]["answer"]) == ['question', 'value']
assert indicator_id in res["data"][0]["answer"]["question"]
# TODO: Delete
# assert res["data"][0] == {
# 'id': 649130936,
Expand Down Expand Up @@ -502,8 +493,6 @@ async def test_get_maps_data(
'current', 'data', 'total', 'total_page'
]
assert list(res["data"][0]) == ['id', 'answer']
assert list(res["data"][0]["answer"]) == ['question', 'value']
assert indicator_id in res["data"][0]["answer"]["question"]
# TODO: Delete
# assert res["data"][0] == {
# 'id': 649130936,
Expand Down

0 comments on commit 5013fd9

Please sign in to comment.