-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Let's keep it simple, as we only need support for a few cases:
def convert_units(values: list[int | float], from_unit: str, to_unit: str) -> dict:
"""Convert values between W, kW and MW, as required."
if from_unit == "MW" and to_unit == "W":
values = [v * 10**6 for v in values]
elif (from_unit == "MW" and to_unit == "kW) or (from_unit == "kW" and to_unit == "W"):
values = [v * 10**3 for v in values]
elif from_unit == to_unit:
pass
elif (from_unit == "W" and to_unit == "kW) or (from_unit == "kW" and to_unit == "MW"):
values = [v * 10**-3 for v in values]
elif from_unit == "W" and to_unit == "MW":
values = [v * 10**-6 for v in values]
else:
raise NotImplementedError(f"Power conversion from {from_unit} to {to_unit} is not supported.")
return values
async def get_schedule(
...
unit: str, # <----------
) -> dict:
...
check_for_status(status, 200)
# Convert to the requested unit
from_unit = schedule["unit"] # from the schedule
to_unit = unit # from the function argument
schedule["values"] = convert_units(schedule["values"], from_unit, to_unit)
return schedule
Potential follow-up: open a FlexMeasures issue to handle this server-side. Then, after the feature lands and the host server has been upgraded, it should be possible to simply pass the desired unit in the [GET] schedule request.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels