コード例 #1
1
ファイル: View.py プロジェクト: MariusWirtz/TM1py
    def test1_create_view(self):
        # create instance of native View
        native_view = NativeView(cube_name='Plan_BudgetPlan',
                                 view_name=self.native_view_name)

        # set up native view - put subsets on Rows, Columns and Titles
        subset = self.tm1.get_subset(dimension_name='plan_version', subset_name='FY 2004 Budget', private=False)
        native_view.add_row(dimension_name='plan_version', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_business_unit', subset_name='n level business unit',
                                     private=False)
        native_view.add_row(dimension_name='plan_business_unit', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_department', subset_name='n level departments', private=False)
        native_view.add_row(dimension_name='plan_department', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_chart_of_accounts', subset_name='Consolidations',
                                     private=False)
        native_view.add_row(dimension_name='plan_chart_of_accounts', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_exchange_rates', subset_name='local', private=False)
        native_view.add_title(dimension_name='plan_exchange_rates', subset=subset, selection='local')

        subset = self.tm1.get_subset(dimension_name='plan_time', subset_name='2004 Total Year', private=False)
        native_view.add_column(dimension_name='plan_time', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_source', subset_name='budget', private=False)
        native_view.add_column(dimension_name='plan_source', subset=subset)

        # create native view on Server
        self.tm1.create_view(view=native_view, private=self.random_boolean)

        # create instance of MDXView
        nv_view = self.tm1.get_native_view(cube_name='Plan_BudgetPlan', view_name=self.native_view_name,
                                           private=self.random_boolean)
        mdx = nv_view.as_MDX
        mdx_view = MDXView(cube_name='Plan_BudgetPlan',
                           view_name=self.mdx_view_name,
                           MDX=mdx)
        # create mdx view on Server
        self.tm1.create_view(view=mdx_view, private=self.random_boolean)
コード例 #2
0
ファイル: View.py プロジェクト: jischebeck/TM1py
    def test1_create_view(self):
        # create instance of native View
        native_view = NativeView(cube_name='Plan_BudgetPlan',
                                 view_name=self.native_view_name)

        # set up native view - put subsets on Rows, Columns and Titles
        subset = self.tm1.get_subset(dimension_name='plan_version',
                                     subset_name='FY 2004 Budget',
                                     private=False)
        native_view.add_row(dimension_name='plan_version', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_business_unit',
                                     subset_name='n level business unit',
                                     private=False)
        native_view.add_row(dimension_name='plan_business_unit', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_department',
                                     subset_name='n level departments',
                                     private=False)
        native_view.add_row(dimension_name='plan_department', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_chart_of_accounts',
                                     subset_name='Consolidations',
                                     private=False)
        native_view.add_row(dimension_name='plan_chart_of_accounts',
                            subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_exchange_rates',
                                     subset_name='local',
                                     private=False)
        native_view.add_title(dimension_name='plan_exchange_rates',
                              subset=subset,
                              selection='local')

        subset = self.tm1.get_subset(dimension_name='plan_time',
                                     subset_name='2004 Total Year',
                                     private=False)
        native_view.add_column(dimension_name='plan_time', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_source',
                                     subset_name='budget',
                                     private=False)
        native_view.add_column(dimension_name='plan_source', subset=subset)

        # create native view on Server
        self.tm1.create_view(view=native_view, private=self.random_boolean)

        # create instance of MDXView
        nv_view = self.tm1.get_native_view(cube_name='Plan_BudgetPlan',
                                           view_name=self.native_view_name,
                                           private=self.random_boolean)
        mdx = nv_view.as_MDX
        mdx_view = MDXView(cube_name='Plan_BudgetPlan',
                           view_name=self.mdx_view_name,
                           MDX=mdx)
        # create mdx view on Server
        self.tm1.create_view(view=mdx_view, private=self.random_boolean)
コード例 #3
0
ファイル: View.py プロジェクト: zPat/TM1py
    def test1_create_view(self):
        # create instance of native View
        native_view = NativeView(name_cube='Plan_BudgetPlan',
                                 name_view=self.native_view_name)

        # set up native view - put subsets on Rows, Columns and Titles
        subset = self.tm1.get_subset(dimension_name='plan_version', subset_name='FY 2004 Budget')
        native_view.add_row(dimension_name='plan_version', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_business_unit', subset_name='n level business unit')
        native_view.add_row(dimension_name='plan_business_unit', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_department', subset_name='n level departments')
        native_view.add_row(dimension_name='plan_department', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_chart_of_accounts', subset_name='Consolidations')
        native_view.add_row(dimension_name='plan_chart_of_accounts', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_source', subset_name='budget')
        native_view.add_row(dimension_name='plan_source', subset=subset)

        subset = self.tm1.get_subset(dimension_name='plan_exchange_rates', subset_name='actual')
        native_view.add_title(dimension_name='plan_exchange_rates', subset=subset, selection='actual')

        subset = self.tm1.get_subset(dimension_name='plan_time', subset_name='2003 Total Year')
        native_view.add_column(dimension_name='plan_time', subset=subset)

        # create native view on Server
        self.tm1.create_view(view=native_view, private=self.random_boolean)

        # create instance of MDXView
        mdx = "SELECT {([plan_version].[FY 2003 Budget], [plan_department].[105], [plan_chart_of_accounts].[61030], " \
              "[plan_exchange_rates].[local], [plan_source].[goal] , [plan_time].[Jan-2004]) } on COLUMNS," \
              "{[plan_business_unit].[10110]} on ROWS FROM [plan_BudgetPlan]"
        mdx_view = MDXView(cube_name='Plan_BudgetPlan',
                           view_name=self.mdx_view_name,
                           MDX=mdx)
        # create mdx view on Server
        self.tm1.create_view(view=mdx_view, private=self.random_boolean)
コード例 #4
0
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):
        tm1.cubes.views.delete(cube_name="Bike Shares",
                               view_name="Bike Shares By City",
                               private=False)

    tm1.cubes.views.create(view=view, private=False)
コード例 #5
0
ファイル: View.py プロジェクト: rimoe/TM1py
q = TM1Queries(ip='', port=8008, user='******', password='******', ssl=True)

# random text
random_string = str(uuid.uuid4())

# create native view
view = NativeView(name_cube='plan_Budgetplan', name_view=random_string)

# assign subsets to rows, columns, titles
view.add_row(dimension_name='plan_version', subset_name='FY 2004 Budget')
view.add_row(dimension_name='plan_business_unit', subset_name='n level business unit')
view.add_row(dimension_name='plan_department', subset_name='n level departments')
view.add_row(dimension_name='plan_chart_of_accounts', subset_name='Consolidations')
view.add_row(dimension_name='plan_source', subset_name='budget')
view.add_title(dimension_name='plan_exchange_rates', subset_name='actual', selection='actual')
view.add_column(dimension_name='plan_time', subset_name='2003 Total Year')

# create native view against TM1 Server
q.create_view(view=view)

# delete native view from server
q.delete_view(view.get_cube(), view.get_name())

# random text
random_string = str(uuid.uuid4())

# create mdx view
mdx = "SELECT {([plan_version].[FY 2003 Budget], [plan_department].[105], [plan_chart_of_accounts].[61030], " \
      "[plan_exchange_rates].[local], [plan_source].[goal] , [plan_time].[Jan-2004]) } on COLUMNS," \
      "{[plan_business_unit].[10110]} on ROWS FROM [plan_BudgetPlan]"
mdx_view = MDXView('plan_Budgetplan', random_string, mdx)
コード例 #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
        # 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,
            suppress_empty_rows=False)
        view.add_row(
            dimension_name="Py Project Summary Measure",
            subset=AnonymousSubset(
コード例 #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)
コード例 #10
0
ファイル: create view.py プロジェクト: MariusWirtz/TM1py
# establish connection to TM1 Server
with TM1(ip='', port=8001, login=login, ssl=False) as tm1:

    native_view = NativeView(cube_name='Plan_BudgetPlan',
                             view_name='TM1py View')

    # set up native view - put subsets on Rows, Columns and Titles
    subset = tm1.get_subset(dimension_name='plan_version', subset_name='FY 2004 Budget', private=False)
    native_view.add_row(dimension_name='plan_version', subset=subset)

    subset = tm1.get_subset(dimension_name='plan_business_unit', subset_name='n level business unit', private=False)
    native_view.add_row(dimension_name='plan_business_unit', subset=subset)

    subset = tm1.get_subset(dimension_name='plan_department', subset_name='n level departments', private=False)
    native_view.add_row(dimension_name='plan_department', subset=subset)

    subset = tm1.get_subset(dimension_name='plan_chart_of_accounts', subset_name='Consolidations', private=False)
    native_view.add_row(dimension_name='plan_chart_of_accounts', subset=subset)

    subset = tm1.get_subset(dimension_name='plan_exchange_rates', subset_name='local', private=False)
    native_view.add_title(dimension_name='plan_exchange_rates', subset=subset, selection='local')

    subset = tm1.get_subset(dimension_name='plan_time', subset_name='2004 Total Year', private=False)
    native_view.add_column(dimension_name='plan_time', subset=subset)

    subset = tm1.get_subset(dimension_name='plan_source', subset_name='budget', private=False)
    native_view.add_column(dimension_name='plan_source', subset=subset)

    # create native view on Server
    tm1.create_view(view=native_view, private=False)