File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 1919 SolarInverter ,
2020)
2121
22+ from frequenz .sdk .microgrid .component_graph import ComponentGraph
23+
2224
2325@dataclass
2426class ComponentGraphConfig :
@@ -107,3 +109,18 @@ def create_component_graph_structure(
107109 components .add (DcEvCharger (id = ev_id , microgrid_id = microgrid_id ))
108110 connections .add (ComponentConnection (source = junction_id , destination = ev_id ))
109111 return components , connections
112+
113+
114+ def component_grap_to_mermaid (comp_graph : ComponentGraph ) -> str :
115+ """Return a string representation of the component graph in Mermaid format."""
116+
117+ def component_to_mermaid (component : Component ) -> str :
118+ return f'"{ component .id } "["{ component } "]'
119+
120+ def connection_to_mermaid (connection : ComponentConnection ) -> str :
121+ return f'"{ connection .source } " --> "{ connection .destination } "'
122+
123+ components = "\n " .join (map (component_to_mermaid , comp_graph .components ()))
124+ connections = "\n " .join (map (connection_to_mermaid , comp_graph .connections ()))
125+
126+ return f"graph TD\n { components } \n { connections } "
You can’t perform that action at this time.
0 commit comments