zepben.ewb 1.0.0b2__py3-none-any.whl → 1.0.0b3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zepben/ewb/services/network/tracing/networktrace/actions/equipment_tree_builder.py +37 -4
- zepben/ewb/services/network/tracing/networktrace/actions/tree_node.py +8 -10
- {zepben_ewb-1.0.0b2.dist-info → zepben_ewb-1.0.0b3.dist-info}/METADATA +1 -1
- {zepben_ewb-1.0.0b2.dist-info → zepben_ewb-1.0.0b3.dist-info}/RECORD +7 -7
- {zepben_ewb-1.0.0b2.dist-info → zepben_ewb-1.0.0b3.dist-info}/WHEEL +0 -0
- {zepben_ewb-1.0.0b2.dist-info → zepben_ewb-1.0.0b3.dist-info}/licenses/LICENSE +0 -0
- {zepben_ewb-1.0.0b2.dist-info → zepben_ewb-1.0.0b3.dist-info}/top_level.txt +0 -0
|
@@ -34,15 +34,40 @@ class EquipmentTreeBuilder(StepActionWithContextValue):
|
|
|
34
34
|
>>> .add_step_action(tree_builder)).run()
|
|
35
35
|
"""
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def __init__(self):
|
|
37
|
+
def __init__(self, calculate_leaves: bool = False):
|
|
40
38
|
super().__init__(key=str(uuid.uuid4()))
|
|
41
39
|
|
|
40
|
+
self._roots: dict[ConductingEquipment, EquipmentTreeNode] = {}
|
|
41
|
+
self._leaves: set[EquipmentTreeNode] = set()
|
|
42
|
+
|
|
43
|
+
self._calculate_leaves = calculate_leaves
|
|
44
|
+
|
|
42
45
|
@property
|
|
43
46
|
def roots(self) -> Generator[TreeNode[ConductingEquipment], None, None]:
|
|
44
47
|
return (r for r in self._roots.values())
|
|
45
48
|
|
|
49
|
+
def recurse_nodes(self) -> Generator[TreeNode[ConductingEquipment], None, None]:
|
|
50
|
+
"""
|
|
51
|
+
Returns a generator that will yield every node in the tree structure.
|
|
52
|
+
"""
|
|
53
|
+
def recurse(node: TreeNode[ConductingEquipment]):
|
|
54
|
+
yield node
|
|
55
|
+
for child in node.children:
|
|
56
|
+
yield from recurse(child)
|
|
57
|
+
|
|
58
|
+
for root in self._roots.values():
|
|
59
|
+
yield from recurse(root)
|
|
60
|
+
|
|
61
|
+
@property
|
|
62
|
+
def leaves(self) -> set[EquipmentTreeNode]:
|
|
63
|
+
"""
|
|
64
|
+
Return the leaves of the tree structure.
|
|
65
|
+
Depending on how the backing trace is configured, there may be extra unexpected leaves in loops.
|
|
66
|
+
"""
|
|
67
|
+
if not self._calculate_leaves:
|
|
68
|
+
raise AttributeError('leaves were not calculated, you must pass calculate_leaves=True to the EquipmentTreeBuilder when creating.')
|
|
69
|
+
return set(self._leaves)
|
|
70
|
+
|
|
46
71
|
def compute_initial_value(self, item: NetworkTraceStep[Any]) -> EquipmentTreeNode:
|
|
47
72
|
node = self._roots.get(item.path.to_equipment)
|
|
48
73
|
if node is None:
|
|
@@ -62,10 +87,18 @@ class EquipmentTreeBuilder(StepActionWithContextValue):
|
|
|
62
87
|
else:
|
|
63
88
|
return TreeNode(next_item.path.to_equipment, current_value)
|
|
64
89
|
|
|
65
|
-
def _apply(self,
|
|
90
|
+
def _apply(self, _: NetworkTraceStep[Any], context: StepContext):
|
|
66
91
|
current_node: TreeNode = self.get_context_value(context)
|
|
67
92
|
if current_node.parent:
|
|
68
93
|
current_node.parent.add_child(current_node)
|
|
69
94
|
|
|
95
|
+
if self._calculate_leaves:
|
|
96
|
+
self._process_leaf(current_node)
|
|
97
|
+
|
|
98
|
+
def _process_leaf(self, current_node: TreeNode[ConductingEquipment]):
|
|
99
|
+
self._leaves.add(current_node) # add this node to _leaves as it has no children
|
|
100
|
+
if current_node.parent:
|
|
101
|
+
self._leaves.discard(current_node.parent) # this nodes parent now has a child, it's not a leaf anymore
|
|
102
|
+
|
|
70
103
|
def clear(self):
|
|
71
104
|
self._roots.clear()
|
|
@@ -5,33 +5,31 @@
|
|
|
5
5
|
|
|
6
6
|
__all__ = ['TreeNode']
|
|
7
7
|
|
|
8
|
-
from typing import
|
|
9
|
-
|
|
10
|
-
from zepben.ewb import IdentifiedObject
|
|
8
|
+
from typing import TypeVar, Generic, Set
|
|
11
9
|
|
|
12
10
|
T = TypeVar('T')
|
|
13
11
|
|
|
14
12
|
|
|
15
13
|
class TreeNode(Generic[T]):
|
|
16
14
|
"""
|
|
17
|
-
|
|
15
|
+
Represents a node in the NetworkTrace tree
|
|
18
16
|
"""
|
|
19
17
|
|
|
20
|
-
def __init__(self, identified_object:
|
|
18
|
+
def __init__(self, identified_object: T, parent=None):
|
|
21
19
|
self.identified_object = identified_object
|
|
22
20
|
self._parent: TreeNode = parent
|
|
23
|
-
self._children:
|
|
21
|
+
self._children: Set[TreeNode] = set()
|
|
24
22
|
|
|
25
23
|
@property
|
|
26
24
|
def parent(self) -> 'TreeNode[T]':
|
|
27
25
|
return self._parent
|
|
28
26
|
|
|
29
27
|
@property
|
|
30
|
-
def children(self):
|
|
31
|
-
return
|
|
28
|
+
def children(self) -> Set['TreeNode[T]']:
|
|
29
|
+
return set(self._children)
|
|
32
30
|
|
|
33
|
-
def add_child(self, child: 'TreeNode'):
|
|
34
|
-
self._children.
|
|
31
|
+
def add_child(self, child: 'TreeNode[T]'):
|
|
32
|
+
self._children.add(child)
|
|
35
33
|
|
|
36
34
|
def __str__(self):
|
|
37
35
|
return f"{{object: {self.identified_object}, parent: {self.parent or ''}, num children: {len(self.children)}}}"
|
|
@@ -568,8 +568,8 @@ zepben/ewb/services/network/tracing/networktrace/network_trace_step_path_provide
|
|
|
568
568
|
zepben/ewb/services/network/tracing/networktrace/network_trace_tracker.py,sha256=EZAwZ9aSuKrykxKCHmNQHhDE-1LjvhwT-pGy6EScv0s,1521
|
|
569
569
|
zepben/ewb/services/network/tracing/networktrace/tracing.py,sha256=gsgR_wWOqcZNGbHBYg7h8aqzi2BlSF6AqBPHIYxSN-I,6836
|
|
570
570
|
zepben/ewb/services/network/tracing/networktrace/actions/__init__.py,sha256=8-znO960twGtcAGArLGl_ijbCB9BBv0_hUNYf1eF0Lk,243
|
|
571
|
-
zepben/ewb/services/network/tracing/networktrace/actions/equipment_tree_builder.py,sha256=
|
|
572
|
-
zepben/ewb/services/network/tracing/networktrace/actions/tree_node.py,sha256=
|
|
571
|
+
zepben/ewb/services/network/tracing/networktrace/actions/equipment_tree_builder.py,sha256=SHfcB-J28NmewfUO54-CbejCHIeGkojhw11ymxZjXAQ,4200
|
|
572
|
+
zepben/ewb/services/network/tracing/networktrace/actions/tree_node.py,sha256=89sW584s6l2Slb3sBsA5MeD_n1YQPhn5-AMUConQjw8,1021
|
|
573
573
|
zepben/ewb/services/network/tracing/networktrace/conditions/__init__.py,sha256=8-znO960twGtcAGArLGl_ijbCB9BBv0_hUNYf1eF0Lk,243
|
|
574
574
|
zepben/ewb/services/network/tracing/networktrace/conditions/conditions.py,sha256=OkG8at-9nIqgN0cOki7kZ7EXQr1YnQEB5-FGTt7xfFk,3503
|
|
575
575
|
zepben/ewb/services/network/tracing/networktrace/conditions/direction_condition.py,sha256=6OCkd3m94UJYaV-c8Bym1PnWIbB6Od7BRaWTEg9QlH8,3390
|
|
@@ -632,8 +632,8 @@ zepben/ewb/streaming/mutations/update_network_state_client.py,sha256=e0Oma5PRT8m
|
|
|
632
632
|
zepben/ewb/streaming/mutations/update_network_state_service.py,sha256=irR-TO67QXRyBmK8PU8SzM31NKSSefZt_nQGHi5IhT8,3260
|
|
633
633
|
zepben/ewb/testing/__init__.py,sha256=waADXEvfUG9wAN4STx5uIUHOv0UnpZLH2qU1LXgaDBc,243
|
|
634
634
|
zepben/ewb/testing/test_network_builder.py,sha256=KG0o2ZHUswx3xClu-JnLs_pYIYbQ5jjtvtyZ7LI6IZ8,38092
|
|
635
|
-
zepben_ewb-1.0.
|
|
636
|
-
zepben_ewb-1.0.
|
|
637
|
-
zepben_ewb-1.0.
|
|
638
|
-
zepben_ewb-1.0.
|
|
639
|
-
zepben_ewb-1.0.
|
|
635
|
+
zepben_ewb-1.0.0b3.dist-info/licenses/LICENSE,sha256=aAHD66h6PQIETpkJDvg5yEObyFvXUED8u7S8dlh6K0Y,16725
|
|
636
|
+
zepben_ewb-1.0.0b3.dist-info/METADATA,sha256=aCg3N2fotPlZL3ZAAjuP4RJzBx3q27296CAYYJIWifQ,3451
|
|
637
|
+
zepben_ewb-1.0.0b3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
638
|
+
zepben_ewb-1.0.0b3.dist-info/top_level.txt,sha256=eVLDJiO6FGjL_Z7KdmFE-R8uf1Q07aaVLGe9Ee4kmBw,7
|
|
639
|
+
zepben_ewb-1.0.0b3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|