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)
def get_element_attributes(self, dimension_name, hierarchy_name): """ Get element attributes from hierarchy :param dimension_name: :param hierarchy_name: :return: """ request = '/api/v1/Dimensions(\'{}\')/Hierarchies(\'{}\')/ElementAttributes'.format( dimension_name, hierarchy_name) response = self._rest.GET(request, '') element_attributes = [ ElementAttribute.from_dict(ea) for ea in json.loads(response)['value'] ] return element_attributes
def add_element_attribute(self, name: str, attribute_type: str): attribute = ElementAttribute(name, attribute_type) if attribute not in self.element_attributes: self.element_attributes.append(attribute)
def add_element_attribute(self, name, attribute_type): if name not in self.element_attributes: self.element_attributes.append( ElementAttribute(name, attribute_type))