flexmeasures.data.services.sensors

Functions

flexmeasures.data.services.sensors.build_asset_jobs_data(asset: GenericAsset) list[dict]

Get all jobs data for an asset Returns a list of dictionaries, each containing the following keys: - job_id: id of a job - queue: job queue (scheduling or forecasting) - asset_or_sensor_type: type of an asset that is linked to the job (asset or sensor) - asset_id: id of sensor or asset - status: job status (e.g finished, failed, etc) - err: job error (equals to None when there was no error for a job) - enqueued_at: time when the job was enqueued

flexmeasures.data.services.sensors.build_sensor_status_data(asset: GenericAsset, now: datetime | None = None) list[dict]

Get data connectivity status information for each sensor in given asset and its children Returns a list of dictionaries, each containing the following keys: - id: sensor id - name: sensor name - asset_name: asset name - staleness: staleness of the sensor (for how long the sensor data is stale) - stale: whether the sensor is stale - staleness_since: time since sensor data is considered stale - reason: reason for staleness

flexmeasures.data.services.sensors.get_most_recent_knowledge_time(sensor: Sensor, staleness_search: dict) datetime | None

Get the knowledge time of the sensor’s most recent event.

This knowledge time represents when you could have known about the event (specifically, when you could have formed an ex-post belief about it).

flexmeasures.data.services.sensors.get_sensors(account: Account | list[Account] | None, include_public_assets: bool = False, sensor_id_allowlist: list[int] | None = None, sensor_name_allowlist: list[str] | None = None) list[Sensor]

Return a list of Sensor objects that belong to the given account, and/or public sensors.

Parameters:
  • account – select only sensors from this account (or list of accounts)

  • include_public_assets – if True, include sensors that belong to a public asset

  • sensor_id_allowlist – optionally, allow only sensors whose id is in this list

  • sensor_name_allowlist – optionally, allow only sensors whose name is in this list

flexmeasures.data.services.sensors.get_staleness(sensor: Sensor, staleness_search: dict, now: datetime) timedelta | None

Get the staleness of the sensor.

The staleness is defined relative to the knowledge time of the most recent event, rather than to its belief time. Basically, that means that we don’t really care when the data arrived, as long as the available data is about what we should be able to know by now.

Parameters:
  • sensor – The sensor to compute the staleness for.

  • staleness_search – Deserialized keyword arguments to TimedBelief.search.

  • now – Datetime representing now, used both to mask future beliefs, and to measures staleness against.

flexmeasures.data.services.sensors.get_status(sensor: Sensor, now: datetime, status_specs: dict | None = None) dict

Get the status of the sensor Main part of result here is a stale value, which is True if the sensor is stale, False otherwise. Other values are just context information for the stale value.

flexmeasures.data.services.sensors.get_status_specs(sensor: Sensor) dict

Get status specs from a given sensor.