|
| 1 | +"""Statistics models for Aquarea""" |
| 2 | +from __future__ import annotations |
| 3 | + |
| 4 | +from dataclasses import dataclass |
| 5 | + |
| 6 | +try: |
| 7 | + from enum import StrEnum |
| 8 | +except ImportError: |
| 9 | + from strenum import StrEnum |
| 10 | + |
| 11 | + |
| 12 | +class DateType(StrEnum): |
| 13 | + """Date types""" |
| 14 | + |
| 15 | + DAY = "date" |
| 16 | + WEEK = "week" |
| 17 | + MONTH = "month" |
| 18 | + YEAR = "year" |
| 19 | + |
| 20 | + |
| 21 | +class AggregationType(StrEnum): |
| 22 | + """Aggregation type""" |
| 23 | + |
| 24 | + HOURLY = "hourly" |
| 25 | + DAILY = "daily" |
| 26 | + MONTHLY = "monthly" |
| 27 | + |
| 28 | + |
| 29 | +class DataType(StrEnum): |
| 30 | + """Data type""" |
| 31 | + |
| 32 | + HEAT = "Heat" |
| 33 | + COOL = "AC" |
| 34 | + WATER_TANK = "HW" |
| 35 | + TOTAL = "Consume" |
| 36 | + |
| 37 | + |
| 38 | +class GenerationDataType(StrEnum): |
| 39 | + """Generation data type""" |
| 40 | + |
| 41 | + GHT = "GHT" |
| 42 | + GHR = "GHR" |
| 43 | + GHW = "GHW" |
| 44 | + |
| 45 | + |
| 46 | +class DataSetName(StrEnum): |
| 47 | + """Data set name""" |
| 48 | + |
| 49 | + ENERGY = "energyShowing" |
| 50 | + GENERATED = "generateEnergyShowing" |
| 51 | + COST = "costShowing" |
| 52 | + TEMPERATURE = "temperatureShowing" |
| 53 | + |
| 54 | + |
| 55 | +class Consumption: |
| 56 | + """Consumption""" |
| 57 | + |
| 58 | + def __init__(self, date_data: dict[str, object]): |
| 59 | + self._data = dict( |
| 60 | + [ |
| 61 | + ( |
| 62 | + dataset.get("name"), |
| 63 | + dict( |
| 64 | + [ |
| 65 | + (data.get("name"), data.get("values")) |
| 66 | + for data in dataset.get("data", []) |
| 67 | + ] |
| 68 | + ), |
| 69 | + ) |
| 70 | + for dataset in date_data.get("dataSets", []) |
| 71 | + ] |
| 72 | + ) |
| 73 | + self._start_date = date_data.get("startDate") |
| 74 | + self._aggregation = AggregationType(date_data.get("timeline", {}).get("type")) |
| 75 | + |
| 76 | + @property |
| 77 | + def energy(self) -> dict[DataType, list[float | None]]: |
| 78 | + """Energy consumption in kWh""" |
| 79 | + return self._data.get(DataSetName.ENERGY) |
| 80 | + |
| 81 | + @property |
| 82 | + def generation(self) -> dict[GenerationDataType, list[float]]: |
| 83 | + """Energy generation in kWh""" |
| 84 | + return self._data.get(DataSetName.GENERATED) |
| 85 | + |
| 86 | + @property |
| 87 | + def cost(self) -> dict[DataType, list[float]]: |
| 88 | + """Energy cost in configured currency""" |
| 89 | + return self._data.get(DataSetName.COST) |
| 90 | + |
| 91 | + @property |
| 92 | + def start_date(self) -> str: |
| 93 | + """Start date of the period""" |
| 94 | + return self._start_date |
| 95 | + |
| 96 | + @property |
| 97 | + def aggregation(self) -> AggregationType: |
| 98 | + """Aggregation type""" |
| 99 | + return self._aggregation |
0 commit comments