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.kebab_to_snake(key: str) str

Convert kebab-case to snake_case.

flexmeasures.data.schemas.utils.snake_to_kebab(key: str) str

Convert snake_case to kebab-case.

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 run command (e.g. flexmeasures run or flask 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 the run subcommand context is current

(ctx.info_name == "run", ctx.invoked_subcommand is None).

  • flexmeasures run: modules are imported at group level, where the parent context has invoked_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.