flexmeasures.data.schemas.sensors

Classes

class flexmeasures.data.schemas.sensors.JSON(*, load_default: typing.Any = <marshmallow.missing>, missing: typing.Any = <marshmallow.missing>, dump_default: typing.Any = <marshmallow.missing>, default: typing.Any = <marshmallow.missing>, data_key: str | None = None, attribute: str | None = None, validate: None | typing.Callable[[typing.Any], typing.Any] | typing.Iterable[typing.Callable[[typing.Any], typing.Any]] = None, required: bool = False, allow_none: bool | None = None, load_only: bool = False, dump_only: bool = False, error_messages: dict[str, str] | None = None, metadata: typing.Mapping[str, typing.Any] | None = None, **additional_metadata)
_deserialize(value, attr, data, **kwargs) dict

Deserialize value. Concrete Field classes should implement this method.

Parameters:
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises:

ValidationError – In case of formatting or validation failure.

Returns:

The deserialized value.

Changed in version 2.0.0: Added attr and data parameters.

Changed in version 3.0.0: Added **kwargs to signature.

_serialize(value, attr, data, **kwargs) str

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes should implement this method.

Example:

class TitleCase(Field):
    def _serialize(self, value, attr, obj, **kwargs):
        if not value:
            return ''
        return str(value).title()
Parameters:
  • value – The value to be serialized.

  • attr (str) – The attribute or key on the object to be serialized.

  • obj (object) – The object the value was pulled from.

  • kwargs (dict) – Field-specific keyword arguments.

Returns:

The serialized value

class flexmeasures.data.schemas.sensors.SensorIdField(*args, **kwargs)

Field that deserializes to a Sensor and serializes back to an integer.

_deserialize(value: int, attr, obj, **kwargs) Sensor

Turn a sensor id into a Sensor.

_serialize(sensor: Sensor, attr, data, **kwargs) int

Turn a Sensor into a sensor id.

class flexmeasures.data.schemas.sensors.SensorSchema(*args, **kwargs)

Sensor schema, with validations.

class Meta
model

alias of Sensor

opts: SchemaOpts = <flask_marshmallow.sqla.SQLAlchemySchemaOpts object>
class flexmeasures.data.schemas.sensors.SensorSchemaMixin(*, only: types.StrSequenceOrSet | None = None, exclude: types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: types.StrSequenceOrSet = (), dump_only: types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)

Base sensor schema.

Here we include all fields which are implemented by timely_beliefs.SensorDBMixin All classes inheriting from timely beliefs sensor don’t need to repeat these. In a while, this schema can represent our unified Sensor class.

When subclassing, also subclass from ma.SQLAlchemySchema and add your own DB model class, e.g.:

class Meta:

model = Asset