Skip to content
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
111 changes: 58 additions & 53 deletions src/bemserver_api/resources/timeseries_data/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,33 +278,35 @@ def get_aggregate(args):
timeseries = _get_many_timeseries_by_id(args["timeseries"])
data_state = _get_data_state(args["data_state"])

if mime_type == "text/csv":
resp = tsdcsvio.export_csv_bucket(
args["start_time"],
args["end_time"],
timeseries,
data_state,
args["bucket_width_value"],
args["bucket_width_unit"],
args["aggregation"],
convert_to=args.get("convert_to"),
timezone=args["timezone"],
col_label="id",
)
else:
resp = tsdjsonio.export_json_bucket(
args["start_time"],
args["end_time"],
timeseries,
data_state,
args["bucket_width_value"],
args["bucket_width_unit"],
args["aggregation"],
convert_to=args.get("convert_to"),
timezone=args["timezone"],
col_label="id",
)

try:
if mime_type == "text/csv":
resp = tsdcsvio.export_csv_bucket(
args["start_time"],
args["end_time"],
timeseries,
data_state,
args["bucket_width_value"],
args["bucket_width_unit"],
args["aggregation"],
convert_to=args.get("convert_to"),
timezone=args["timezone"],
col_label="id",
)
else:
resp = tsdjsonio.export_json_bucket(
args["start_time"],
args["end_time"],
timeseries,
data_state,
args["bucket_width_value"],
args["bucket_width_unit"],
args["aggregation"],
convert_to=args.get("convert_to"),
timezone=args["timezone"],
col_label="id",
)
except BEMServerCoreDimensionalityError as exc:
abort(422, message=str(exc))
return flask.Response(resp, mimetype=mime_type)


Expand Down Expand Up @@ -487,32 +489,35 @@ def get_aggregate_for_campaign(args, campaign_id):
timeseries = _get_many_timeseries_by_name(campaign, args["timeseries"])
data_state = _get_data_state(args["data_state"])

if mime_type == "text/csv":
resp = tsdcsvio.export_csv_bucket(
args["start_time"],
args["end_time"],
timeseries,
data_state,
args["bucket_width_value"],
args["bucket_width_unit"],
args["aggregation"],
convert_to=args.get("convert_to"),
timezone=args["timezone"],
col_label="name",
)
else:
resp = tsdjsonio.export_json_bucket(
args["start_time"],
args["end_time"],
timeseries,
data_state,
args["bucket_width_value"],
args["bucket_width_unit"],
args["aggregation"],
convert_to=args.get("convert_to"),
timezone=args["timezone"],
col_label="name",
)
try:
if mime_type == "text/csv":
resp = tsdcsvio.export_csv_bucket(
args["start_time"],
args["end_time"],
timeseries,
data_state,
args["bucket_width_value"],
args["bucket_width_unit"],
args["aggregation"],
convert_to=args.get("convert_to"),
timezone=args["timezone"],
col_label="name",
)
else:
resp = tsdjsonio.export_json_bucket(
args["start_time"],
args["end_time"],
timeseries,
data_state,
args["bucket_width_value"],
args["bucket_width_unit"],
args["aggregation"],
convert_to=args.get("convert_to"),
timezone=args["timezone"],
col_label="name",
)
except BEMServerCoreDimensionalityError as exc:
abort(422, message=str(exc))

return flask.Response(resp, mimetype=mime_type)

Expand Down
27 changes: 25 additions & 2 deletions tests/resources/test_timeseries_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,29 @@ def test_timeseries_data_get_aggregate_errors(
)
assert ret.status_code == 422

# Conversions: wrong convert_to unit
if not for_campaign:
query_url = TIMESERIES_DATA_URL
ts_l = (ts_1_id,)
else:
query_url = TIMESERIES_DATA_URL + f"campaign/{campaign_1_id}/"
ts_l = (f"Timeseries {ts_1_id - 1}",)

ret = client.get(
f"{query_url}aggregate",
query_string={
"start_time": start_time.isoformat(),
"end_time": end_time.isoformat(),
"timeseries": ts_l,
"data_state": ds_id,
"bucket_width_value": 1,
"bucket_width_unit": "hour",
"aggregation": "avg",
"convert_to": ("m/s"),
},
)
assert ret.status_code == 422

# Conversions: wrong convert_to list size
if not for_campaign:
query_url = TIMESERIES_DATA_URL
Expand All @@ -841,8 +864,8 @@ def test_timeseries_data_get_aggregate_errors(
"end_time": end_time.isoformat(),
"timeseries": ts_l,
"data_state": ds_id,
"bucket_width_value": 2,
"bucket_width_unit": "week",
"bucket_width_value": 1,
"bucket_width_unit": "hour",
"aggregation": "avg",
"convert_to": ("mm", "m/s"),
},
Expand Down
Loading