From c8e6475ddf621a198b15a279eb46777f07517ffe Mon Sep 17 00:00:00 2001 From: Jessica Millar Date: Sun, 5 Jan 2025 17:53:59 -0500 Subject: [PATCH] Updated LayoutLite with FudgeFactor in Ha1Params --- .../Types/AslUtil/DeriveAslUtil.xslt | 6 +++ src/gjk/journal_keeper.py | 21 ++++------ src/gjk/named_types/asl_types.py | 2 + src/gjk/named_types/ha1_params.py | 5 ++- src/gjk/named_types/layout_lite.py | 8 ++-- src/gjk/named_types/scada_params.py | 14 +------ src/gjk/old_types/__init__.py | 8 ++++ src/gjk/old_types/ha1_params_001.py | 21 ++++++++++ src/gjk/old_types/layout_lite_003.py | 40 +++++++++++++++++++ src/gjk/old_types/scada_params_002.py | 35 ++++++++++++++++ tests/types/test_ha1_params.py | 5 ++- tests/types/test_layout_lite.py | 5 ++- tests/types/test_machine_states.py | 2 +- tests/types/test_scada_params.py | 2 +- 14 files changed, 136 insertions(+), 38 deletions(-) create mode 100644 src/gjk/old_types/ha1_params_001.py create mode 100644 src/gjk/old_types/layout_lite_003.py create mode 100644 src/gjk/old_types/scada_params_002.py diff --git a/CodeGenerationTools/GridworksCore/Types/AslUtil/DeriveAslUtil.xslt b/CodeGenerationTools/GridworksCore/Types/AslUtil/DeriveAslUtil.xslt index e5ea8a4..a576251 100644 --- a/CodeGenerationTools/GridworksCore/Types/AslUtil/DeriveAslUtil.xslt +++ b/CodeGenerationTools/GridworksCore/Types/AslUtil/DeriveAslUtil.xslt @@ -41,15 +41,18 @@ from gjk.old_types.gt_sh_multipurpose_telemetry_status import ( from gjk.old_types.gt_sh_simple_telemetry_status import GtShSimpleTelemetryStatus from gjk.old_types.gt_sh_status import GtShStatus from gjk.old_types.ha1_params_000 import Ha1Params000 +from gjk.old_types.ha1_params_001 import Ha1Params001 from gjk.old_types.i2c_multichannel_dt_relay_component_gt_001 import I2cMultichannelDtRelayComponentGt001 from gjk.old_types.layout_event import LayoutEvent from gjk.old_types.layout_lite_000 import LayoutLite000 from gjk.old_types.layout_lite_001 import LayoutLite001 from gjk.old_types.layout_lite_002 import LayoutLite002 +from gjk.old_types.layout_lite_003 import LayoutLite003 from gjk.old_types.my_channels import MyChannels from gjk.old_types.my_channels_event import MyChannelsEvent from gjk.old_types.report_000 import Report000 from gjk.old_types.scada_params_001 import ScadaParams001 +from gjk.old_types.scada_params_002 import ScadaParams002 from gjk.old_types.snapshot_spaceheat_000 import SnapshotSpaceheat000 from gjk.old_types.snapshot_spaceheat_001 import SnapshotSpaceheat001 from gjk.old_types.telemetry_snapshot_spaceheat import TelemetrySnapshotSpaceheat @@ -88,15 +91,18 @@ def types() -> List[GwBase]: GtShSimpleTelemetryStatus, GtShStatus, Ha1Params000, + Ha1Params001, I2cMultichannelDtRelayComponentGt001, LayoutEvent, LayoutLite000, LayoutLite001, LayoutLite002, + LayoutLite003, MyChannels, MyChannelsEvent, Report000, ScadaParams001, + ScadaParams002, SnapshotSpaceheat000, SnapshotSpaceheat001, TelemetrySnapshotSpaceheat, diff --git a/src/gjk/journal_keeper.py b/src/gjk/journal_keeper.py index 2705308..fb4c814 100644 --- a/src/gjk/journal_keeper.py +++ b/src/gjk/journal_keeper.py @@ -1,11 +1,10 @@ """JournalKeeper""" - import logging import threading import time import uuid from contextlib import contextmanager -from typing import List +from typing import Any, List import pendulum from gw.named_types import GwBase @@ -38,7 +37,7 @@ TicklistReedReport, ) from gjk.named_types.asl_types import TypeByName -from gjk.old_types import GridworksEventReport, LayoutEvent +from gjk.old_types import GridworksEventReport, LayoutEvent, LayoutLite003 from gjk.type_helpers import Message, Reading from gjk.utils import FileNameMeta, str_from_ms @@ -224,11 +223,7 @@ def route_mqtt_message(self, from_alias: str, payload: GwBase) -> None: self.report_from_scada(payload) except Exception as e: raise Exception(f"Trouble with report_from_scada: {e}") from e - elif payload.type_name == LayoutEvent.type_name_value(): - try: - self.old_layout_event_from_scada(payload) - except Exception as e: - raise Exception(f"Trouble with layout_event_from_scada: {e}") from e + def ticklist_hall_report_from_scada( self, from_alias: str, t: TicklistHallReport @@ -291,7 +286,11 @@ def timestamped_message_received( with self.get_db() as db: insert_single_message(db, pyd_to_sql(msg)) - def layout_lite_received(self, layout: LayoutLite) -> None: + def layout_lite_received(self, layout: GwBase) -> None: + """ + Could be a couple different versions + """ + print(f"Storing LayoutLite Version {layout.version}") msg = Message( message_id=layout.message_id, from_alias=layout.from_g_node_alias, @@ -422,10 +421,6 @@ def old_gridworks_event_report_from_scada(self, t: GridworksEventReport) -> None self.msg = msg print("Set this up when loading old data") - def old_layout_event_from_scada(self, t: LayoutEvent) -> None: - layout = t.layout - self.layout_lite_received(layout) - def main(self) -> None: while True: time.sleep(3600) diff --git a/src/gjk/named_types/asl_types.py b/src/gjk/named_types/asl_types.py index 9c2cd1b..49920f2 100644 --- a/src/gjk/named_types/asl_types.py +++ b/src/gjk/named_types/asl_types.py @@ -58,6 +58,7 @@ from gjk.old_types.layout_lite_000 import LayoutLite000 from gjk.old_types.layout_lite_001 import LayoutLite001 from gjk.old_types.layout_lite_002 import LayoutLite002 +from gjk.old_types.layout_lite_003 import LayoutLite003 from gjk.old_types.my_channels import MyChannels from gjk.old_types.my_channels_event import MyChannelsEvent from gjk.old_types.report_000 import Report000 @@ -88,6 +89,7 @@ def types() -> List[GwBase]: LayoutLite000, LayoutLite001, LayoutLite002, + LayoutLite003, MyChannels, MyChannelsEvent, Report000, diff --git a/src/gjk/named_types/ha1_params.py b/src/gjk/named_types/ha1_params.py index 4f3540d..d0f305c 100644 --- a/src/gjk/named_types/ha1_params.py +++ b/src/gjk/named_types/ha1_params.py @@ -1,4 +1,4 @@ -"""Type ha1.params, version 001""" +"""Type ha1.params, version 002""" from typing import Literal @@ -17,5 +17,6 @@ class Ha1Params(GwBase): dd_delta_t_f: StrictInt hp_max_kw_th: float max_ewt_f: StrictInt + load_overestimation_percent: StrictInt type_name: Literal["ha1.params"] = "ha1.params" - version: Literal["001"] = "001" + version: Literal["002"] = "002" diff --git a/src/gjk/named_types/layout_lite.py b/src/gjk/named_types/layout_lite.py index 8304c40..44b1bb9 100644 --- a/src/gjk/named_types/layout_lite.py +++ b/src/gjk/named_types/layout_lite.py @@ -1,4 +1,4 @@ -"""Type layout.lite, version 003""" +"""Type layout.lite, version 004""" from typing import List, Literal @@ -7,9 +7,7 @@ from gjk.named_types.data_channel_gt import DataChannelGt from gjk.named_types.ha1_params import Ha1Params -from gjk.named_types.i2c_multichannel_dt_relay_component_gt import ( - I2cMultichannelDtRelayComponentGt, -) +from gjk.named_types.i2c_multichannel_dt_relay_component_gt import I2cMultichannelDtRelayComponentGt from gjk.named_types.pico_flow_module_component_gt import PicoFlowModuleComponentGt from gjk.named_types.pico_tank_module_component_gt import PicoTankModuleComponentGt from gjk.named_types.spaceheat_node_gt import SpaceheatNodeGt @@ -37,4 +35,4 @@ class LayoutLite(GwBase): ha1_params: Ha1Params i2c_relay_component: I2cMultichannelDtRelayComponentGt type_name: Literal["layout.lite"] = "layout.lite" - version: Literal["003"] = "003" + version: Literal["004"] = "004" diff --git a/src/gjk/named_types/scada_params.py b/src/gjk/named_types/scada_params.py index e94dd2f..69f02ca 100644 --- a/src/gjk/named_types/scada_params.py +++ b/src/gjk/named_types/scada_params.py @@ -1,10 +1,8 @@ -"""Type scada.params, version 002""" +"""Type scada.params, version 003""" from typing import Literal, Optional from gw.named_types import GwBase -from gw.utils import snake_to_pascal -from pydantic import ConfigDict from gjk.named_types.ha1_params import Ha1Params from gjk.property_format import ( @@ -24,12 +22,4 @@ class ScadaParams(GwBase): new_params: Optional[Ha1Params] = None old_params: Optional[Ha1Params] = None type_name: Literal["scada.params"] = "scada.params" - version: Literal["002"] = "002" - - model_config = ConfigDict( - alias_generator=snake_to_pascal, - extra="allow", - frozen=True, - populate_by_name=True, - use_enum_values=True, - ) + version: Literal["003"] = "003" diff --git a/src/gjk/old_types/__init__.py b/src/gjk/old_types/__init__.py index a6b4321..015f2df 100644 --- a/src/gjk/old_types/__init__.py +++ b/src/gjk/old_types/__init__.py @@ -15,13 +15,17 @@ from gjk.old_types.gt_sh_simple_telemetry_status import GtShSimpleTelemetryStatus from gjk.old_types.gt_sh_status import GtShStatus from gjk.old_types.ha1_params_000 import Ha1Params000 +from gjk.old_types.ha1_params_001 import Ha1Params001 from gjk.old_types.layout_event import LayoutEvent from gjk.old_types.layout_lite_000 import LayoutLite000 from gjk.old_types.layout_lite_001 import LayoutLite001 +from gjk.old_types.layout_lite_002 import LayoutLite002 +from gjk.old_types.layout_lite_003 import LayoutLite003 from gjk.old_types.my_channels import MyChannels from gjk.old_types.my_channels_event import MyChannelsEvent from gjk.old_types.report_000 import Report000 from gjk.old_types.scada_params_001 import ScadaParams001 +from gjk.old_types.scada_params_002 import ScadaParams002 from gjk.old_types.snapshot_spaceheat_000 import SnapshotSpaceheat000 from gjk.old_types.snapshot_spaceheat_001 import SnapshotSpaceheat001 from gjk.old_types.telemetry_snapshot_spaceheat import TelemetrySnapshotSpaceheat @@ -38,13 +42,17 @@ "GtShSimpleTelemetryStatus", "GtShStatus", "Ha1Params000", + "Ha1Params001", "LayoutEvent", "LayoutLite000", "LayoutLite001", + "LayoutLite002", + "LayoutLite003", "MyChannels", "MyChannelsEvent", "Report000", "ScadaParams001", + "ScadaParams002", "SnapshotSpaceheat000", "SnapshotSpaceheat001", "TelemetrySnapshotSpaceheat", diff --git a/src/gjk/old_types/ha1_params_001.py b/src/gjk/old_types/ha1_params_001.py new file mode 100644 index 0000000..7f3ec52 --- /dev/null +++ b/src/gjk/old_types/ha1_params_001.py @@ -0,0 +1,21 @@ +"""Type ha1.params, version 001""" + +from typing import Literal + +from gw.named_types import GwBase +from pydantic import StrictInt + + +class Ha1Params001(GwBase): + alpha_times10: StrictInt + beta_times100: StrictInt + gamma_ex6: StrictInt + intermediate_power_kw: float + intermediate_rswt_f: StrictInt + dd_power_kw: float + dd_rswt_f: StrictInt + dd_delta_t_f: StrictInt + hp_max_kw_th: float + max_ewt_f: StrictInt + type_name: Literal["ha1.params"] = "ha1.params" + version: Literal["001"] = "001" diff --git a/src/gjk/old_types/layout_lite_003.py b/src/gjk/old_types/layout_lite_003.py new file mode 100644 index 0000000..e24d6d4 --- /dev/null +++ b/src/gjk/old_types/layout_lite_003.py @@ -0,0 +1,40 @@ +"""Type layout.lite, version 003""" + +from typing import List, Literal + +from gw.named_types import GwBase +from pydantic import PositiveInt + +from gjk.named_types.data_channel_gt import DataChannelGt +from gjk.named_types.i2c_multichannel_dt_relay_component_gt import ( + I2cMultichannelDtRelayComponentGt, +) +from gjk.named_types.pico_flow_module_component_gt import PicoFlowModuleComponentGt +from gjk.named_types.pico_tank_module_component_gt import PicoTankModuleComponentGt +from gjk.named_types.spaceheat_node_gt import SpaceheatNodeGt +from gjk.named_types.synth_channel_gt import SynthChannelGt +from gjk.old_types.ha1_params_001 import Ha1Params001 +from gjk.property_format import ( + LeftRightDot, + UTCMilliseconds, + UUID4Str, +) + + +class LayoutLite003(GwBase): + from_g_node_alias: LeftRightDot + from_g_node_instance_id: UUID4Str + message_created_ms: UTCMilliseconds + message_id: UUID4Str + strategy: str + zone_list: List[str] + total_store_tanks: PositiveInt + sh_nodes: List[SpaceheatNodeGt] + data_channels: List[DataChannelGt] + synth_channels: List[SynthChannelGt] + tank_module_components: List[PicoTankModuleComponentGt] + flow_module_components: List[PicoFlowModuleComponentGt] + ha1_params: Ha1Params001 + i2c_relay_component: I2cMultichannelDtRelayComponentGt + type_name: Literal["layout.lite"] = "layout.lite" + version: Literal["003"] = "003" diff --git a/src/gjk/old_types/scada_params_002.py b/src/gjk/old_types/scada_params_002.py new file mode 100644 index 0000000..d1915c0 --- /dev/null +++ b/src/gjk/old_types/scada_params_002.py @@ -0,0 +1,35 @@ +"""Type scada.params, version 002""" + +from typing import Literal, Optional + +from gw.named_types import GwBase +from gw.utils import snake_to_pascal +from pydantic import ConfigDict + +from gjk.old_types.ha1_params_001 import Ha1Params001 +from gjk.property_format import ( + LeftRightDot, + SpaceheatName, + UTCMilliseconds, + UUID4Str, +) + + +class ScadaParams002(GwBase): + from_g_node_alias: LeftRightDot + from_name: SpaceheatName + to_name: SpaceheatName + unix_time_ms: UTCMilliseconds + message_id: UUID4Str + new_params: Optional[Ha1Params001] = None + old_params: Optional[Ha1Params001] = None + type_name: Literal["scada.params"] = "scada.params" + version: Literal["002"] = "002" + + model_config = ConfigDict( + alias_generator=snake_to_pascal, + extra="allow", + frozen=True, + populate_by_name=True, + use_enum_values=True, + ) diff --git a/tests/types/test_ha1_params.py b/tests/types/test_ha1_params.py index d5bb94f..8132fba 100644 --- a/tests/types/test_ha1_params.py +++ b/tests/types/test_ha1_params.py @@ -1,4 +1,4 @@ -"""Tests ha1.params type, version 001""" +"""Tests ha1.params type, version 002""" from gjk.named_types import Ha1Params @@ -15,8 +15,9 @@ def test_ha1_params_generated() -> None: "DdDeltaTF": 20, "HpMaxKwTh": 6, "MaxEwtF": 170, + "LoadOverestimationPercent": 10, "TypeName": "ha1.params", - "Version": "001", + "Version": "002", } assert Ha1Params.from_dict(d).to_dict() == d diff --git a/tests/types/test_layout_lite.py b/tests/types/test_layout_lite.py index 82d4c55..31e2cbb 100644 --- a/tests/types/test_layout_lite.py +++ b/tests/types/test_layout_lite.py @@ -23,8 +23,9 @@ def test_layout_lite_generated() -> None: "DdDeltaTF": 20, "HpMaxKwTh": 6.0, "MaxEwtF": 170, + "LoadOverestimationPercent": 10, "TypeName": "ha1.params", - "Version": "001", + "Version": "002", }, "ShNodes": [ { @@ -296,7 +297,7 @@ def test_layout_lite_generated() -> None: "Version": "002", }, "TypeName": "layout.lite", - "Version": "003", + "Version": "004", } t = LayoutLite.from_dict(d) # TODO : figure out why LayoutLite.from_dict(d).to_dict() == d fails diff --git a/tests/types/test_machine_states.py b/tests/types/test_machine_states.py index 50fa849..882b9e1 100644 --- a/tests/types/test_machine_states.py +++ b/tests/types/test_machine_states.py @@ -5,7 +5,7 @@ def test_machine_states_generated() -> None: d = { - "MachineHandle": "h.pico-cycler", + "MachineHandle": "auto.pico-cycler", "StateEnum": "pico.cycler.state", "StateList": ["PicosLive"], "UnixMsList": [1731168353695], diff --git a/tests/types/test_scada_params.py b/tests/types/test_scada_params.py index a8e4ea4..4748865 100644 --- a/tests/types/test_scada_params.py +++ b/tests/types/test_scada_params.py @@ -11,7 +11,7 @@ def test_scada_params_generated() -> None: "UnixTimeMs": 1731637846788, "MessageId": "37b64437-f5b2-4a80-b5fc-3d5a9f6b5b59", "TypeName": "scada.params", - "Version": "002", + "Version": "003", } assert ScadaParams.from_dict(d).to_dict() == d