Skip to content

Commit

Permalink
Merge pull request #107 from thegridelectric/fudge-factor
Browse files Browse the repository at this point in the history
Updated LayoutLite with FudgeFactor in Ha1Params
  • Loading branch information
jessicamillar authored Jan 5, 2025
2 parents f20a6ad + c8e6475 commit f63513a
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 8 additions & 13 deletions src/gjk/journal_keeper.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/gjk/named_types/asl_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -88,6 +89,7 @@ def types() -> List[GwBase]:
LayoutLite000,
LayoutLite001,
LayoutLite002,
LayoutLite003,
MyChannels,
MyChannelsEvent,
Report000,
Expand Down
5 changes: 3 additions & 2 deletions src/gjk/named_types/ha1_params.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Type ha1.params, version 001"""
"""Type ha1.params, version 002"""

from typing import Literal

Expand All @@ -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"
8 changes: 3 additions & 5 deletions src/gjk/named_types/layout_lite.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Type layout.lite, version 003"""
"""Type layout.lite, version 004"""

from typing import List, Literal

Expand All @@ -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
Expand Down Expand Up @@ -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"
14 changes: 2 additions & 12 deletions src/gjk/named_types/scada_params.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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"
8 changes: 8 additions & 0 deletions src/gjk/old_types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,13 +42,17 @@
"GtShSimpleTelemetryStatus",
"GtShStatus",
"Ha1Params000",
"Ha1Params001",
"LayoutEvent",
"LayoutLite000",
"LayoutLite001",
"LayoutLite002",
"LayoutLite003",
"MyChannels",
"MyChannelsEvent",
"Report000",
"ScadaParams001",
"ScadaParams002",
"SnapshotSpaceheat000",
"SnapshotSpaceheat001",
"TelemetrySnapshotSpaceheat",
Expand Down
21 changes: 21 additions & 0 deletions src/gjk/old_types/ha1_params_001.py
Original file line number Diff line number Diff line change
@@ -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"
40 changes: 40 additions & 0 deletions src/gjk/old_types/layout_lite_003.py
Original file line number Diff line number Diff line change
@@ -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"
35 changes: 35 additions & 0 deletions src/gjk/old_types/scada_params_002.py
Original file line number Diff line number Diff line change
@@ -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,
)
5 changes: 3 additions & 2 deletions tests/types/test_ha1_params.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tests ha1.params type, version 001"""
"""Tests ha1.params type, version 002"""

from gjk.named_types import Ha1Params

Expand All @@ -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
5 changes: 3 additions & 2 deletions tests/types/test_layout_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/types/test_machine_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion tests/types/test_scada_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f63513a

Please sign in to comment.