Skip to content

Commit

Permalink
Fix camelCase naming of variables
Browse files Browse the repository at this point in the history
Signed-off-by: Steffen Vogel <[email protected]>
  • Loading branch information
stv0g committed Jun 17, 2024
1 parent 8feb082 commit 0e89379
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 72 deletions.
88 changes: 44 additions & 44 deletions cimpy/cimexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ def _get_reference_uuid(attr_dict, version, topology, mRID, urls):
# The % added before the mRID is used in the lambda _set_attribute_or_reference
if not hasattr(elem, "mRID"):
# Search for the object in the res dictionary and return the mRID
UUID = "%" + _search_mRID(elem, topology)
if UUID == "%":
uuid = "%" + _search_mRID(elem, topology)
if uuid == "%":
logger.warning(
"Object of type %s not found as reference for object with UUID %s.",
elem.__class__.__name__,
mRID,
)
else:
UUID = "%" + elem.mRID
uuid = "%" + elem.mRID

array.append(UUID)
array.append(uuid)
else:
logger.warning("Reference object not subclass of Base class for object with UUID %s.", mRID)
if len(array) == 1:
Expand All @@ -79,16 +79,16 @@ def _get_reference_uuid(attr_dict, version, topology, mRID, urls):
if not hasattr(attr_dict[key], "mRID"):
# Search for object in res dict and return mRID
# The % added before the mRID is used in the lambda _set_attribute_or_reference
UUID = "%" + _search_mRID(attr_dict[key], topology)
if UUID == "%":
uuid = "%" + _search_mRID(attr_dict[key], topology)
if uuid == "%":
logger.warning(
"Object of type %s not found as reference for object with UUID %s.",
attr_dict[key].__class__.__name__,
mRID,
)
else:
UUID = "%" + attr_dict[key].mRID
attributes["value"] = UUID
uuid = "%" + attr_dict[key].mRID
attributes["value"] = uuid
elif attr_dict[key] == "" or attr_dict[key] is None:
pass
else:
Expand Down Expand Up @@ -185,45 +185,45 @@ def _sort_classes_to_profile(class_attributes_list, activeProfileList):
# Store serializationProfile and possibleProfileList
# serializationProfile class attribute, same for multiple instances
# of same class, only last origin of variable stored
serializationProfile = copy.deepcopy(klass["attributes"][0]["serializationProfile"])
possibleProfileList = copy.deepcopy(klass["attributes"][1]["possibleProfileList"])
serialization_profile = copy.deepcopy(klass["attributes"][0]["serializationProfile"])
possible_profile_list = copy.deepcopy(klass["attributes"][1]["possibleProfileList"])

class_serializationProfile = ""
class_serialization_profile = ""

if "class" in serializationProfile.keys():
if "class" in serialization_profile.keys():
# Class was imported
if Profile[serializationProfile["class"]] in activeProfileList:
if Profile[serialization_profile["class"]] in activeProfileList:
# Else: class origin profile not active for export, get active profile from possibleProfileList
if Profile[serializationProfile["class"]].value in possibleProfileList[klass["name"]]["class"]:
if Profile[serialization_profile["class"]].value in possible_profile_list[klass["name"]]["class"]:
# Profile active and in possibleProfileList
# Else: class should not have been imported from this profile, get allowed profile
# from possibleProfileList
class_serializationProfile = serializationProfile["class"]
class_serialization_profile = serialization_profile["class"]
else:
logger.warning(
"Class %s was read from profile %s but this profile is not possible for this class",
klass["name"],
serializationProfile["class"],
serialization_profile["class"],
)
else:
logger.info(
"Class %s was read from profile %s but this profile is not active for the export. "
+ "Use default profile from possibleProfileList.",
klass["name"],
serializationProfile["class"],
serialization_profile["class"],
)

if class_serializationProfile == "":
if class_serialization_profile == "":
# Class was created
if klass["name"] in possibleProfileList.keys():
if "class" in possibleProfileList[klass["name"]].keys():
possibleProfileList[klass["name"]]["class"].sort()
for klass_profile in possibleProfileList[klass["name"]]["class"]:
if klass["name"] in possible_profile_list.keys():
if "class" in possible_profile_list[klass["name"]].keys():
possible_profile_list[klass["name"]]["class"].sort()
for klass_profile in possible_profile_list[klass["name"]]["class"]:
if Profile(klass_profile).name in activeProfileList:
# Active profile for class export found
class_serializationProfile = Profile(klass_profile).name
class_serialization_profile = Profile(klass_profile).name
break
if class_serializationProfile == "":
if class_serialization_profile == "":
# No profile in possibleProfileList active
logger.warning(
"All possible export profiles for class %s not active. Skip class for export.",
Expand All @@ -245,26 +245,26 @@ def _sort_classes_to_profile(class_attributes_list, activeProfileList):
if attribute_name == "mRID":
continue

attribute_serializationProfile = ""
attribute_serialization_profile = ""

if attribute_name in serializationProfile.keys():
if attribute_name in serialization_profile.keys():
# Attribute was imported
if Profile[serializationProfile[attribute_name]] in activeProfileList:
attr_value = Profile[serializationProfile[attribute_name]].value
if attr_value in possibleProfileList[attribute_class][attribute_name]:
attribute_serializationProfile = serializationProfile[attribute_name]
if Profile[serialization_profile[attribute_name]] in activeProfileList:
attr_value = Profile[serialization_profile[attribute_name]].value
if attr_value in possible_profile_list[attribute_class][attribute_name]:
attribute_serialization_profile = serialization_profile[attribute_name]

if attribute_serializationProfile == "":
if attribute_serialization_profile == "":
# Attribute was added
if attribute_class in possibleProfileList.keys():
if attribute_name in possibleProfileList[attribute_class].keys():
possibleProfileList[attribute_class][attribute_name].sort()
for attr_profile in possibleProfileList[attribute_class][attribute_name]:
if attribute_class in possible_profile_list.keys():
if attribute_name in possible_profile_list[attribute_class].keys():
possible_profile_list[attribute_class][attribute_name].sort()
for attr_profile in possible_profile_list[attribute_class][attribute_name]:
if Profile(attr_profile) in activeProfileList:
# Active profile for class export found
attribute_serializationProfile = Profile(attr_profile).name
attribute_serialization_profile = Profile(attr_profile).name
break
if attribute_serializationProfile == "":
if attribute_serialization_profile == "":
# No profile in possibleProfileList active, skip attribute
logger.warning(
"All possible export profiles for attribute %s.%s of class %s not active. "
Expand All @@ -288,25 +288,25 @@ def _sort_classes_to_profile(class_attributes_list, activeProfileList):
attribute_name,
)

if attribute_serializationProfile == class_serializationProfile:
if attribute_serialization_profile == class_serialization_profile:
# Class and current attribute belong to same profile
same_package_list.append(attribute)
else:
# Class and current attribute does not belong to same profile -> rdf:about in
# attribute origin profile
if attribute_serializationProfile in about_dict.keys():
about_dict[attribute_serializationProfile].append(attribute)
if attribute_serialization_profile in about_dict.keys():
about_dict[attribute_serialization_profile].append(attribute)
else:
about_dict[attribute_serializationProfile] = [attribute]
about_dict[attribute_serialization_profile] = [attribute]

# Add class with all attributes in the same profile to the export dict sorted by the profile
if class_serializationProfile in export_dict.keys():
if class_serialization_profile in export_dict.keys():
export_class = dict(name=klass["name"], mRID=klass["mRID"], attributes=same_package_list)
export_dict[class_serializationProfile]["classes"].append(export_class)
export_dict[class_serialization_profile]["classes"].append(export_class)
del export_class
else:
export_class = dict(name=klass["name"], mRID=klass["mRID"], attributes=same_package_list)
export_dict[class_serializationProfile] = {"classes": [export_class]}
export_dict[class_serialization_profile] = {"classes": [export_class]}

# Add class with all attributes defined in another profile to the about_key sorted by the profile
for about_key in about_dict.keys():
Expand Down
4 changes: 2 additions & 2 deletions cimpy/examples/add_external_network_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@

import_result = cimpy.utils.add_external_network_injection(import_result, "cgmes_v2_4_15", "N1", 20.0)

activeProfileList = ["DL", "EQ", "SV", "TP"]
active_profile_list = ["DL", "EQ", "SV", "TP"]

cimpy.cim_export(import_result, "ExternalInjection", "cgmes_v2_4_15", activeProfileList)
cimpy.cim_export(import_result, "ExternalInjection", "cgmes_v2_4_15", active_profile_list)
4 changes: 2 additions & 2 deletions cimpy/examples/convert_to_bus_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@

import_result = cimpy.utils.node_breaker_to_bus_branch(import_result)

activeProfileList = ["DL", "EQ", "TP"]
active_profile_list = ["DL", "EQ", "TP"]

cimpy.cim_export(import_result, "Bus_Branch_Converted", "cgmes_v2_4_15", activeProfileList)
cimpy.cim_export(import_result, "Bus_Branch_Converted", "cgmes_v2_4_15", active_profile_list)
4 changes: 2 additions & 2 deletions cimpy/examples/export_cigre_mv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

import_result = cimpy.cim_import(xml_files, "cgmes_v2_4_15")

activeProfileList = ["DL", "EQ", "SV", "TP"]
active_profile_list = ["DL", "EQ", "SV", "TP"]

cimpy.cim_export(import_result, "CIGREMV_reference_cgmes_v2_4_15", "cgmes_v2_4_15", activeProfileList)
cimpy.cim_export(import_result, "CIGREMV_reference_cgmes_v2_4_15", "cgmes_v2_4_15", active_profile_list)
10 changes: 5 additions & 5 deletions cimpy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ def node_breaker_to_bus_branch(import_result):
def add_external_network_injection(import_result, version, mRID, voltage_set_point):
"""TODO: Add documentation"""
res = import_result["topology"]
TopologicalNode = ""
topological_node = ""
if mRID in res:
if "TopologicalNode" in str(type(res[mRID])):
TopologicalNode = res[mRID]
topological_node = res[mRID]
elif "ConnectivityNode" in str(type(res[mRID])):
TopologicalNode = res[mRID].TopologicalNode.mRID
topological_node = res[mRID].TopologicalNode.mRID

if TopologicalNode != "":
if topological_node != "":
i = 1
while "Injection " + str(i) in res.keys():
i += 1
Expand All @@ -118,7 +118,7 @@ def add_external_network_injection(import_result, version, mRID, voltage_set_poi

terminal_module = importlib.import_module((module_name + "Terminal"))
terminal_class = getattr(terminal_module, "Terminal")
res[terminal_name] = terminal_class(mRID=terminal_name, name=terminal_name, TopologicalNode=TopologicalNode)
res[terminal_name] = terminal_class(mRID=terminal_name, name=terminal_name, TopologicalNode=topological_node)

regulating_control_module = importlib.import_module(module_name + "RegulatingControl")
regulating_control_class = getattr(regulating_control_module, "RegulatingControl")
Expand Down
34 changes: 17 additions & 17 deletions tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def read_exported_xml(directory):


def test_export_with_exported_files(sample_cimdata, tmpdir):
activeProfileList = ["DL", "EQ", "SV", "TP"]
active_profile_list = ["DL", "EQ", "SV", "TP"]

cimpy.cim_export(sample_cimdata, tmpdir + "/EXPORTED_Test", "cgmes_v2_4_15", activeProfileList)
cimpy.cim_export(sample_cimdata, tmpdir + "/EXPORTED_Test", "cgmes_v2_4_15", active_profile_list)

test_dict = read_ref_xml()
export_dict = read_exported_xml(tmpdir)
Expand All @@ -90,9 +90,9 @@ def test_export_with_exported_files(sample_cimdata, tmpdir):


def test_export_with_imported_files(sample_cimdata, tmpdir):
activeProfileList = ["DL", "EQ", "SSH", "SV", "TP"]
active_profile_list = ["DL", "EQ", "SSH", "SV", "TP"]

cimpy.cim_export(sample_cimdata, tmpdir + "/EXPORTED_Test", "cgmes_v2_4_15", activeProfileList)
cimpy.cim_export(sample_cimdata, tmpdir + "/EXPORTED_Test", "cgmes_v2_4_15", active_profile_list)

test_dict = read_ref_xml()
export_dict = read_exported_xml(tmpdir)
Expand All @@ -108,61 +108,61 @@ def test_export_with_imported_files(sample_cimdata, tmpdir):
if class_key in current_export_dict.keys():
current_export_class = current_export_dict[class_key]
current_test_class = current_test_dict[class_key]
test_mRIDs = []
test_mrids = []
test_class_dict = {}
if isinstance(current_test_class, list):
for obj in current_test_class:
try:
test_mRIDs.append(obj["$rdf:ID"])
test_mrids.append(obj["$rdf:ID"])
test_class_dict[obj["$rdf:ID"]] = obj
except KeyError:
try:
test_mRIDs.append(obj["$rdf:about"])
test_mrids.append(obj["$rdf:about"])
test_class_dict[obj["$rdf:about"]] = obj
except KeyError:
check.is_in("$rdf:about", obj.keys())
check.is_in("$rdf:ID", obj.keys())
else:
try:
test_mRIDs.append(current_test_class["$rdf:ID"])
test_mrids.append(current_test_class["$rdf:ID"])
test_class_dict[current_test_class["$rdf:ID"]] = current_test_class
except KeyError:
try:
test_mRIDs.append(current_test_class["$rdf:about"])
test_mrids.append(current_test_class["$rdf:about"])
test_class_dict[current_test_class["$rdf:about"]] = obj
except KeyError:
check.is_in("$rdf:about", current_test_class.keys())
check.is_in("$rdf:ID", current_test_class.keys())

export_mRIDs = []
export_mrids = []
export_class_dict = {}
if isinstance(current_export_class, list):
for obj in current_export_class:
try:
export_mRIDs.append(obj["$rdf:ID"])
export_mrids.append(obj["$rdf:ID"])
export_class_dict[obj["$rdf:ID"]] = obj
except KeyError:
try:
export_mRIDs.append(obj["$rdf:about"])
export_mrids.append(obj["$rdf:about"])
export_class_dict[obj["$rdf:about"]] = obj
except KeyError:
check.is_in("$rdf:about", obj.keys())
check.is_in("$rdf:ID", obj.keys())
else:
try:
export_mRIDs.append(current_export_class["$rdf:ID"])
export_mrids.append(current_export_class["$rdf:ID"])
export_class_dict[current_export_class["$rdf:ID"]] = current_export_class
except KeyError:
try:
export_mRIDs.append(current_export_class["$rdf:about"])
export_mrids.append(current_export_class["$rdf:about"])
export_class_dict[current_export_class["$rdf:about"]] = obj
except KeyError:
check.is_in("$rdf:about", current_export_class.keys())
check.is_in("$rdf:ID", current_export_class.keys())

for mRID in test_mRIDs:
check.is_in(mRID, export_mRIDs)
if mRID in export_mRIDs:
for mRID in test_mrids:
check.is_in(mRID, export_mrids)
if mRID in export_mrids:
test_attr = test_class_dict[mRID].items()
export_attr = export_class_dict[mRID].items()
for item in test_attr:
Expand Down

0 comments on commit 0e89379

Please sign in to comment.