Пример #1
0
    def from_dict(cls, view_as_dict: Dict, cube_name: str = None) -> 'NativeView':
        titles, columns, rows = [], [], []

        for selection in view_as_dict['Titles']:
            if selection['Subset']['Name'] == '':
                subset = AnonymousSubset.from_dict(selection['Subset'])
            else:
                subset = Subset.from_dict(selection['Subset'])
            selected = selection['Selected']['Name'] if selection['Selected'] else ""
            titles.append(ViewTitleSelection(dimension_name=subset.dimension_name,
                                             subset=subset, selected=selected))
        for i, axe in enumerate([view_as_dict['Columns'], view_as_dict['Rows']]):
            for selection in axe:
                if selection['Subset']['Name'] == '':
                    subset = AnonymousSubset.from_dict(selection['Subset'])
                else:
                    subset = Subset.from_dict(selection['Subset'])
                axis_selection = ViewAxisSelection(dimension_name=subset.dimension_name,
                                                   subset=subset)
                columns.append(axis_selection) if i == 0 else rows.append(axis_selection)

        return cls(
            cube_name=view_as_dict["@odata.context"][20:view_as_dict["@odata.context"].find("')/")]
            if not cube_name else cube_name,
            view_name=view_as_dict['Name'],
            suppress_empty_columns=view_as_dict['SuppressEmptyColumns'],
            suppress_empty_rows=view_as_dict['SuppressEmptyRows'],
            format_string=view_as_dict['FormatString'],
            titles=titles,
            columns=columns,
            rows=rows)
Пример #2
0
    def add_title(self, dimension_name: str, selection: str, subset: Union[Subset, AnonymousSubset] = None):
        """ Add subset and element to the titles-axis

        :param dimension_name: name of the dimension.
        :param selection: name of an element.
        :param subset:  instance of TM1py.Subset. Can be None instead.
        :return:
        """
        view_title_selection = ViewTitleSelection(dimension_name, subset, selection)
        self._titles.append(view_title_selection)