Utility Models
Types
- class encodapy.config.types.AttributeTypes(*values)[source]
Bases:
EnumEnum class for the attribute types
- TIMESERIES = 'timeseries'
- VALUE = 'value'
- class encodapy.config.types.DataQueryTypes(*values)[source]
Bases:
EnumEnum class for the data query types, used for the functions to get data
- Variables:
- CALCULATION = 'calculation'
- CALIBRATION = 'calibration'
- class encodapy.config.types.FileExtensionTypes(*values)[source]
Bases:
EnumEnum class for file Extensions, used for the file interface and defines the possible file formats
- CSV = '.csv'
- JSON = '.json'
- class encodapy.config.types.Interfaces(*values)[source]
Bases:
EnumEnum class for the interfaces
- Variables:
- FILE = 'file'
- FIWARE = 'fiware'
- MQTT = 'mqtt'
- class encodapy.config.types.MQTTFormatTypes(*values)[source]
Bases:
EnumEnum class for MQTT format types Possible values: - PLAIN (plain): Plain format - FIWARE_ATTR (fiware-attr): FIWARE attribute format - FIWARE_CMDEXE (fiware-cmdexe): FIWARE command execution format - TEMPLATE (template): Template-based format
- FIWARE_ATTR = 'fiware-attr'
- FIWARE_CMDEXE = 'fiware-cmdexe'
- PLAIN = 'plain'
- TEMPLATE = 'template'
- class encodapy.config.types.TimerangeTypes(*values)[source]
Bases:
EnumEnum class for the timedelta types, used for the functions to get timeseries data
- Variables:
- ABSOLUTE = 'absolute'
- RELATIVE = 'relative'
- pydantic model encodapy.config.mqtt_messages_template.MQTTTemplateConfigDoc[source]
Model for MQTT template configuration.
Mock class for documentation purposes.
Note
In the actual implementation, topic and payload are jinja2.Template objects, time_format is a str as time format for the timestamp in the payload. This mock uses dict to avoid import issues during documentation generation.
For more information, see
MQTTTemplateConfig.
Datapoints
- pydantic model encodapy.utils.datapoints.DataPointGeneral[source]
Bases:
BaseModelModel for datapoints of the controller component.
- Variables:
value (
Any) – The value of the datapoint, which can be of various types (string, float, int, boolean, dictionary, list, DataFrame, or None).unit (
Optional[DataUnits]) – Optional unit of the datapoint, if applicable.time (
Optional[datetime]) – Optional timestamp of the datapoint, if applicable.
Show JSON schema
{ "title": "DataPointGeneral", "description": "Model for datapoints of the controller component.\n\nAttributes:\n value (Any): The value of the datapoint, which can be of various types (string, float, int, boolean, dictionary, list, DataFrame, or None).\n unit (Optional[DataUnits]): Optional unit of the datapoint, if applicable.\n time (Optional[datetime]): Optional timestamp of the datapoint, if applicable.", "type": "object", "properties": { "value": { "title": "Value" }, "unit": { "anyOf": [ { "$ref": "#/$defs/DataUnits" }, { "type": "null" } ], "default": null }, "time": { "anyOf": [ { "format": "date-time", "type": "string" }, { "type": "null" } ], "default": null, "title": "Time" } }, "$defs": { "DataUnits": { "description": "Possible units for the data\nUnits which are defined by Unit Code (https://unece.org/trade/cefact/UNLOCODE-Download\nor https://github.com/RWTH-EBC/FiLiP/blob/master/filip/data/unece-units/units_of_measure.csv)\nor here: https://unece.org/fileadmin/DAM/cefact/recommendations/rec20/rec20_rev3_Annex3e.pdf\n\nThe enum value is the standardized unit code (e.g., \"SEC\" for seconds).\nThe pint_unit attribute contains the corresponding pint unit string for conversion.\n\nTo add a new unit, add it to the DataUnits enum: UNIT_NAME = (\"CODE\", \"pint_string\")\nThe _UNIT_MAP will be generated automatically from the pint_unit attributes.\n\nUsage:\n - DataUnits.PERCENT.value -> \"P1\" (unit code, for serialization)\n - DataUnits.PERCENT.pint_unit -> \"percent\" (for pint conversion)\n - DataUnits(\"P1\") -> DataUnits.PERCENT (lookup by unit code)", "enum": [ "SEC", "HUR", "MIN", "DAY", "MON", "ANN", "CEL", "KEL", "LTR", "MTQ", "MQH", "MQS", "E32", "L2", "WTT", "KWT", "WHR", "KWH", "CMT", "MTR", "MTK", "MTS", "P1", "OHM", "VLT" ], "title": "DataUnits", "type": "string" } }, "required": [ "value" ] }
- pydantic model encodapy.utils.datapoints.DataPointNumber[source]
Bases:
DataPointGeneralModel for datapoints of the controller component.
- Variables:
value (
float | int) – The value of the datapoint, which is a number (float, int).unit (
Optional[DataUnits]) – Optional unit of the datapoint, if applicable.time (
Optional[datetime]) – Optional timestamp of the datapoint, if applicable.
Show JSON schema
{ "title": "DataPointNumber", "description": "Model for datapoints of the controller component.\n\nAttributes:\n value (float | int): The value of the datapoint, which is a number (float, int).\n unit (Optional[DataUnits]): Optional unit of the datapoint, if applicable.\n time (Optional[datetime]): Optional timestamp of the datapoint, if applicable.", "type": "object", "properties": { "value": { "anyOf": [ { "type": "number" }, { "type": "integer" } ], "title": "Value" }, "unit": { "anyOf": [ { "$ref": "#/$defs/DataUnits" }, { "type": "null" } ], "default": null }, "time": { "anyOf": [ { "format": "date-time", "type": "string" }, { "type": "null" } ], "default": null, "title": "Time" } }, "$defs": { "DataUnits": { "description": "Possible units for the data\nUnits which are defined by Unit Code (https://unece.org/trade/cefact/UNLOCODE-Download\nor https://github.com/RWTH-EBC/FiLiP/blob/master/filip/data/unece-units/units_of_measure.csv)\nor here: https://unece.org/fileadmin/DAM/cefact/recommendations/rec20/rec20_rev3_Annex3e.pdf\n\nThe enum value is the standardized unit code (e.g., \"SEC\" for seconds).\nThe pint_unit attribute contains the corresponding pint unit string for conversion.\n\nTo add a new unit, add it to the DataUnits enum: UNIT_NAME = (\"CODE\", \"pint_string\")\nThe _UNIT_MAP will be generated automatically from the pint_unit attributes.\n\nUsage:\n - DataUnits.PERCENT.value -> \"P1\" (unit code, for serialization)\n - DataUnits.PERCENT.pint_unit -> \"percent\" (for pint conversion)\n - DataUnits(\"P1\") -> DataUnits.PERCENT (lookup by unit code)", "enum": [ "SEC", "HUR", "MIN", "DAY", "MON", "ANN", "CEL", "KEL", "LTR", "MTQ", "MQH", "MQS", "E32", "L2", "WTT", "KWT", "WHR", "KWH", "CMT", "MTR", "MTK", "MTS", "P1", "OHM", "VLT" ], "title": "DataUnits", "type": "string" } }, "required": [ "value" ] }
- pydantic model encodapy.utils.datapoints.DataPointString[source]
Bases:
DataPointGeneralModel for datapoints of the controller component.
- Variables:
value (
str) – The value of the datapoint, which is a string.unit (
Optional[DataUnits]) – Optional unit of the datapoint, if applicable.time (
Optional[datetime]) – Optional timestamp of the datapoint, if applicable.
Show JSON schema
{ "title": "DataPointString", "description": "Model for datapoints of the controller component.\n\nAttributes:\n value (str): The value of the datapoint, which is a string.\n unit (Optional[DataUnits]): Optional unit of the datapoint, if applicable.\n time (Optional[datetime]): Optional timestamp of the datapoint, if applicable.", "type": "object", "properties": { "value": { "title": "Value", "type": "string" }, "unit": { "anyOf": [ { "$ref": "#/$defs/DataUnits" }, { "type": "null" } ], "default": null }, "time": { "anyOf": [ { "format": "date-time", "type": "string" }, { "type": "null" } ], "default": null, "title": "Time" } }, "$defs": { "DataUnits": { "description": "Possible units for the data\nUnits which are defined by Unit Code (https://unece.org/trade/cefact/UNLOCODE-Download\nor https://github.com/RWTH-EBC/FiLiP/blob/master/filip/data/unece-units/units_of_measure.csv)\nor here: https://unece.org/fileadmin/DAM/cefact/recommendations/rec20/rec20_rev3_Annex3e.pdf\n\nThe enum value is the standardized unit code (e.g., \"SEC\" for seconds).\nThe pint_unit attribute contains the corresponding pint unit string for conversion.\n\nTo add a new unit, add it to the DataUnits enum: UNIT_NAME = (\"CODE\", \"pint_string\")\nThe _UNIT_MAP will be generated automatically from the pint_unit attributes.\n\nUsage:\n - DataUnits.PERCENT.value -> \"P1\" (unit code, for serialization)\n - DataUnits.PERCENT.pint_unit -> \"percent\" (for pint conversion)\n - DataUnits(\"P1\") -> DataUnits.PERCENT (lookup by unit code)", "enum": [ "SEC", "HUR", "MIN", "DAY", "MON", "ANN", "CEL", "KEL", "LTR", "MTQ", "MQH", "MQS", "E32", "L2", "WTT", "KWT", "WHR", "KWH", "CMT", "MTR", "MTK", "MTS", "P1", "OHM", "VLT" ], "title": "DataUnits", "type": "string" } }, "required": [ "value" ] }
- pydantic model encodapy.utils.datapoints.DataPointDict[source]
Bases:
DataPointGeneralModel for datapoints of the controller component.
- Variables:
value (
dict) – The value of the datapoint, which is a dictionary.unit (
Optional[DataUnits]) – Optional unit of the datapoint, if applicable.time (
Optional[datetime]) – Optional timestamp of the datapoint, if applicable.
Show JSON schema
{ "title": "DataPointDict", "description": "Model for datapoints of the controller component.\n\nAttributes:\n value (dict): The value of the datapoint, which is a dictionary.\n unit (Optional[DataUnits]): Optional unit of the datapoint, if applicable.\n time (Optional[datetime]): Optional timestamp of the datapoint, if applicable.", "type": "object", "properties": { "value": { "title": "Value", "type": "object" }, "unit": { "anyOf": [ { "$ref": "#/$defs/DataUnits" }, { "type": "null" } ], "default": null }, "time": { "anyOf": [ { "format": "date-time", "type": "string" }, { "type": "null" } ], "default": null, "title": "Time" } }, "$defs": { "DataUnits": { "description": "Possible units for the data\nUnits which are defined by Unit Code (https://unece.org/trade/cefact/UNLOCODE-Download\nor https://github.com/RWTH-EBC/FiLiP/blob/master/filip/data/unece-units/units_of_measure.csv)\nor here: https://unece.org/fileadmin/DAM/cefact/recommendations/rec20/rec20_rev3_Annex3e.pdf\n\nThe enum value is the standardized unit code (e.g., \"SEC\" for seconds).\nThe pint_unit attribute contains the corresponding pint unit string for conversion.\n\nTo add a new unit, add it to the DataUnits enum: UNIT_NAME = (\"CODE\", \"pint_string\")\nThe _UNIT_MAP will be generated automatically from the pint_unit attributes.\n\nUsage:\n - DataUnits.PERCENT.value -> \"P1\" (unit code, for serialization)\n - DataUnits.PERCENT.pint_unit -> \"percent\" (for pint conversion)\n - DataUnits(\"P1\") -> DataUnits.PERCENT (lookup by unit code)", "enum": [ "SEC", "HUR", "MIN", "DAY", "MON", "ANN", "CEL", "KEL", "LTR", "MTQ", "MQH", "MQS", "E32", "L2", "WTT", "KWT", "WHR", "KWH", "CMT", "MTR", "MTK", "MTS", "P1", "OHM", "VLT" ], "title": "DataUnits", "type": "string" } }, "required": [ "value" ] }
- pydantic model encodapy.utils.datapoints.DataPointBool[source]
Bases:
DataPointGeneralModel for datapoints of the controller component.
- Variables:
value (
bool) – The value of the datapoint, which is a boolean.unit (
Optional[DataUnits]) – Optional unit of the datapoint, if applicable.time (
Optional[datetime]) – Optional timestamp of the datapoint, if applicable.
Show JSON schema
{ "title": "DataPointBool", "description": "Model for datapoints of the controller component.\n\nAttributes:\n value (bool): The value of the datapoint, which is a boolean.\n unit (Optional[DataUnits]): Optional unit of the datapoint, if applicable.\n time (Optional[datetime]): Optional timestamp of the datapoint, if applicable.", "type": "object", "properties": { "value": { "title": "Value", "type": "boolean" }, "unit": { "anyOf": [ { "$ref": "#/$defs/DataUnits" }, { "type": "null" } ], "default": null }, "time": { "anyOf": [ { "format": "date-time", "type": "string" }, { "type": "null" } ], "default": null, "title": "Time" } }, "$defs": { "DataUnits": { "description": "Possible units for the data\nUnits which are defined by Unit Code (https://unece.org/trade/cefact/UNLOCODE-Download\nor https://github.com/RWTH-EBC/FiLiP/blob/master/filip/data/unece-units/units_of_measure.csv)\nor here: https://unece.org/fileadmin/DAM/cefact/recommendations/rec20/rec20_rev3_Annex3e.pdf\n\nThe enum value is the standardized unit code (e.g., \"SEC\" for seconds).\nThe pint_unit attribute contains the corresponding pint unit string for conversion.\n\nTo add a new unit, add it to the DataUnits enum: UNIT_NAME = (\"CODE\", \"pint_string\")\nThe _UNIT_MAP will be generated automatically from the pint_unit attributes.\n\nUsage:\n - DataUnits.PERCENT.value -> \"P1\" (unit code, for serialization)\n - DataUnits.PERCENT.pint_unit -> \"percent\" (for pint conversion)\n - DataUnits(\"P1\") -> DataUnits.PERCENT (lookup by unit code)", "enum": [ "SEC", "HUR", "MIN", "DAY", "MON", "ANN", "CEL", "KEL", "LTR", "MTQ", "MQH", "MQS", "E32", "L2", "WTT", "KWT", "WHR", "KWH", "CMT", "MTR", "MTK", "MTS", "P1", "OHM", "VLT" ], "title": "DataUnits", "type": "string" } }, "required": [ "value" ] }
- pydantic model encodapy.utils.datapoints.DataPointMedium[source]
Bases:
DataPointGeneralModel for datapoints of the controller component which define the medium.
- Variables:
value (
Medium) – The value of the datapoint, which is a Medium representing the medium.unit (
Optional[DataUnits]) – Optional unit of the datapoint, if applicable.time (
Optional[datetime]) – Optional timestamp of the datapoint, if applicable.
Show JSON schema
{ "title": "DataPointMedium", "description": "Model for datapoints of the controller component which define the medium.\n\nAttributes:\n value (Medium): The value of the datapoint, which is a Medium representing the medium.\n unit (Optional[DataUnits]): Optional unit of the datapoint, if applicable.\n time (Optional[datetime]): Optional timestamp of the datapoint, if applicable.", "type": "object", "properties": { "value": { "$ref": "#/$defs/Medium" }, "unit": { "anyOf": [ { "$ref": "#/$defs/DataUnits" }, { "type": "null" } ], "default": null }, "time": { "anyOf": [ { "format": "date-time", "type": "string" }, { "type": "null" } ], "default": null, "title": "Time" } }, "$defs": { "DataUnits": { "description": "Possible units for the data\nUnits which are defined by Unit Code (https://unece.org/trade/cefact/UNLOCODE-Download\nor https://github.com/RWTH-EBC/FiLiP/blob/master/filip/data/unece-units/units_of_measure.csv)\nor here: https://unece.org/fileadmin/DAM/cefact/recommendations/rec20/rec20_rev3_Annex3e.pdf\n\nThe enum value is the standardized unit code (e.g., \"SEC\" for seconds).\nThe pint_unit attribute contains the corresponding pint unit string for conversion.\n\nTo add a new unit, add it to the DataUnits enum: UNIT_NAME = (\"CODE\", \"pint_string\")\nThe _UNIT_MAP will be generated automatically from the pint_unit attributes.\n\nUsage:\n - DataUnits.PERCENT.value -> \"P1\" (unit code, for serialization)\n - DataUnits.PERCENT.pint_unit -> \"percent\" (for pint conversion)\n - DataUnits(\"P1\") -> DataUnits.PERCENT (lookup by unit code)", "enum": [ "SEC", "HUR", "MIN", "DAY", "MON", "ANN", "CEL", "KEL", "LTR", "MTQ", "MQH", "MQS", "E32", "L2", "WTT", "KWT", "WHR", "KWH", "CMT", "MTR", "MTK", "MTS", "P1", "OHM", "VLT" ], "title": "DataUnits", "type": "string" }, "Medium": { "const": "water", "description": "Enum class for the mediums\n\nTODO: Add more mediums", "title": "Medium" } }, "required": [ "value" ] }
Units
- class encodapy.utils.units.DataUnits(*values)[source]
Bases:
EnumPossible units for the data Units which are defined by Unit Code (https://unece.org/trade/cefact/UNLOCODE-Download or https://github.com/RWTH-EBC/FiLiP/blob/master/filip/data/unece-units/units_of_measure.csv) or here: https://unece.org/fileadmin/DAM/cefact/recommendations/rec20/rec20_rev3_Annex3e.pdf
The enum value is the standardized unit code (e.g., “SEC” for seconds). The pint_unit attribute contains the corresponding pint unit string for conversion.
To add a new unit, add it to the DataUnits enum: UNIT_NAME = (“CODE”, “pint_string”) The _UNIT_MAP will be generated automatically from the pint_unit attributes.
- Usage:
DataUnits.PERCENT.value -> “P1” (unit code, for serialization)
DataUnits.PERCENT.pint_unit -> “percent” (for pint conversion)
DataUnits(“P1”) -> DataUnits.PERCENT (lookup by unit code)
- CMT = 'CMT'
- DAY = 'DAY'
- DEGREECELSIUS = 'CEL'
- E32 = 'E32'
- HOUR = 'HUR'
- KELVIN = 'KEL'
- KWH = 'KWH'
- KWT = 'KWT'
- L2 = 'L2'
- LITER = 'LTR'
- MINUTE = 'MIN'
- MONTH = 'MON'
- MQH = 'MQH'
- MQS = 'MQS'
- MTK = 'MTK'
- MTQ = 'MTQ'
- MTR = 'MTR'
- MTS = 'MTS'
- OHM = 'OHM'
- PERCENT = 'P1'
- SECOND = 'SEC'
- VLT = 'VLT'
- WHR = 'WHR'
- WTT = 'WTT'
- YEAR = 'ANN'
- class encodapy.utils.units.TimeUnits(*values)[source]
Bases:
EnumPossible time units for the time series data
TODO: Is it better to use standard time units? Like in the unit code?
- DAY = 'day'
- HOUR = 'hour'
- MINUTE = 'minute'
- MONTH = 'month'
- SECOND = 'second'
- encodapy.utils.units.adjust_unit_of_value(value: float | int, unit_actual: DataUnits, unit_target: DataUnits) float | None[source]
Function to adjust the unit of a value.
- Parameters:
- Returns:
Adjusted value, if adjustment factor could be determined.
- Return type:
Optional[float]
- Parameters:
- encodapy.utils.units.adjust_units(value: str | float | int | DataFrame | Series | list | dict | bool | None, unit_actual: DataUnits | None, unit_target: DataUnits | None, column_name: str | None = None) str | float | int | DataFrame | Series | list | dict | bool | None[source]
Function to adjust the unit of a datapoint. To use this function, simply pass the value, the actual unit and the target unit, like:
adjusted_value = adjust_units( value=10, unit_actual=DataUnits.SECOND, unit_target=DataUnits.MINUTE )
- Parameters:
value (
Optional[Union[str,float,int,pd.DataFrame,pd.Series,list,dict,bool]]) – Value to adjustunit_actual (
Optional[DataUnits]) – Actual unit of the valueunit_target (
Optional[DataUnits]) – Target unit of the valuecolumn_name (
Optional[str]) – Name of the column to adjust, if value is a DataFrame
- Returns:
Datapoint with adjusted unit, if adjustment factor could be determined, otherwise None
- Return type:
Optional[Union[str, float, int, pd.DataFrame, pd.Series, list, dict, bool]]
- Parameters:
- encodapy.utils.units.get_time_unit_seconds(time_unit: TimeUnits | str | DataUnits) float | None[source]
Function to get the seconds for a time unit using pint
- encodapy.utils.units.get_unit_adjustment_factor(unit_actual: DataUnits, unit_target: DataUnits) float | None[source]
Function to get the adjustment factor for the conversion of units
It is recommended to use adjust_units instead, which directly adjusts the value and unit of a datapoint, and handles more complex cases (e.g., DataFrames, Series, lists, dicts) and also handles the case when the value is None or not a number.
This function is still available for backward compatibility, but will be removed in future versions. It is recommended to switch to adjust_units, which is more robust and handles more cases.
- Parameters:
- Returns:
Adjustment factor for the conversion of the units, if found
- Return type:
Optional[float]
- Parameters:
TODO: Remove the function
Mediums
- class encodapy.utils.mediums.Medium(*values)[source]
Bases:
EnumEnum class for the mediums
TODO: Add more mediums
- WATER = 'water'
- pydantic model encodapy.utils.mediums.MediumParameters[source]
Bases:
BaseModelBase class for the medium parameters
Show JSON schema
{ "title": "MediumParameters", "description": "Base class for the medium parameters\n\nAttributes:\n cp (float): Specific heat capacity [kJ/kgK]\n rho (float): Density [kg/m\u00b3]", "type": "object", "properties": { "cp": { "title": "Cp", "type": "number" }, "rho": { "title": "Rho", "type": "number" } }, "required": [ "cp", "rho" ] }
- encodapy.utils.mediums.get_medium_parameter(medium: Medium, temperature: float | None = None) MediumParameters[source]
- Function to get the medium parameter
const values, if no temperature is set
- calculation of cp and rho (constant pressure) as approximation of Glück
“Zustandswerte Luft Wasser Dampf” ISBN 3-345-00487-9
- Parameters:
medium (
Mediums) – The mediumtemperature – float = None
- Returns:
The parameters of the medium
- Return type:
- Parameters: