Beispiel #1
1
    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)
Beispiel #2
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)
Beispiel #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)
Beispiel #4
0
    def test_substitute_title(self):
        s1 = Subset("s1", "d1", "d1", None, None, ["e1", "e2"])
        s2 = Subset("s2", "d2", "d2", None, None, ["e1", "e2"])
        s3 = Subset("s3", "d3", "d3", None, None, ["e1", "e2"])

        native_view = NativeView(cube_name="c1",
                                 view_name="not_relevant",
                                 suppress_empty_columns=True,
                                 suppress_empty_rows=False,
                                 titles=[ViewTitleSelection("d1", s1, "e1")],
                                 columns=[ViewAxisSelection("d2", s2)],
                                 rows=[ViewAxisSelection("d3", s3)])

        native_view.substitute_title("d1", "e2")

        self.assertEqual(native_view.titles[0].selected, "e2")
Beispiel #5
0
def build_views(tm1: TM1Service):
    for file_name in VIEW_FILES:
        with open(file_name, "r", encoding="utf-8") as file:
            view = NativeView.from_json(file.read(), CUBE_NAME)
            if tm1.cubes.views.exists(CUBE_NAME, view.name, False):
                tm1.cubes.views.update(view, False)
            else:
                tm1.cubes.views.create(view, False)
Beispiel #6
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)
Beispiel #7
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
Beispiel #8
0
    def test_as_mdx_registered_subsets(self):
        s1 = Subset("s1", "d1", "d1", None, None, ["e1", "e2"])
        s2 = Subset("s2", "d2", "d2", None, None, ["e1", "e2"])
        s3 = Subset("s3", "d3", "d3", None, None, ["e1", "e2"])

        native_view = NativeView(cube_name="c1",
                                 view_name="not_relevant",
                                 suppress_empty_columns=True,
                                 suppress_empty_rows=False,
                                 titles=[ViewTitleSelection("d1", s1, "e1")],
                                 columns=[ViewAxisSelection("d2", s2)],
                                 rows=[ViewAxisSelection("d3", s3)])

        self.assertEqual(
            "SELECT\r\n"
            "NON EMPTY {TM1SUBSETTOSET([D2].[D2],\"s2\")} ON 0,\r\n"
            "{TM1SUBSETTOSET([D3].[D3],\"s3\")} ON 1\r\n"
            "FROM [C1]\r\n"
            "WHERE ([D1].[D1].[E1])", native_view.mdx)
config.read(r'..\config.ini')

mdx = """
SELECT
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"]))
Beispiel #10
0
    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)
Beispiel #11
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)
Beispiel #12
0
    if not tm1.cubes.exists(cube.name):
        tm1.cubes.create(cube)

    # create cube 2
    cube = Cube(
        name="Py Project Summary", 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)
Beispiel #13
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)
Beispiel #14
0
    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)
Beispiel #15
0
from TM1py import TM1pyQueries as TM1, TM1pyLogin, NativeView

login = TM1pyLogin.native('admin', 'apple')

# 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)
Beispiel #16
0
from TM1py import TM1Queries, NativeView, MDXView
import uuid

# establish connection to TM1 Server
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
Beispiel #17
0
    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)