コード例 #1
0
    def test_as_mdx_happy_case(self):
        native_view = NativeView(
            cube_name="c1",
            view_name="not_relevant",
            suppress_empty_columns=True,
            suppress_empty_rows=False,
            titles=[
                ViewTitleSelection("d3",
                                   AnonymousSubset("d3", "d3", "",
                                                   ["e3"]), "e3")
            ],
            columns=[
                ViewAxisSelection("d1",
                                  AnonymousSubset("d1", "d1", "{[d1].[e1]}"))
            ],
            rows=[
                ViewAxisSelection("d2",
                                  AnonymousSubset("d2", "d2", "{[d2].[e2]}"))
            ])

        self.assertEqual(
            "SELECT\r\n"
            "NON EMPTY {[d1].[e1]} ON 0,\r\n"
            "{[d2].[e2]} ON 1\r\n"
            "FROM [C1]\r\n"
            "WHERE ([D3].[D3].[E3])", native_view.mdx)
コード例 #2
0
    def test_as_mdx_no_columns(self):
        with self.assertRaises(ValueError) as _:
            native_view = NativeView(
                cube_name="c1",
                view_name="not_relevant",
                suppress_empty_columns=True,
                suppress_empty_rows=False,
                titles=[
                    ViewTitleSelection("d3",
                                       AnonymousSubset("d3", "d3", "", ["e3"]),
                                       "e3")
                ],
                rows=[
                    ViewAxisSelection(
                        "d1", AnonymousSubset("d1", "d1", "{[d1].[e1]}"))
                ])

            _ = native_view.mdx
コード例 #3
0
    def test_as_mdx_multi_rows_multi_columns(self):
        native_view = NativeView(
            cube_name="c1",
            view_name="not_relevant",
            suppress_empty_columns=True,
            suppress_empty_rows=True,
            titles=[
                ViewTitleSelection("d5",
                                   AnonymousSubset("d5", "d5", "",
                                                   ["e5"]), "e5"),
                ViewTitleSelection("d6",
                                   AnonymousSubset("d6", "d6", "",
                                                   ["e6"]), "e6")
            ],
            columns=[
                ViewAxisSelection("d1",
                                  AnonymousSubset("d1", "d1", "{[d1].[e1]}")),
                ViewAxisSelection("d2",
                                  AnonymousSubset("d2", "d2", "{[d2].[e2]}"))
            ],
            rows=[
                ViewAxisSelection("d3",
                                  AnonymousSubset("d3", "d3", "{[d3].[e3]}")),
                ViewAxisSelection("d4",
                                  AnonymousSubset("d4", "d4", "{[d4].[e4]}"))
            ])

        self.assertEqual(
            "SELECT\r\n"
            "NON EMPTY {[d1].[e1]} * {[d2].[e2]} ON 0,\r\n"
            "NON EMPTY {[d3].[e3]} * {[d4].[e4]} ON 1\r\n"
            "FROM [C1]\r\n"
            "WHERE ([D5].[D5].[E5],[D6].[D6].[E6])", native_view.mdx)
コード例 #4
0
    def test_as_mdx_no_titles(self):
        native_view = NativeView(
            cube_name="c1",
            view_name="not_relevant",
            suppress_empty_columns=True,
            suppress_empty_rows=False,
            columns=[
                ViewAxisSelection("d1",
                                  AnonymousSubset("d1", "d1", "{[d1].[e1]}"))
            ])

        self.assertEqual(
            "SELECT\r\n"
            "NON EMPTY {[d1].[e1]} ON 0\r\n"
            "FROM [C1]", native_view.mdx)
