flexmeasures.data.schemas.scheduling
Modules
These descriptions are used in documentation/features/scheduling.rst and in OpenAPI. If you need to use a new .rst directive, update make_openapi_compatible accordingly, so it shows up nicely in OpenAPI. For instance: - the X directive is converted to a <abbr title="Y">X</abbr> HTML tag. - any footnote references, such as [#quantity_field]_, are stripped (these are meant for .rst docs to explain field types, which in OpenAPI is redundant, given that each field is already documented as being of an explicit type). |
|
Classes
- class flexmeasures.data.schemas.scheduling.AssetTriggerSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: Literal['exclude', 'include', 'raise'] | None = None)
- {
“start”: “2025-01-21T15:00+01”, “flex-model”: [
- {
“sensor”: 1, “soc-at-start”: “10 kWh”
}, {
“sensor”: 2, “soc-at-start”: “20 kWh”
},
]
}
- check_flex_model_sensors(data, **kwargs)
Verify that the flex-model’s sensors live under the asset for which a schedule is triggered.
- normalize_flex_context_format(data, **kwargs)
Normalize flex_context to always be a dict.
Accepts both: - Single commodity dict: {“commodity”: “electricity”, …} - List of commodity dicts: [{“commodity”: “electricity”, …}, {“commodity”: “heat”, …}] - MultiDict with multiple ‘flex-context’ entries (when JSON list is parsed by webargs)
If a list is provided, it is wrapped under the ‘commodities’ field. If a dict is provided, it is kept as-is. This ensures downstream code always sees a dict structure.
- class flexmeasures.data.schemas.scheduling.CommitmentSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: Literal['exclude', 'include', 'raise'] | None = None)
- class flexmeasures.data.schemas.scheduling.CommodityFlexContextSchema(*args, **kwargs)
- __init__(*args, **kwargs)
- class flexmeasures.data.schemas.scheduling.DBCommitmentSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: Literal['exclude', 'include', 'raise'] | None = None)
- class flexmeasures.data.schemas.scheduling.DBFlexContextSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: Literal['exclude', 'include', 'raise'] | None = None)
- _forbid_fixed_prices(data: dict, **kwargs)
Do not allow fixed consumption price or fixed production price in the flex-context fields saved in the db.
This is a temporary restriction as future iterations will allow fixed prices on these fields as well.
- class flexmeasures.data.schemas.scheduling.FlexContextSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: Literal['exclude', 'include', 'raise'] | None = None)
This schema defines fields that provide context to the portfolio to be optimized.
- check_prices(data: dict, original_data: dict, **kwargs)
Check assumptions about prices.
The flex-context must contain at most 1 consumption price and at most 1 production price field.
All prices must share the same currency.
Validate that all prices across commodity contexts share the same currency.
Each commodity context already computed its own normalized
shared_currency_unit(a base-unit currency string, e.g. “EUR”) via the inherited_try_to_convert_price_unitsschema-level validator. We simply compare those.
- class flexmeasures.data.schemas.scheduling.GetScheduleSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: Literal['exclude', 'include', 'raise'] | None = None)
- class flexmeasures.data.schemas.scheduling.MultiSensorFlexModelSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: Literal['exclude', 'include', 'raise'] | None = None)
This schema is agnostic to the underlying type of flex-model, which is governed by the chosen Scheduler instead. Therefore, the underlying type of flex-model is not deserialized.
So:
- {
“sensor”: 1, “soc-at-start”: “10 kWh”
}
becomes:
- {
“sensor”: <Sensor 1>, “sensor_flex_model”: {
“soc-at-start”: “10 kWh”
}
}
- unwrap_envelope(data, **kwargs)
Any field other than ‘sensor’ and ‘asset’ becomes part of the sensor’s flex-model.
- wrap_with_envelope(data, **kwargs)
Any field in the ‘sensor-flex-model’ field becomes a main field.
- class flexmeasures.data.schemas.scheduling.NoTimeSeriesSpecs(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: Literal['exclude', 'include', 'raise'] | None = None)
- class flexmeasures.data.schemas.scheduling.ScheduleSignConvention
Named constants for the three sign-convention modes of the get_schedule endpoint.
- Variables:
CONSUMPTION_POSITIVE – Always return schedules with consumption as positive values and production as negative values. This is the default and matches the view a consumer has of their device.
PRODUCTION_POSITIVE – Always return schedules with production as positive values and consumption as negative values. This matches the view a producer (or generator) has of their device.
WYSIWYG – Return the raw values from the database without any sign inversion, regardless of the sensor’s
consumption_is_positiveattribute. Useful when you want to see exactly what was stored.
Shared schema for fields common across commodities in flex-context and commodity-context.
Convert a price unit to a base currency used to express that price per MWh.
>>> FlexContextSchema()._to_currency_per_mwh("EUR/MWh") 'EUR' >>> FlexContextSchema()._to_currency_per_mwh("EUR/kWh") 'EUR'
Convert price units to the same unit and scale if they can (incl. same currency).
Dictionary mapping field_names ->
Fieldobjects
Fill in default breach prices.
This relies on _try_to_convert_price_units to run first, setting a shared currency unit.