Skip to content

Commit

Permalink
RM: unmodified CIM (redundant)
Browse files Browse the repository at this point in the history
  • Loading branch information
pseudocubic committed Aug 14, 2024
1 parent 823c17a commit c8588d8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 40 deletions.
1 change: 0 additions & 1 deletion cim/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*

!.gitignore
!iec61970cim17v40_iec61968cim13v13b_iec62325cim03v17b_CIM100.1.1.1.eap
!iec61970cim17v40_iec61968cim13v13b_iec62325cim03v17b_CIM100.1.1.1_mgravens24v1.eap

This file was deleted.

36 changes: 7 additions & 29 deletions ravens/cim_tools/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@ def add_class_nodes_to_graph(G, core_data: CoreData, exclude_packages: list = No
if exclude_objects is None:
exclude_objects = []

attrs = {
obj.Index: [attr.Index for attr in core_data.attributes[core_data.attributes["Object_ID"] == obj.Index].itertuples()]
for obj in core_data.objects[core_data.objects["Object_Type"] == "Class"].itertuples()
if pd.isnull(obj.Stereotype)
}
attrs = {obj.Index: [attr.Index for attr in core_data.attributes[core_data.attributes["Object_ID"] == obj.Index].itertuples()] for obj in core_data.objects[core_data.objects["Object_Type"] == "Class"].itertuples() if pd.isnull(obj.Stereotype)}

conns = {
obj.Index: [
c.Index
for c in core_data.connectors[
(core_data.connectors["Start_Object_ID"] == obj.Index) | (core_data.connectors["End_Object_ID"] == obj.Index)
].itertuples()
]
obj.Index: [c.Index for c in core_data.connectors[(core_data.connectors["Start_Object_ID"] == obj.Index) | (core_data.connectors["End_Object_ID"] == obj.Index)].itertuples()]
for obj in core_data.objects[core_data.objects["Object_Type"] == "Class"].itertuples()
if pd.isnull(obj.Stereotype)
}
Expand Down Expand Up @@ -98,9 +89,7 @@ def build_attribute_graph(core_data: CoreData, exclude_packages: list = None, ex
for n in list(AT.nodes):
for attr in core_data.attributes[core_data.attributes["Object_ID"] == n].itertuples():
AT.add_edge(attr.Index, n, Connector_Type="Attribute", Connector_ID="ATTR_" + str(attr.Index), weight=100.0)
AT.nodes[attr.Index].update(
{"Name": str(attr.Name), "Note": str(attr.Notes), "Object_Type": "Attribute", "Attribute_ID": str(attr.Index)}
)
AT.nodes[attr.Index].update({"Name": str(attr.Name), "Note": str(attr.Notes), "Object_Type": "Attribute", "Attribute_ID": str(attr.Index)})

return AT

Expand All @@ -114,9 +103,7 @@ def build_association_graph(core_data: CoreData, exclude_packages: list = None,

AG = nx.MultiDiGraph()
AG = add_class_nodes_to_graph(AG, core_data, exclude_packages, exclude_objects)
for c in core_data.connectors[
(core_data.connectors["Connector_Type"] == "Association") | (core_data.connectors["Connector_Type"] == "Aggregation")
].itertuples():
for c in core_data.connectors[(core_data.connectors["Connector_Type"] == "Association") | (core_data.connectors["Connector_Type"] == "Aggregation")].itertuples():
if (
core_data.objects.loc[c.Start_Object_ID]["Object_Type"] == "Class"
and core_data.objects.loc[c.End_Object_ID]["Object_Type"] == "Class"
Expand Down Expand Up @@ -163,11 +150,7 @@ def build_template_cim_graphs(template, core_data, GG, AG, AT, clean_dir=False):
**{obj.Index: str(obj.Name) for obj in core_data.objects.itertuples()},
**{attr.Index: str(attr.Name) for attr in core_data.attributes.itertuples()},
}
cls_name2id = {
str(obj.Name): obj.Index
for obj in core_data.objects[core_data.objects["Object_Type"] == "Class"].itertuples()
if pd.isnull(obj.Stereotype)
}
cls_name2id = {str(obj.Name): obj.Index for obj in core_data.objects[core_data.objects["Object_Type"] == "Class"].itertuples() if pd.isnull(obj.Stereotype)}

template_names = []
template_names = collect_template_node_names(template, template_names)
Expand All @@ -178,12 +161,7 @@ def build_template_cim_graphs(template, core_data, GG, AG, AT, clean_dir=False):

for name in template_names:
obj_id = cls_name2id[name]
nodes = {
at
for n in [obj_id] + list(nx.ancestors(GG, obj_id)) + list(nx.descendants(GG, obj_id))
for a in list(AG.neighbors(n)) + [n]
for at in [n, a] + list(AT.predecessors(a)) + list(AT.predecessors(n))
}
nodes = {at for n in [obj_id] + list(nx.ancestors(GG, obj_id)) + list(nx.descendants(GG, obj_id)) for a in list(AG.neighbors(n)) + [n] for at in [n, a] + list(AT.predecessors(a)) + list(AT.predecessors(n))}

SG = nx.subgraph(GG_AT_AG, nodes)
nx.write_graphml(SG, f"out/template_graphs/{name}.graphml")
Expand All @@ -194,7 +172,7 @@ def build_template_cim_graphs(template, core_data, GG, AG, AT, clean_dir=False):
from ravens.cim_tools.template import CIMTemplate
from ravens.io import parse_eap_data

db_filename = "cim/iec61970cim17v40_iec61968cim13v13b_iec62325cim03v17b_CIM100.1.1.1.eap"
db_filename = "cim/iec61970cim17v40_iec61968cim13v13b_iec62325cim03v17b_CIM100.1.1.1_mgravens24v1.eap"

core_data = parse_eap_data(db_filename)

Expand Down
10 changes: 3 additions & 7 deletions ravens/schema/build_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,15 @@ def build_definitions(core_data: CoreData) -> dict:
},
}

if (
all(v["default"] is not None for k, v in defs[str(obj.Name).replace(" ", "")]["properties"].items() if k != "value")
and "value" in defs[str(obj.Name).replace(" ", "")]["properties"]
):
if all(v["default"] is not None for k, v in defs[str(obj.Name).replace(" ", "")]["properties"].items() if k != "value") and "value" in defs[str(obj.Name).replace(" ", "")]["properties"]:
defs[str(obj.Name).replace(" ", "")]["type"] = [
"object",
cim_primitives_to_json[defs[str(obj.Name).replace(" ", "")]["properties"]["value"]["type"]],
]


for k, v in defs.items():
if "properties" in v:
for _k,_v in v["properties"].items():
for _k, _v in v["properties"].items():
if "type" in _v and _v["type"] in defs:
_v["$ref"] = f"#/$defs/{_v.pop("type")}"

Expand All @@ -74,7 +70,7 @@ def build_definitions(core_data: CoreData) -> dict:
if __name__ == "__main__":
from ravens.io import parse_eap_data

db_filename = "cim/iec61970cim17v40_iec61968cim13v13b_iec62325cim03v17b_CIM100.1.1.1.eap"
db_filename = "cim/iec61970cim17v40_iec61968cim13v13b_iec62325cim03v17b_CIM100.1.1.1_mgravens24v1.eap"

core_data = parse_eap_data(db_filename)

Expand Down

0 comments on commit c8588d8

Please sign in to comment.