コード例 #5
0
NON EMPTY {[Date].[2017-11-26], [Date].[2017-11-27]} * {[Bike Shares Measure].[Count]} ON ROWS,
NON EMPTY {[City].[NYC], [City].[Chicago]} ON COLUMNS
FROM [Bike Shares]
WHERE ([Version].[Actual])
"""

with TM1Service(**config['tm1srv01']) as tm1:
    pivot = tm1.cubes.cells.execute_mdx_dataframe_pivot(mdx=mdx)
    print(pivot)

view = NativeView(cube_name="Bike Shares",
                  view_name="Bike Shares By City",
                  suppress_empty_columns=True,
                  suppress_empty_rows=True)
view.add_row(dimension_name="Date",
             subset=AnonymousSubset(dimension_name="Date",
                                    expression="{Tm1SubsetAll([Date])}"))
view.add_row(dimension_name="Bike Shares Measure",
             subset=AnonymousSubset(dimension_name="Bike Shares Measure",
                                    elements=["Count"]))
view.add_column(dimension_name="City",
                subset=AnonymousSubset(dimension_name="City",
                                       elements=["NYC", "Chicago"]))
view.add_title(dimension_name="Version",
               selection="Actual",
               subset=AnonymousSubset(dimension_name="Version",
                                      elements=["Actual"]))

with TM1Service(**config['tm1srv01']) as tm1:
    if tm1.cubes.views.exists(cube_name="Bike Shares",
                              view_name="Bike Shares By City",
                              private=False):
コード例 #6
0
ファイル: Application.py プロジェクト: ykud/tm1py
    def setUpClass(cls) -> None:
        # Build Dimensions
        for dimension_name in DIMENSION_NAMES:
            elements = [
                Element('Element {}'.format(str(j)), 'Numeric')
                for j in range(1, 1001)
            ]
            element_attributes = [
                ElementAttribute("Attr1", "String"),
                ElementAttribute("Attr2", "Numeric"),
                ElementAttribute("Attr3", "Numeric")
            ]
            hierarchy = Hierarchy(dimension_name=dimension_name,
                                  name=dimension_name,
                                  elements=elements,
                                  element_attributes=element_attributes)
            dimension = Dimension(dimension_name, [hierarchy])
            if cls.tm1.dimensions.exists(dimension.name):
                cls.tm1.dimensions.update(dimension)
            else:
                cls.tm1.dimensions.create(dimension)

        # Build Cube
        cube = Cube(CUBE_NAME, DIMENSION_NAMES)
        if not cls.tm1.cubes.exists(CUBE_NAME):
            cls.tm1.cubes.create(cube)

        # Build cube view
        view = NativeView(cube_name=CUBE_NAME,
                          view_name=VIEW_NAME,
                          suppress_empty_columns=True,
                          suppress_empty_rows=True)
        view.add_row(dimension_name=DIMENSION_NAMES[0],
                     subset=AnonymousSubset(dimension_name=DIMENSION_NAMES[0],
                                            expression='{[' +
                                            DIMENSION_NAMES[0] + '].Members}'))
        view.add_row(dimension_name=DIMENSION_NAMES[1],
                     subset=AnonymousSubset(dimension_name=DIMENSION_NAMES[1],
                                            expression='{[' +
                                            DIMENSION_NAMES[1] + '].Members}'))
        view.add_column(
            dimension_name=DIMENSION_NAMES[2],
            subset=AnonymousSubset(dimension_name=DIMENSION_NAMES[2],
                                   expression='{[' + DIMENSION_NAMES[2] +
                                   '].Members}'))
        if not cls.tm1.cubes.views.exists(CUBE_NAME, view.name, private=False):
            cls.tm1.cubes.views.create(view=view, private=False)

        # Build subset
        subset = Subset(SUBSET_NAME, DIMENSION_NAMES[0], DIMENSION_NAMES[0],
                        None, None, ["Element 1"])
        if cls.tm1.dimensions.hierarchies.subsets.exists(
                subset.name, subset.dimension_name, subset.hierarchy_name,
                False):
            cls.tm1.dimensions.hierarchies.subsets.delete(
                subset.name, subset.dimension_name, subset.hierarchy_name,
                False)
        cls.tm1.dimensions.hierarchies.subsets.create(subset, False)

        # Build process
        p1 = Process(name=PROCESS_NAME)
        p1.add_parameter('pRegion', 'pRegion (String)', value='US')
        if cls.tm1.processes.exists(p1.name):
            cls.tm1.processes.delete(p1.name)
        cls.tm1.processes.create(p1)

        # Build chore
        c1 = Chore(name=CHORE_NAME,
                   start_time=ChoreStartTime(datetime.now().year,
                                             datetime.now().month,
                                             datetime.now().day,
                                             datetime.now().hour,
                                             datetime.now().minute,
                                             datetime.now().second),
                   dst_sensitivity=False,
                   active=True,
                   execution_mode=Chore.MULTIPLE_COMMIT,
                   frequency=ChoreFrequency(days=int(random.uniform(0, 355)),
                                            hours=int(random.uniform(0, 23)),
                                            minutes=int(random.uniform(0, 59)),
                                            seconds=int(random.uniform(0,
                                                                       59))),
                   tasks=[
                       ChoreTask(0,
                                 PROCESS_NAME,
                                 parameters=[{
                                     'Name': 'pRegion',
                                     'Value': 'UK'
                                 }])
                   ])
        cls.tm1.chores.create(c1)

        # create Folder
        app = FolderApplication("", TM1PY_APP_FOLDER)
        cls.tm1.applications.create(application=app, private=False)
コード例 #7
0
    def setUpClass(cls) -> None:
        """
        Establishes a connection to TM1 and creates TM1 objects to use across all tests
        """

        # Connection to TM1
        cls.config = configparser.ConfigParser()
        cls.config.read(Path(__file__).parent.joinpath('config.ini'))
        cls.tm1 = TM1Service(**cls.config['tm1srv01'])

        # Build Dimensions
        for dimension_name in cls.dimension_names:
            elements = [
                Element('Element {}'.format(str(j)), 'Numeric')
                for j in range(1, 1001)
            ]
            element_attributes = [
                ElementAttribute("Attr1", "String"),
                ElementAttribute("Attr2", "Numeric"),
                ElementAttribute("Attr3", "Numeric")
            ]
            hierarchy = Hierarchy(dimension_name=dimension_name,
                                  name=dimension_name,
                                  elements=elements,
                                  element_attributes=element_attributes)
            dimension = Dimension(dimension_name, [hierarchy])
            if cls.tm1.dimensions.exists(dimension.name):
                cls.tm1.dimensions.update(dimension)
            else:
                cls.tm1.dimensions.create(dimension)

        # Build Cube
        cube = Cube(cls.cube_name, cls.dimension_names)
        if not cls.tm1.cubes.exists(cls.cube_name):
            cls.tm1.cubes.create(cube)

        # Build cube view
        view = NativeView(cube_name=cls.cube_name,
                          view_name=cls.view_name,
                          suppress_empty_columns=True,
                          suppress_empty_rows=True)
        view.add_row(
            dimension_name=cls.dimension_names[0],
            subset=AnonymousSubset(dimension_name=cls.dimension_names[0],
                                   expression='{[' + cls.dimension_names[0] +
                                   '].Members}'))
        view.add_row(
            dimension_name=cls.dimension_names[1],
            subset=AnonymousSubset(dimension_name=cls.dimension_names[1],
                                   expression='{[' + cls.dimension_names[1] +
                                   '].Members}'))
        view.add_column(
            dimension_name=cls.dimension_names[2],
            subset=AnonymousSubset(dimension_name=cls.dimension_names[2],
                                   expression='{[' + cls.dimension_names[2] +
                                   '].Members}'))
        if not cls.tm1.cubes.views.exists(
                cls.cube_name, view.name, private=False):
            cls.tm1.cubes.views.create(view=view, private=False)

        # Build subset
        subset = Subset(cls.subset_name, cls.dimension_names[0],
                        cls.dimension_names[0], None, None, ["Element 1"])
        if cls.tm1.dimensions.hierarchies.subsets.exists(
                subset.name, subset.dimension_name, subset.hierarchy_name,
                False):
            cls.tm1.dimensions.hierarchies.subsets.delete(
                subset.name, subset.dimension_name, subset.hierarchy_name,
                False)
        cls.tm1.dimensions.hierarchies.subsets.create(subset, False)

        # Build process
        p1 = Process(name=cls.process_name)
        p1.add_parameter('pRegion', 'pRegion (String)', value='US')
        if cls.tm1.processes.exists(p1.name):
            cls.tm1.processes.delete(p1.name)
        cls.tm1.processes.create(p1)

        # Build chore
        c1 = Chore(name=cls.chore_name,
                   start_time=ChoreStartTime(datetime.now().year,
                                             datetime.now().month,
                                             datetime.now().day,
                                             datetime.now().hour,
                                             datetime.now().minute,
                                             datetime.now().second),
                   dst_sensitivity=False,
                   active=True,
                   execution_mode=Chore.MULTIPLE_COMMIT,
                   frequency=ChoreFrequency(days=int(random.uniform(0, 355)),
                                            hours=int(random.uniform(0, 23)),
                                            minutes=int(random.uniform(0, 59)),
                                            seconds=int(random.uniform(0,
                                                                       59))),
                   tasks=[
                       ChoreTask(0,
                                 cls.process_name,
                                 parameters=[{
                                     'Name': 'pRegion',
                                     'Value': 'UK'
                                 }])
                   ])
        cls.tm1.chores.create(c1)

        # create Folder
        app = FolderApplication("", cls.tm1py_app_folder)
        cls.tm1.applications.create(application=app, private=False)
コード例 #8
0
ファイル: setup_sample.py プロジェクト: gladkovsl/cubecalc
        tm1.cubes.create(cube)

    # create views
    for project in ("Project1", "Project2", "Project3"):
        # Project Summary
        cube_name = "Py Project Summary"
        view = NativeView(
            cube_name=cube_name,
            view_name=project + " NPV",
            format_string="0.#########",
            suppress_empty_columns=False,
            suppress_empty_rows=False)
        view.add_row(
            dimension_name="Py Project Summary Measure",
            subset=AnonymousSubset(
                dimension_name="Py Project Summary Measure",
                elements=["NPV"]))
        view.add_column(
            dimension_name="Py Project",
            subset=AnonymousSubset(
                dimension_name="Py Project",
                elements=[project]))
        if tm1.cubes.views.exists(cube_name=view.cube, view_name=view.name, private=False):
            tm1.cubes.views.delete(cube_name=view.cube, view_name=view.name, private=False)
        tm1.cubes.views.create(view=view, private=False)

        view = NativeView(
            cube_name=cube_name,
            view_name=project + " IRR",
            format_string="0.#########",
            suppress_empty_columns=False,
コード例 #9
0
 def test_tm1io_input_nativeview_output_nativeview(self):
     # create input view
     view_input = NativeView(cube_name=CUBE_NAME_SOURCE,
                             view_name=VIEW_NAME_SOURCE,
                             suppress_empty_columns=False,
                             suppress_empty_rows=False)
     view_input.add_row(
         dimension_name=DIMENSION_NAMES[0],
         subset=AnonymousSubset(dimension_name=DIMENSION_NAMES[0],
                                expression="{ HEAD ( { [" +
                                DIMENSION_NAMES[0] + "].Members}," +
                                str(len(IRR_INPUT_VALUES)) + ") }"))
     view_input.add_column(
         dimension_name=DIMENSION_NAMES[1],
         subset=AnonymousSubset(dimension_name=DIMENSION_NAMES[1],
                                expression="{[" + DIMENSION_NAMES[1] +
                                "].[Element_1]}"))
     self.tm1.cubes.views.create(view=view_input, private=False)
     # create output view
     view_output = NativeView(cube_name=CUBE_NAME_TARGET,
                              view_name=VIEW_NAME_TARGET,
                              suppress_empty_columns=False,
                              suppress_empty_rows=False)
     view_output.add_row(
         dimension_name=DIMENSION_NAMES[0],
         subset=AnonymousSubset(dimension_name=DIMENSION_NAMES[0],
                                expression="{[" + DIMENSION_NAMES[0] +
                                "].[Element_1]}"))
     view_output.add_column(
         dimension_name=DIMENSION_NAMES[1],
         subset=AnonymousSubset(dimension_name=DIMENSION_NAMES[1],
                                expression="{[" + DIMENSION_NAMES[1] +
                                "].[Element_1]}"))
     self.tm1.cubes.views.create(view=view_output, private=False)
     # write values into input view
     mdx = view_input.MDX
     self.tm1.cubes.cells.write_values_through_cellset(
         mdx, IRR_INPUT_VALUES)
     # execute method
     result = irr(tm1_services={
         "tm1srv01": self.tm1,
         "tm1srv02": self.tm1
     },
                  tm1_source="tm1srv01",
                  tm1_target="tm1srv02",
                  cube_source=CUBE_NAME_SOURCE,
                  cube_target=CUBE_NAME_TARGET,
                  view_source=VIEW_NAME_SOURCE,
                  view_target=VIEW_NAME_TARGET)
     self.assertAlmostEqual(IRR_EXPECTED_RESULT,
                            result,
                            delta=IRR_TOLERANCE)
     # check output view
     cell_value = next(
         self.tm1.cubes.cells.execute_view_values(
             cube_name=CUBE_NAME_TARGET,
             view_name=VIEW_NAME_TARGET,
             private=False))
     self.assertAlmostEqual(cell_value,
                            IRR_EXPECTED_RESULT,
                            delta=IRR_TOLERANCE)