예제 #1
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)
예제 #2
0
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(
예제 #3
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 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)
예제 #4
0
                dimensions=["Py Project", "Py Project Summary Measure"])
    if not tm1.cubes.exists(cube.name):
        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.#########",