Skip to content

Commit

Permalink
Add order by
Browse files Browse the repository at this point in the history
  • Loading branch information
hellais committed Nov 22, 2023
1 parent 4748d83 commit 8ba7f83
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions oonidata/fastapi/routers/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ async def get_aggregation(
q_args = {}
and_clauses = []
extra_cols = {}
dimension_count = 1
if axis_x == "measurement_start_day":

Check warning on line 103 in oonidata/fastapi/routers/aggregation.py

View check run for this annotation

Codecov / codecov/patch

oonidata/fastapi/routers/aggregation.py#L99-L103

Added lines #L99 - L103 were not covered by tests
# TODO(arturo): wouldn't it be nicer if we dropped the time_grain
# argument and instead used axis_x IN (measurement_start_day,
# measurement_start_hour, ..)?
extra_cols[

Check warning on line 107 in oonidata/fastapi/routers/aggregation.py

View check run for this annotation

Codecov / codecov/patch

oonidata/fastapi/routers/aggregation.py#L107

Added line #L107 was not covered by tests
"measurement_start_day"
] = f"{get_measurement_start_day_agg(time_grain)} as measurement_start_day"
elif axis_x:
col = OONI_DATA_COLS_REMAP.get(axis_x)
extra_cols[axis_x] = f"{col} as {axis_x}"

Check warning on line 112 in oonidata/fastapi/routers/aggregation.py

View check run for this annotation

Codecov / codecov/patch

oonidata/fastapi/routers/aggregation.py#L110-L112

Added lines #L110 - L112 were not covered by tests

if probe_asn is not None:
if isinstance(probe_asn, str) and probe_asn.startswith("AS"):
probe_asn = int(probe_asn[2:])
Expand All @@ -125,18 +137,6 @@ async def get_aggregation(
# XXX
pass

Check warning on line 138 in oonidata/fastapi/routers/aggregation.py

View check run for this annotation

Codecov / codecov/patch

oonidata/fastapi/routers/aggregation.py#L138

Added line #L138 was not covered by tests

dimension_count = 1
if axis_x == "measurement_start_day":
# TODO(arturo): wouldn't it be nicer if we dropped the time_grain
# argument and instead used axis_x IN (measurement_start_day,
# measurement_start_hour, ..)?
extra_cols[
"measurement_start_day"
] = f"{get_measurement_start_day_agg(time_grain)} as measurement_start_day"
elif axis_x:
col = OONI_DATA_COLS_REMAP.get(axis_x)
extra_cols[axis_x] = f"{col} as {axis_x}"

if axis_y:
dimension_count += 1
if axis_y == "measurement_start_day":

Check warning on line 142 in oonidata/fastapi/routers/aggregation.py

View check run for this annotation

Codecov / codecov/patch

oonidata/fastapi/routers/aggregation.py#L140-L142

Added lines #L140 - L142 were not covered by tests
Expand Down Expand Up @@ -270,6 +270,7 @@ async def get_aggregation(
FROM measurement_experiment_result
{where}
GROUP BY {", ".join(extra_cols.keys())}
ORDER BY {", ".join(extra_cols.keys())}
)
"""

Expand Down

0 comments on commit 8ba7f83

Please sign in to comment.