Example #1
0
    def add_element(self, element_name: str,
                    element_type: Union[str, Element.Types]):
        if element_name in self._elements:
            raise ValueError("Element name must be unique")

        self._elements[element_name] = Element(name=element_name,
                                               element_type=element_type)
Example #2
0
    def from_dict(cls, hierarchy_as_dict: Dict) -> 'Hierarchy':
        # Build the Dictionary for the edges
        edges = CaseAndSpaceInsensitiveTuplesDict({
            (edge['ParentName'], edge['ComponentName']): edge['Weight']
            for edge in hierarchy_as_dict['Edges']
        })

        return cls(name=hierarchy_as_dict['Name'],
                   dimension_name=hierarchy_as_dict['UniqueName']
                   [1:hierarchy_as_dict['UniqueName'].find("].[")],
                   elements=[
                       Element.from_dict(elem)
                       for elem in hierarchy_as_dict['Elements']
                   ],
                   element_attributes=[
                       ElementAttribute(ea['Name'], ea['Type'])
                       for ea in hierarchy_as_dict['ElementAttributes']
                   ],
                   edges=edges,
                   subsets=[
                       subset['Name']
                       for subset in hierarchy_as_dict['Subsets']
                   ],
                   structure=hierarchy_as_dict['Structure']
                   if 'Structure' in hierarchy_as_dict else None,
                   default_member=hierarchy_as_dict['DefaultMember']['Name']
                   if hierarchy_as_dict['DefaultMember'] else None)
Example #3
0
 def add_element(self, element_name, element_type):
     if element_name in self._elements:
         raise Exception("Elementname has to be unqiue")
     e = Element(name=element_name, element_type=element_type)
     self._elements[element_name] = e