Commit a4b229cb authored by Philipp Reuber's avatar Philipp Reuber
Browse files

add new cgmes class files, modify import/export for new files

parent 61b21744
......@@ -34,7 +34,7 @@ class WindPitchContEmulIEC(IdentifiedObject):
'tpe': [cgmesProfile.DY.value, ],
}
readInProfile = {}
serializationProfile = {}
__doc__ += '\n Documentation of parent class IdentifiedObject: \n' + IdentifiedObject.__doc__
......
......@@ -16,7 +16,7 @@ class WindPlantDynamics(DynamicsFunctionBlock):
'WindTurbineType3or4Dynamics': [cgmesProfile.DY.value, ],
}
readInProfile = {}
serializationProfile = {}
__doc__ += '\n Documentation of parent class DynamicsFunctionBlock: \n' + DynamicsFunctionBlock.__doc__
......
......@@ -36,7 +36,7 @@ class WindPlantFreqPcontrolIEC(IdentifiedObject):
'WindPlantIEC': [cgmesProfile.DY.value, ],
}
readInProfile = {}
serializationProfile = {}
__doc__ += '\n Documentation of parent class IdentifiedObject: \n' + IdentifiedObject.__doc__
......
......@@ -16,7 +16,7 @@ class WindPlantIEC(WindPlantDynamics):
'WindPlantReactiveControlIEC': [cgmesProfile.DY.value, ],
}
readInProfile = {}
serializationProfile = {}
__doc__ += '\n Documentation of parent class WindPlantDynamics: \n' + WindPlantDynamics.__doc__
......
......@@ -40,7 +40,7 @@ class WindPlantReactiveControlIEC(IdentifiedObject):
'xrefmin': [cgmesProfile.DY.value, ],
}
readInProfile = {}
serializationProfile = {}
__doc__ += '\n Documentation of parent class IdentifiedObject: \n' + IdentifiedObject.__doc__
......
......@@ -16,7 +16,7 @@ class WindPlantUserDefined(WindPlantDynamics):
'ProprietaryParameterDynamics': [cgmesProfile.DY.value, ],
}
readInProfile = {}
serializationProfile = {}
__doc__ += '\n Documentation of parent class WindPlantDynamics: \n' + WindPlantDynamics.__doc__
......
......@@ -32,7 +32,7 @@ class WindProtectionIEC(IdentifiedObject):
'WindTurbineType1or2IEC': [cgmesProfile.DY.value, ],
}
readInProfile = {}
serializationProfile = {}
__doc__ += '\n Documentation of parent class IdentifiedObject: \n' + IdentifiedObject.__doc__
......
......@@ -12,7 +12,7 @@ class WindQcontrolModesKind(Base):
possibleProfileList = {'class': [cgmesProfile.DY.value, ],
}
readInProfile = {}
serializationProfile = {}
......
......@@ -16,7 +16,7 @@ class WindTurbineType1or2Dynamics(DynamicsFunctionBlock):
'AsynchronousMachineDynamics': [cgmesProfile.DY.value, ],
}
readInProfile = {}
serializationProfile = {}
__doc__ += '\n Documentation of parent class DynamicsFunctionBlock: \n' + DynamicsFunctionBlock.__doc__
......
......@@ -16,7 +16,7 @@ class WindTurbineType1or2IEC(WindTurbineType1or2Dynamics):
'WindProtectionIEC': [cgmesProfile.DY.value, ],
}
readInProfile = {}
serializationProfile = {}
__doc__ += '\n Documentation of parent class WindTurbineType1or2Dynamics: \n' + WindTurbineType1or2Dynamics.__doc__
......
......@@ -18,7 +18,7 @@ class WindTurbineType3or4Dynamics(DynamicsFunctionBlock):
'WindPlantDynamics': [cgmesProfile.DY.value, ],
}
readInProfile = {}
serializationProfile = {}
__doc__ += '\n Documentation of parent class DynamicsFunctionBlock: \n' + DynamicsFunctionBlock.__doc__
......
......@@ -18,7 +18,7 @@ class WindTurbineType3or4IEC(WindTurbineType3or4Dynamics):
'WindProtectionIEC': [cgmesProfile.DY.value, ],
}
readInProfile = {}
serializationProfile = {}
__doc__ += '\n Documentation of parent class WindTurbineType3or4Dynamics: \n' + WindTurbineType3or4Dynamics.__doc__
......
......@@ -14,7 +14,7 @@ class WindTurbineType4aIEC(WindGenType4IEC):
'WindContPType4aIEC': [cgmesProfile.DY.value, ],
}
readInProfile = {}
serializationProfile = {}
__doc__ += '\n Documentation of parent class WindGenType4IEC: \n' + WindGenType4IEC.__doc__
......
......@@ -16,7 +16,7 @@ class WindTurbineType4bIEC(WindGenType4IEC):
'WindMechIEC': [cgmesProfile.DY.value, ],
}
readInProfile = {}
serializationProfile = {}
__doc__ += '\n Documentation of parent class WindGenType4IEC: \n' + WindGenType4IEC.__doc__
......
......@@ -16,7 +16,7 @@ class WindType1or2UserDefined(WindTurbineType1or2Dynamics):
'ProprietaryParameterDynamics': [cgmesProfile.DY.value, ],
}
readInProfile = {}
serializationProfile = {}
__doc__ += '\n Documentation of parent class WindTurbineType1or2Dynamics: \n' + WindTurbineType1or2Dynamics.__doc__
......
......@@ -16,7 +16,7 @@ class WindType3or4UserDefined(WindTurbineType3or4Dynamics):
'ProprietaryParameterDynamics': [cgmesProfile.DY.value, ],
}
readInProfile = {}
serializationProfile = {}
__doc__ += '\n Documentation of parent class WindTurbineType3or4Dynamics: \n' + WindTurbineType3or4Dynamics.__doc__
......
......@@ -12,7 +12,7 @@ class WindingConnection(Base):
possibleProfileList = {'class': [cgmesProfile.EQ.value, ],
}
readInProfile = {}
serializationProfile = {}
......
......@@ -34,7 +34,7 @@ def _get_reference_uuid(attr_dict, version, res, mRID):
base_module = importlib.import_module(base_class_name)
base_class = getattr(base_module, 'Base')
for key in attr_dict:
if key in ['readInProfile', 'possibleProfileList']:
if key in ['serializationProfile', 'possibleProfileList']:
reference_list.append({key: attr_dict[key]})
continue
......@@ -140,8 +140,8 @@ def _create_namespaces_list(namespaces_dict):
# This function sorts the classes and their attributes to the corresponding profiles. Either the classes/attributes are
# imported or they are set afterwards. In the first case the readInProfile is used to determine from which profile this
# class/attribute was read. If an entry exists the class/attribute is added to this profile. In the
# imported or they are set afterwards. In the first case the serializationProfile is used to determine from which
# profile this class/attribute was read. If an entry exists the class/attribute is added to this profile. In the
# possibleProfileList dictionary the possible origins of the class/attributes is stored. All profiles have a different
# priority which is stored in the enum cgmesProfile. As default the smallest entry in the dictionary is used to
# determine the profile for the class/attributes.
......@@ -154,39 +154,38 @@ def _sort_classes_to_profile(class_attributes_list, activeProfileList):
same_package_list = []
about_dict = {}
# store readInProfile and possibleProfileList
# readInProfile class attribute, same for multiple instances of same class, only last origin of variable stored
# ToDo: check if multiple attribute origins are possible for read in attributes
readInProfile = klass['attributes'][0]['readInProfile']
# store serializationProfile and possibleProfileList
# serializationProfile class attribute, same for multiple instances of same class, only last origin of variable stored
serializationProfile = klass['attributes'][0]['serializationProfile']
possibleProfileList = klass['attributes'][1]['possibleProfileList']
class_serializationProfile = ''
if 'class' in readInProfile.keys():
if 'class' in serializationProfile.keys():
# class was imported
if readInProfile['class'] in activeProfileList:
if serializationProfile['class'] in activeProfileList:
# else: class origin profile not active for export, get active profile from possibleProfileList
if readInProfile['class'] in possibleProfileList[klass['name']]['class']:
if cgmesProfile[serializationProfile['class']].value in possibleProfileList[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 = readInProfile['class']
class_serializationProfile = serializationProfile['class']
else:
logger.warning('Class {} was read from profile {} but this profile is not possible for this class'
.format(klass['name'], readInProfile['class']))
.format(klass['name'], serializationProfile['class']))
else:
logger.info('Class {} was read from profile {} but this profile is not active for the export. Use'
'default profile from possibleProfileList.'.format(klass['name'], readInProfile['class']))
'default profile from possibleProfileList.'.format(klass['name'], serializationProfile['class']))
if class_serializationProfile == '':
# class was created
if klass['name'] in possibleProfileList.keys():
if 'class' in possibleProfileList[klass['name']].keys():
possibleProfileList[klass['name']]['class'].sort()
for serializationProfile in possibleProfileList[klass['name']]['class']:
if cgmesProfile(serializationProfile).name in activeProfileList:
for klass_profile in possibleProfileList[klass['name']]['class']:
if cgmesProfile(klass_profile).name in activeProfileList:
# active profile for class export found
class_serializationProfile = cgmesProfile(serializationProfile).name
class_serializationProfile = cgmesProfile(klass_profile).name
break
if class_serializationProfile == '':
# no profile in possibleProfileList active
......@@ -210,24 +209,22 @@ def _sort_classes_to_profile(class_attributes_list, activeProfileList):
attribute_serializationProfile = ''
if attribute_name in readInProfile.keys():
if attribute_name in serializationProfile.keys():
# attribute was imported
if readInProfile[attribute_name] in activeProfileList:
attribute_serializationProfile = readInProfile[attribute_name]
else:
logger.info('Attribute {} from class {} was read from profile {} but this profile is inactive'
'for the export. Use default profile from possibleProfileList.'
.format(attribute_name, klass['name'], readInProfile[attribute_name]))
if serializationProfile[attribute_name] in activeProfileList:
attr_value = cgmesProfile[serializationProfile[attribute_name]].value
if attr_value in possibleProfileList[attribute_class][attribute_name]:
attribute_serializationProfile = serializationProfile[attribute_name]
if attribute_serializationProfile == '':
# attribute was added
if attribute_class in possibleProfileList.keys():
if attribute_name in possibleProfileList[attribute_class].keys():
possibleProfileList[attribute_class][attribute_name].sort()
for serializationProfile in possibleProfileList[attribute_class][attribute_name]:
if cgmesProfile(serializationProfile).name in activeProfileList:
for attr_profile in possibleProfileList[attribute_class][attribute_name]:
if cgmesProfile(attr_profile).name in activeProfileList:
# active profile for class export found
attribute_serializationProfile = cgmesProfile(serializationProfile).name
attribute_serializationProfile = cgmesProfile(attr_profile).name
break
if attribute_serializationProfile == '':
# no profile in possibleProfileList active, skip attribute
......@@ -372,7 +369,7 @@ def _get_attributes(class_object):
class_type = type(parent)
# dictionary containing all attributes with key: 'Class_Name.Attribute_Name'
attributes_dict = dict(readInProfile=class_object.readInProfile, possibleProfileList={})
attributes_dict = dict(serializationProfile=class_object.serializationProfile, possibleProfileList={})
# __dict__ of a subclass returns also the attributes of the parent classes
# to avoid multiple attributes create list with all attributes already processed
......@@ -394,8 +391,8 @@ def _get_attributes(class_object):
continue
# get all possibleProfileLists from all parent classes except the Base class (no attributes)
# the readInProfile from parent classes is not needed because entries in the readInProfile are only generated
# for the inherited class
# the serializationProfile from parent classes is not needed because entries in the serializationProfile
# are only generated for the inherited class
if class_name is not 'Base':
attributes_dict['possibleProfileList'][class_name] = parent_class.possibleProfileList
......
......@@ -14,7 +14,7 @@ def cim_import(xml_files, cgmes_version, start_dict=None):
This function parses xml files containing a cgmes topology and instantiates these classes with their attributes.
The instantiation is done in two steps. In the first step all classes are instantiated with default values and
in a second step the attributes contained in the xml files are set. The origin of all classes and attributes are
stored in the class attribute readInProfile.
stored in the class attribute serializationProfile.
:param xml_files: CIM RDF/XML file.
:param cgmes_version: cgmes version, e.g. "cgmes_v2_4_15"
......@@ -62,7 +62,7 @@ def cim_import(xml_files, cgmes_version, start_dict=None):
# The only exception is the mRID which is set for all classes that have this attribute. The attributes of a class
# are set in the _set_attributes function because some attributes might be stored in one package and the class in
# another. Since after this function all classes are instantiated, there should be no problem in setting the attributes.
# Also the information from which package file a class was read is stored in the readInProfile dictionary.
# Also the information from which package file a class was read is stored in the serializationProfile dictionary.
def _instantiate_classes(res, xml_files, cgmes_version_path, namespace_rdf, base, logger_errors_grouped):
# length of element tag base
m = len(base)
......@@ -117,7 +117,7 @@ def _instantiate_classes(res, xml_files, cgmes_version_path, namespace_rdf, base
res[uuid].mRID = uuid
if package is not '':
res[uuid].readInProfile['class'] = short_package_name[package]
res[uuid].serializationProfile['class'] = short_package_name[package]
else:
error_msg = 'Package information not found for class {}'.format(
klass.__class__.__name__
......@@ -142,7 +142,7 @@ def _instantiate_classes(res, xml_files, cgmes_version_path, namespace_rdf, base
# This function sets all attributes after the classes are instantiated by _instanciate_classes. Cyclic attributes like
# PowerTransformerEnd <-> PowerTransformer are set. This function also stores the information from which package file
# the attributes are read in the readInProfile dictionary.
# the attributes are read in the serializationProfile dictionary.
def _set_attributes(res, xml_files, namespace_rdf, base, logger_errors_grouped):
m = len(base)
# Second step pass sets attributes and references.
......@@ -272,7 +272,7 @@ def _set_attributes(res, xml_files, namespace_rdf, base, logger_errors_grouped):
setattr(obj, attr, val)
if package is not '':
obj.readInProfile[attr] = short_package_name[package]
obj.serializationProfile[attr] = short_package_name[package]
else:
error_msg = 'Package information not found for class {}, attribute {}'.format(
obj.__class__.__name__, attr
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment