Skip to content

Commit 93c2eb5

Browse files
committed
Add main test script
1 parent 27f69fb commit 93c2eb5

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

main.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from frequenz.client.reporting.component_graph import ComponentGraph, Component, Connection, ComponentCategory, InverterType
2+
import json
3+
4+
5+
def build_graph(json_data: dict) -> ComponentGraph:
6+
components = []
7+
connections = []
8+
for component in json_data["components"]:
9+
component_id = int(component["id"])
10+
category = ComponentCategory(component["category"])
11+
component_type = None
12+
if category == ComponentCategory.INVERTER and "inverter" in component and "type" in component["inverter"]:
13+
component_type = InverterType(component["inverter"]["type"])
14+
15+
components.append(
16+
Component(
17+
component_id=component_id,
18+
category=category,
19+
type=component_type,
20+
)
21+
)
22+
for connection in json_data["connections"]:
23+
connections.append(
24+
Connection(
25+
start=int(connection["start"]),
26+
end=int(connection["end"]),
27+
)
28+
)
29+
return ComponentGraph(components, connections)
30+
31+
32+
def main():
33+
# Read JSON data from file
34+
with open("comps13.json", "r") as file:
35+
data = json.load(file)
36+
37+
# Build component graph
38+
component_graph = build_graph(data)
39+
40+
# Print component graph
41+
print(component_graph)
42+
43+
if __name__ == "__main__":
44+
main()

0 commit comments

Comments
 (0)