Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order data from chart endpoint #126

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/handlers/dashboard/get_chart_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ def _build_query(query_params: dict, filters: list, path_params: dict) -> str:
f"FROM \"{os.environ.get('GLUE_DB_NAME')}\".\"{dp_id}\" "
f"{coalesce_str} "
f"{query_params['column']} IS NOT Null {filter_str} "
f"GROUP BY {group_str}"
f"GROUP BY {group_str} "
)
if "stratifier" in query_params.keys():
query_str += f"ORDER BY {query_params['stratifier']}, {query_params['column']}"
else:
query_str += f"ORDER BY {query_params['column']}"
logging.debug(query_str)
return query_str

Expand Down
8 changes: 4 additions & 4 deletions tests/dashboard/test_get_chart_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ def mock_data_frame(filter_param):
{"data_package_id": "test_study"},
f'SELECT gender, sum(cnt) as cnt FROM "{TEST_GLUE_DB}"."test_study" '
"WHERE COALESCE (race) IS NOT Null AND gender IS NOT Null "
"GROUP BY gender",
"GROUP BY gender ORDER BY gender",
),
(
{"column": "gender", "stratifier": "race"},
[],
{"data_package_id": "test_study"},
f'SELECT race, gender, sum(cnt) as cnt FROM "{TEST_GLUE_DB}"."test_study" '
"WHERE gender IS NOT Null "
"GROUP BY race, gender",
"GROUP BY race, gender ORDER BY race, gender",
),
(
{"column": "gender"},
Expand All @@ -54,7 +54,7 @@ def mock_data_frame(filter_param):
f'SELECT gender, sum(cnt) as cnt FROM "{TEST_GLUE_DB}"."test_study" '
"WHERE COALESCE (race) IS NOT Null AND gender IS NOT Null "
"AND gender LIKE 'female' "
"GROUP BY gender",
"GROUP BY gender ORDER BY gender",
),
(
{"column": "gender", "stratifier": "race"},
Expand All @@ -63,7 +63,7 @@ def mock_data_frame(filter_param):
f'SELECT race, gender, sum(cnt) as cnt FROM "{TEST_GLUE_DB}"."test_study" '
"WHERE gender IS NOT Null "
"AND gender LIKE 'female' "
"GROUP BY race, gender",
"GROUP BY race, gender ORDER BY race, gender",
),
],
)
Expand Down
Loading