flexmeasures.data.schemas.utils
Functions
- flexmeasures.data.schemas.utils.convert_to_quantity(value: str, to_unit: str) Quantity
Convert value to quantity in the given unit.
- Parameters:
value – Value to convert.
to_unit – Unit to convert to. If the unit starts with a ‘/’, the value can have any unit, and the unit is used as the denominator.
- Returns:
Quantity in the desired unit.
- flexmeasures.data.schemas.utils.with_appcontext_if_needed()
Execute within the script’s application context, in case there is one.
An exception is any server
runcommand (e.g.flexmeasures runorflask run), which has a click context at the time the decorator is called, but no longer has a click context at the time the decorated function is called, which, typically, is a request to the running FlexMeasures server.The check walks up the entire context chain so it handles both: -
flask run: modules are imported while therunsubcommand context is current(
ctx.info_name == "run",ctx.invoked_subcommand is None).flexmeasures run: modules are imported at group level, where the parent context hasinvoked_subcommand == "run".
Classes
- class flexmeasures.data.schemas.utils.MarshmallowClickMixin(*args, **kwargs)
- __init__(*args, **kwargs)
Exceptions
- exception flexmeasures.data.schemas.utils.FMValidationError(message: str | list | dict, field_name: str = '_schema', data: Mapping[str, Any] | Iterable[Mapping[str, Any]] | None = None, valid_data: list[Any] | dict[str, Any] | None = None, **kwargs)
Custom validation error class. It differs from the classic validation error by having two attributes, according to the USEF 2015 reference implementation. Subclasses of this error might adjust the status attribute accordingly.