Skip to content

Commit 2cf27b7

Browse files
committed
current/normal_phases rewrite to match jvm sdk
Signed-off-by: Max Chesterfield <max.chesterfield@zepben.com>
1 parent 9c267fb commit 2cf27b7

File tree

20 files changed

+357
-345
lines changed

20 files changed

+357
-345
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* `MeasurementValue.time_stamp`
88
* `RelayInfo.curve_setting`
99
* `RelayInfo.reclose_fast`
10+
* Removed `TracedPhases`. `Terminal.normalPhases` and `Terminal.currentPhases` should be used instead of `Terminal.tracedPhases` going forward. (missed in 0.48.0)
1011

1112
### New Features
1213
* Added the following new CIM classes:

src/zepben/ewb/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@
240240
# END CIM MODEL #
241241
#################
242242

243-
from zepben.ewb.model.phases import *
244243
from zepben.ewb.model.resistance_reactance import *
245244

246245
from zepben.ewb.services.network.tracing.util import *

src/zepben/ewb/model/cim/iec61970/base/core/terminal.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
# Copyright 2024 Zeppelin Bend Pty Ltd
1+
# Copyright 2026 Zeppelin Bend Pty Ltd
22
# This Source Code Form is subject to the terms of the Mozilla Public
33
# License, v. 2.0. If a copy of the MPL was not distributed with this
44
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
55

66
from __future__ import annotations
77

8+
__all__ = ["Terminal"]
9+
810
from typing import Optional, Generator
911
from typing import TYPE_CHECKING
1012
from weakref import ref, ReferenceType
@@ -13,16 +15,13 @@
1315
from zepben.ewb.model.cim.iec61970.base.core.feeder import Feeder
1416
from zepben.ewb.model.cim.iec61970.base.core.phase_code import PhaseCode
1517
from zepben.ewb.model.cim.iec61970.base.wires.busbar_section import BusbarSection
16-
from zepben.ewb.model.phases import TracedPhases
1718
from zepben.ewb.services.network.tracing.feeder.feeder_direction import FeederDirection
18-
from zepben.ewb.services.network.tracing.phases.phase_status import PhaseStatus, NormalPhases, CurrentPhases
19+
from zepben.ewb.services.network.tracing.phases.phase_status import PhaseStatus
1920

2021
if TYPE_CHECKING:
2122
from zepben.ewb.model.cim.iec61970.base.core.conducting_equipment import ConductingEquipment
2223
from zepben.ewb.model.cim.iec61970.base.core.connectivity_node import ConnectivityNode
2324

24-
__all__ = ["Terminal"]
25-
2625

2726
class Terminal(AcDcTerminal):
2827
"""
@@ -36,10 +35,6 @@ class Terminal(AcDcTerminal):
3635
phases: PhaseCode = PhaseCode.ABC
3736
"""Represents the normal network phasing condition. If the attribute is missing three phases (ABC) shall be assumed."""
3837

39-
traced_phases: TracedPhases = TracedPhases()
40-
"""the phase object representing the traced phases in both the normal and current network. If properly configured you would expect the normal state phases
41-
to match those in `phases`"""
42-
4338
sequence_number: int = 0
4439
"""The orientation of the terminal connections for a multiple terminal conducting equipment. The sequence numbering starts with 1 and additional
4540
terminals should follow in increasing order. The first terminal is the "starting point" for a two terminal branch."""
@@ -56,8 +51,16 @@ class Terminal(AcDcTerminal):
5651
"""This is a weak reference to the connectivity node so if a Network object goes out of scope, holding a single conducting equipment
5752
reference does not cause everything connected to it in the network to stay in memory."""
5853

54+
_normal_phases: PhaseStatus = None
55+
_current_phases: PhaseStatus = None
56+
5957
def __init__(self, conducting_equipment: ConductingEquipment = None, connectivity_node: ConnectivityNode = None, **kwargs):
6058
super(Terminal, self).__init__(**kwargs)
59+
60+
self._normal_phases = PhaseStatus(self)
61+
62+
self._current_phases = PhaseStatus(self)
63+
6164
if conducting_equipment:
6265
self.conducting_equipment = conducting_equipment
6366

@@ -69,13 +72,13 @@ def __init__(self, conducting_equipment: ConductingEquipment = None, connectivit
6972

7073
@property
7174
def normal_phases(self) -> PhaseStatus:
72-
""" Convenience method for accessing the normal phases"""
73-
return NormalPhases(self)
75+
"""The status of phases as traced for the normal state of the network."""
76+
return self._normal_phases
7477

7578
@property
7679
def current_phases(self) -> PhaseStatus:
77-
""" Convenience method for accessing the current phases"""
78-
return CurrentPhases(self)
80+
"""The status of phases as traced for the current state of the network.gi"""
81+
return self._current_phases
7982

8083
@property
8184
def conducting_equipment(self):
@@ -146,9 +149,10 @@ def other_terminals(self) -> Generator[Terminal]:
146149
*
147150
:return: A `Generator` of terminals that share the same `ConductingEquipment` as this `Terminal`.
148151
"""
149-
for t in self.conducting_equipment.terminals:
150-
if t is not self:
151-
yield t
152+
if self.conducting_equipment is not None:
153+
for t in self.conducting_equipment.terminals:
154+
if t is not self:
155+
yield t
152156

153157
def connect(self, connectivity_node: ConnectivityNode):
154158
self.connectivity_node = connectivity_node

src/zepben/ewb/model/phases.py

Lines changed: 0 additions & 168 deletions
This file was deleted.

src/zepben/ewb/services/common/base_service_comparator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def _add_if_different(diff: ObjectDifference, name: str, difference: Optional[Di
219219
diff.differences[name] = difference
220220

221221
@staticmethod
222-
def _calculate_values_diff(prop: Union[MemberDescriptorType, property], diff: ObjectDifference) -> Optional[ValueDifference]:
222+
def _calculate_values_diff(prop: Union[MemberDescriptorType, property], diff: ObjectDifference, to_comparable: Callable[[property], Any] = (lambda it: it)) -> Optional[ValueDifference]:
223223
if isinstance(prop, property):
224224
s_val = getattr(diff.source, prop.fget.__name__) if diff.source else None
225225
t_val = getattr(diff.target, prop.fget.__name__) if diff.target else None
@@ -230,7 +230,7 @@ def _calculate_values_diff(prop: Union[MemberDescriptorType, property], diff: Ob
230230
if (type(s_val) == float) or (type(t_val) == float):
231231
raise TypeError(f"Using wrong comparator for {prop}, use _calculate_float_diff instead.")
232232

233-
if s_val == t_val:
233+
if to_comparable(s_val) == to_comparable(t_val):
234234
return None
235235
else:
236236
return ValueDifference(s_val, t_val)

src/zepben/ewb/services/network/network_service_comparator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,9 @@ def _compare_terminal(self, source: Terminal, target: Terminal) -> ObjectDiffere
764764
Terminal.sequence_number,
765765
Terminal.normal_feeder_direction,
766766
Terminal.current_feeder_direction,
767-
Terminal.phases
768767
)
768+
self._add_if_different(diff, Terminal.normal_phases.fget.__name__, self._calculate_values_diff(Terminal.normal_phases, diff, to_comparable=lambda it: it._phase_status_internal))
769+
self._add_if_different(diff, Terminal.current_phases.fget.__name__, self._calculate_values_diff(Terminal.current_phases, diff, to_comparable=lambda it: it._phase_status_internal))
769770

770771
return self._compare_ac_dc_terminal(diff)
771772

0 commit comments

Comments
 (0)