Beispiel #1
0
    def setUpClass(cls):
        # Connect to TM1
        cls.tm1 = TM1Service(**config['tm1srv01'])

        # Build 4 Dimensions
        cls.dim1_name = PREFIX + "Dimension1"
        cls.dim1_element_names = ["A " + str(i) for i in range(10)]
        cls.dim1 = Dimension(cls.dim1_name)
        h = Hierarchy(cls.dim1_name, cls.dim1_name)
        for element_name in cls.dim1_element_names:
            h.add_element(element_name, 'Numeric')
        cls.dim1.add_hierarchy(h)

        cls.dim2_name = PREFIX + "Dimension2"
        cls.dim2_element_names = ["B " + str(i) for i in range(10)]
        cls.dim2 = Dimension(cls.dim2_name)
        h = Hierarchy(cls.dim2_name, cls.dim2_name)
        for element_name in cls.dim2_element_names:
            h.add_element(element_name, 'Numeric')
        cls.dim2.add_hierarchy(h)

        cls.dim3_name = PREFIX + "Dimension3"
        cls.dim3_element_names = ["C " + str(i) for i in range(10)]
        cls.dim3 = Dimension(cls.dim3_name)
        h = Hierarchy(cls.dim3_name, cls.dim3_name)
        for element_name in cls.dim3_element_names:
            h.add_element(element_name, 'Numeric')
        cls.dim3.add_hierarchy(h)

        cls.dim4_name = PREFIX + "Dimension4"
        cls.dim4_element_names = ["D " + str(i) for i in range(10)]
        cls.dim4 = Dimension(cls.dim4_name)
        h = Hierarchy(cls.dim4_name, cls.dim4_name)
        for element_name in cls.dim4_element_names:
            h.add_element(element_name, 'Numeric')
        cls.dim4.add_hierarchy(h)

        # Define cube with 4 dimensions
        cls.cube_name = PREFIX + "Cube"
        cls.cube = Cube(name=cls.cube_name,
                        dimensions=[
                            cls.dim1_name, cls.dim2_name, cls.dim3_name,
                            cls.dim4_name
                        ])
Beispiel #2
0
    def setUpClass(cls):
        # Namings
        cls.dimension_name1 = PREFIX + "Dimension1"
        cls.dimension_name2 = PREFIX + "Dimension2"
        cls.cube_name = PREFIX + "Cube1"
        cls.process_name1 = PREFIX + "Process1"
        cls.process_name2 = PREFIX + "Process2"

        # Connect to TM1
        cls.tm1 = TM1Service(**config['tm1srv01'])

        # create a simple cube with dimensions to test transactionlog methods
        if not cls.tm1.dimensions.exists(cls.dimension_name1):
            d = Dimension(cls.dimension_name1)
            h = Hierarchy(cls.dimension_name1, cls.dimension_name1)
            h.add_element('Total Years', 'Consolidated')
            h.add_element('No Year', 'Numeric')
            for year in range(1989, 2040, 1):
                h.add_element(str(year), 'Numeric')
                h.add_edge('Total Years', str(year), 1)
            d.add_hierarchy(h)
            cls.tm1.dimensions.create(d)

        if not cls.tm1.dimensions.exists(cls.dimension_name2):
            d = Dimension(cls.dimension_name2)
            h = Hierarchy(cls.dimension_name2, cls.dimension_name2)
            h.add_element('Value', 'Numeric')
            d.add_hierarchy(h)
            cls.tm1.dimensions.create(d)

        if not cls.tm1.cubes.exists(cls.cube_name):
            cube = Cube(cls.cube_name,
                        [cls.dimension_name1, cls.dimension_name2])
            cls.tm1.cubes.create(cube)

        # inject process with ItemReject
        cls.process1 = Process(name=cls.process_name1,
                               prolog_procedure="ItemReject('TM1py Tests');")
        cls.tm1.processes.create(cls.process1)

        # inject process that does nothing and runs successfull
        cls.process2 = Process(name=cls.process_name2,
                               prolog_procedure="sText = 'text';")
        cls.tm1.processes.create(cls.process2)
 def create_or_update_dimension_with_hierarchies(cls):
     dimension = Dimension(cls.dimension_with_hierarchies_name)
     dimension.add_hierarchy(
         Hierarchy(
             name="Hierarchy1",
             dimension_name=dimension.name,
             elements=[Element("Elem1", "Numeric"), Element("Elem2", "Numeric"), Element("Elem3", "Numeric")]))
     dimension.add_hierarchy(
         Hierarchy(
             name="Hierarchy2",
             dimension_name=dimension.name,
             elements=[Element("Elem4", "Numeric"), Element("Elem6", "Numeric"), Element("Cons1", "Consolidated")]))
     dimension.add_hierarchy(
         Hierarchy(
             name="Hierarchy3",
             dimension_name=dimension.name,
             elements=[Element("Elem5", "Numeric"), Element("Cons2", "Consolidated"),
                       Element("Cons3", "Consolidated")]))
     cls.tm1.dimensions.update_or_create(dimension)
def create_dimensions_and_cube():
    with TM1Service(**config['tm1srv01']) as tm1:
        # Build Measure Dimension
        element = Element('Numeric Element', 'Numeric')
        hierarchy1 = Hierarchy('Python Cube Measure', 'Python Cube Measure', [element])
        dimension1 = Dimension('Python Cube Measure', [hierarchy1])
        if not tm1.dimensions.exists(dimension1.name):
            tm1.dimensions.create(dimension1)

        # Build Index Dimension
        elements = [Element(str(num), 'Numeric') for num in range(1, 100000)]
        hierarchy2 = Hierarchy('Big Dimension', 'Big Dimension', elements)
        dimension2 = Dimension('Big Dimension', [hierarchy2])
        if not tm1.dimensions.exists(dimension2.name):
            tm1.dimensions.create(dimension2)

        cube = Cube('Python Cube', [dimension2.name, dimension1.name])
        if cube.name not in tm1.cubes.get_all_names():
            tm1.cubes.create(cube)
Beispiel #5
0
 def test1_create_hierarchy(self):
     d = Dimension(self.dimension_name)
     h = Hierarchy(self.dimension_name, self.dimension_name)
     h.add_element('Total Years', 'Consolidated')
     h.add_element('No Year', 'Numeric')
     h.add_element('1989', 'Numeric')
     h.add_element_attribute('Previous Year', 'String')
     h.add_element_attribute('Next Year', 'String')
     h.add_edge('Total Years', '1989', 2)
     d.add_hierarchy(h)
     self.tm1.dimensions.create(d)
Beispiel #6
0
 def create_dimension(cls):
     d = Dimension(DIMENSION_NAME)
     h = Hierarchy(DIMENSION_NAME, DIMENSION_NAME)
     h.add_element('Total Years', 'Consolidated')
     h.add_element('No Year', 'Numeric')
     h.add_element('1989', 'Numeric')
     h.add_element("Marius's Element", "Numeric")
     h.add_element_attribute('Previous Year', 'String')
     h.add_element_attribute('Next Year', 'String')
     h.add_edge('Total Years', '1989', 2)
     d.add_hierarchy(h)
     cls.tm1.dimensions.create(d)
Beispiel #7
0
 def create_dimension(cls):
     dimension = Dimension(DIMENSION_NAME)
     hierarchy = Hierarchy(name=DIMENSION_NAME, dimension_name=DIMENSION_NAME)
     hierarchy.add_element('Total Years', 'Consolidated')
     hierarchy.add_element('No Year', 'Numeric')
     hierarchy.add_element('1989', 'Numeric')
     hierarchy.add_element("My Element", "Numeric")
     hierarchy.add_element_attribute('Previous Year', 'String')
     hierarchy.add_element_attribute('Next Year', 'String')
     hierarchy.add_edge('Total Years', '1989', 2)
     dimension.add_hierarchy(hierarchy)
     cls.tm1.dimensions.create(dimension)
Beispiel #8
0
 def add_other_hierarchy(self):
     dimension = self.tm1.dimensions.get(DIMENSION_NAME)
     # other hierarchy
     hierarchy = Hierarchy(name="Other Hierarchy", dimension_name=DIMENSION_NAME)
     hierarchy.add_element('Other Total Years', 'Consolidated')
     hierarchy.add_element('No Year', 'Numeric')
     hierarchy.add_element('1989', 'Numeric')
     hierarchy.add_element("Element With ' in the name", "Numeric")
     hierarchy.add_element_attribute('Previous Year', 'String')
     hierarchy.add_element_attribute('Next Year', 'String')
     hierarchy.add_edge('Other Total Years', '1989', 2)
     dimension.add_hierarchy(hierarchy)
     self.tm1.dimensions.update(dimension)
Beispiel #9
0
 def setup_class(cls):
     elements = [
         Element('USD', 'Numeric'),
         Element('EUR', 'Numeric'),
         Element('JPY', 'Numeric'),
         Element('CNY', 'Numeric'),
         Element('GBP', 'Numeric'),
         Element('NZD', 'Numeric')
     ]
     element_attributes = [ElementAttribute('Currency Name', 'String')]
     h = Hierarchy(cls.dimension_name, cls.dimension_name, elements,
                   element_attributes)
     d = Dimension(cls.dimension_name, hierarchies=[h])
     cls.tm1.dimensions.create(d)
Beispiel #10
0
    def setUp(cls):
        # Elements
        cls.years = ("No Year", "1989", "1990", "1991", "1992")
        cls.extra_year = "4321"
        # Element Attributes
        cls.attributes = ('Previous Year', 'Next Year')
        cls.alias_attributes = ("Financial Year", )

        # create dimension with a default hierarchy
        d = Dimension(DIMENSION_NAME)
        h = Hierarchy(DIMENSION_NAME, HIERARCHY_NAME)
        h.add_element('Total Years', 'Consolidated')
        h.add_element('All Consolidations', 'Consolidated')
        h.add_edge("All Consolidations", "Total Years", 1)
        for year in cls.years:
            h.add_element(year, 'Numeric')
            h.add_edge('Total Years', year, 1)
        for attribute in cls.attributes:
            h.add_element_attribute(attribute, "String")
        for attribute in cls.alias_attributes:
            h.add_element_attribute(attribute, "Alias")
        d.add_hierarchy(h)
        cls.tm1.dimensions.create(d)

        # write attribute values
        cls.tm1.cubes.cells.write_value('1988',
                                        '}ElementAttributes_' + DIMENSION_NAME,
                                        ('1989', 'Previous Year'))
        cls.tm1.cubes.cells.write_value('1989',
                                        '}ElementAttributes_' + DIMENSION_NAME,
                                        ('1990', 'Previous Year'))
        cls.tm1.cubes.cells.write_value('1990',
                                        '}ElementAttributes_' + DIMENSION_NAME,
                                        ('1991', 'Previous Year'))
        cls.tm1.cubes.cells.write_value('1991',
                                        '}ElementAttributes_' + DIMENSION_NAME,
                                        ('1992', 'Previous Year'))

        cls.tm1.cubes.cells.write_value('1988/89',
                                        '}ElementAttributes_' + DIMENSION_NAME,
                                        ('1989', 'Financial Year'))
        cls.tm1.cubes.cells.write_value('1989/90',
                                        '}ElementAttributes_' + DIMENSION_NAME,
                                        ('1990', 'Financial Year'))
        cls.tm1.cubes.cells.write_value('1990/91',
                                        '}ElementAttributes_' + DIMENSION_NAME,
                                        ('1991', 'Financial Year'))
        cls.tm1.cubes.cells.write_value('1991/92',
                                        '}ElementAttributes_' + DIMENSION_NAME,
                                        ('1992', 'Financial Year'))
Beispiel #11
0
    def add_unbalanced_hierarchy(self, hierarchy_name):
        dimension = self.tm1.dimensions.get(DIMENSION_NAME)
        # other hierarchy
        hierarchy = Hierarchy(name=hierarchy_name, dimension_name=DIMENSION_NAME)

        hierarchy.add_element("Total Years Unbalanced", "Consolidated")
        hierarchy.add_element('1989', 'Numeric')
        hierarchy.add_element('1990', 'Numeric')
        hierarchy.add_element('1991', 'Numeric')
        hierarchy.add_edge("Total Years Unbalanced", "1989", 1)
        hierarchy.add_edge("Total Years Unbalanced", "1990", 1)
        dimension.add_hierarchy(hierarchy)

        self.tm1.dimensions.update(dimension)
Beispiel #12
0
    def setUp(self):
        # Instantiate Subsets
        self.static_subset = Subset(dimension_name=self.dimension_name,
                                    subset_name=self.subset_name_static,
                                    elements=['USD', 'EUR', 'NZD', 'Dum\'my'])
        self.dynamic_subset = Subset(
            dimension_name=self.dimension_name,
            subset_name=self.subset_name_dynamic,
            expression='{ HIERARCHIZE( {TM1SUBSETALL( [' +
            self.dimension_name + '] )} ) }')

        elements = [
            Element('USD', 'Numeric'),
            Element('EUR', 'Numeric'),
            Element('JPY', 'Numeric'),
            Element('CNY', 'Numeric'),
            Element('GBP', 'Numeric'),
            Element('NZD', 'Numeric'),
            Element('Dum\'my', 'Numeric')
        ]
        element_attributes = [ElementAttribute('Currency Name', 'String')]
        h = Hierarchy(self.dimension_name, self.dimension_name, elements,
                      element_attributes)
        d = Dimension(self.dimension_name, hierarchies=[h])
        self.tm1.dimensions.create(d)

        elements = [Element(self.unfriendly_element_name, "Numeric")]
        h = Hierarchy(self.unfriendly_dimension_name,
                      self.unfriendly_dimension_name, elements)
        d = Dimension(self.unfriendly_dimension_name, hierarchies=[h])
        self.tm1.dimensions.create(d)

        for private in (True, False):
            self.tm1.dimensions.subsets.create(subset=self.static_subset,
                                               private=private)
            self.tm1.dimensions.subsets.create(subset=self.dynamic_subset,
                                               private=private)
    def setUp(cls):
        # create dimension with a default hierarchy
        d = Dimension(cls.dimension_name)
        h = Hierarchy(cls.dimension_name, cls.hierarchy_name)

        # add elements
        cls.years = ("No Year", "1989", "1990", "1991", "1992")
        cls.extra_year = "4321"

        h.add_element('Total Years', 'Consolidated')
        h.add_element('All Consolidations', 'Consolidated')
        h.add_edge("All Consolidations", "Total Years", 1)
        for year in cls.years:
            h.add_element(year, 'Numeric')
            h.add_edge('Total Years', year, 1)

        # add attributes
        cls.attributes = ('Previous Year', 'Next Year')
        cls.alias_attributes = ("Financial Year", )

        for attribute in cls.attributes:
            h.add_element_attribute(attribute, "String")
        for attribute in cls.alias_attributes:
            h.add_element_attribute(attribute, "Alias")
        d.add_hierarchy(h)
        cls.tm1.dimensions.update_or_create(d)

        cls.added_attribute_name = "NewAttribute"

        # write attribute values
        cls.tm1.cubes.cells.write_value('1988', cls.attribute_cube_name,
                                        ('1989', 'Previous Year'))
        cls.tm1.cubes.cells.write_value('1989', cls.attribute_cube_name,
                                        ('1990', 'Previous Year'))
        cls.tm1.cubes.cells.write_value('1990', cls.attribute_cube_name,
                                        ('1991', 'Previous Year'))
        cls.tm1.cubes.cells.write_value('1991', cls.attribute_cube_name,
                                        ('1992', 'Previous Year'))

        cls.tm1.cubes.cells.write_value('1988/89', cls.attribute_cube_name,
                                        ('1989', 'Financial Year'))
        cls.tm1.cubes.cells.write_value('1989/90', cls.attribute_cube_name,
                                        ('1990', 'Financial Year'))
        cls.tm1.cubes.cells.write_value('1990/91', cls.attribute_cube_name,
                                        ('1991', 'Financial Year'))
        cls.tm1.cubes.cells.write_value('1991/92', cls.attribute_cube_name,
                                        ('1992', 'Financial Year'))

        cls.create_or_update_dimension_with_hierarchies()
Beispiel #14
0
def create_dimensions_and_cube():
    with TM1Service(address='localhost',
                    port=12354,
                    user='******',
                    password='******',
                    ssl=True) as tm1:
        # Build Measure Dimension
        element = Element('Numeric Element', 'Numeric')
        hierarchy1 = Hierarchy('Python Cube Measure', 'Python Cube Measure',
                               [element])
        dimension1 = Dimension('Python Cube Measure', [hierarchy1])
        if not tm1.dimensions.exists(dimension1.name):
            tm1.dimensions.create(dimension1)

        # Build Index Dimension
        elements = [Element(str(num), 'Numeric') for num in range(1, 100000)]
        hierarchy2 = Hierarchy('Big Dimension', 'Big Dimension', elements)
        dimension2 = Dimension('Big Dimension', [hierarchy2])
        if not tm1.dimensions.exists(dimension2.name):
            tm1.dimensions.create(dimension2)

        cube = Cube('Python Cube', [dimension2.name, dimension1.name])
        if cube.name not in tm1.cubes.get_all_names():
            tm1.cubes.create(cube)
Beispiel #15
0
    def test1_create_hierarchy(self):
        d = Dimension(self.dimension_name)
        h = Hierarchy(self.dimension_name, self.dimension_name)
        h.add_element('Total Years', 'Consolidated')
        h.add_element('No Year', 'Numeric')
        h.add_element('1989', 'Numeric')
        h.add_element_attribute('Previous Year', 'String')
        h.add_element_attribute('Next Year', 'String')
        h.add_edge('Total Years', '1989', 2)
        d.add_hierarchy(h)
        self.tm1.dimensions.create(d)

        time.sleep(1)
        s = Subset(self.subset_name,
                   self.dimension_name,
                   self.dimension_name,
                   expression="{{[{}].Members}}".format(self.dimension_name))
        self.tm1.dimensions.subsets.create(s, False)
Beispiel #16
0
 def create_dimension(cls):
     root_element = Element(name='Root', element_type='Consolidated')
     elements = [root_element]
     edges = {}
     for i in range(1, 1001):
         element_name = "Element {}".format(i)
         elements.append(Element(name=element_name, element_type='Numeric'))
         edges[('Root', element_name)] = i
     element_attributes = [
         ElementAttribute(name='Name Long', attribute_type='Alias'),
         ElementAttribute(name='Name Short', attribute_type='Alias')]
     h = Hierarchy(
         name=DIMENSION_NAME,
         dimension_name=DIMENSION_NAME,
         elements=elements,
         edges=edges,
         element_attributes=element_attributes)
     d = Dimension(name=DIMENSION_NAME, hierarchies=[h])
     cls.tm1.dimensions.create(d)
Beispiel #17
0
    def test1_create_dimension(self):
        root_element = Element(name='Root', element_type='Consolidated')
        elements = [root_element]
        edges = {}
        for i in range(1000):
            element_name = str(uuid.uuid4())
            elements.append(Element(name=element_name, element_type='Numeric'))
            edges[('Root', element_name)] = i
        h = Hierarchy(name=self.dimension_name,
                      dimension_name=self.dimension_name,
                      elements=elements,
                      edges=edges)
        d = Dimension(name=self.dimension_name, hierarchies=[h])
        # create it
        self.tm1.dimensions.create(d)

        # Test
        dimensions = self.tm1.dimensions.get_all_names()
        self.assertIn(self.dimension_name, dimensions)
Beispiel #18
0
    def setUpClass(cls):
        """
        Establishes a connection to TM1 and creates TM! 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'])

        cls.prefix = 'TM1py_unittest_element_'
        cls.dimension_name = f"{cls.prefix}{uuid.uuid4()}"
        cls.hierarchy_name = cls.dimension_name
        cls.attribute_cube_name = '}ElementAttributes_' + cls.dimension_name

        # create dimension with a default hierarchy
        d = Dimension(cls.dimension_name)
        h = Hierarchy(cls.dimension_name, cls.hierarchy_name)

        # add elements
        cls.years = ("No Year", "1989", "1990", "1991", "1992")
        cls.extra_year = "4321"

        h.add_element('Total Years', 'Consolidated')
        h.add_element('All Consolidations', 'Consolidated')
        h.add_edge("All Consolidations", "Total Years", 1)
        for year in cls.years:
            h.add_element(year, 'Numeric')
            h.add_edge('Total Years', year, 1)

        # add attributes
        cls.attributes = ('Previous Year', 'Next Year')
        cls.alias_attributes = ("Financial Year",)

        for attribute in cls.attributes:
            h.add_element_attribute(attribute, "String")
        for attribute in cls.alias_attributes:
            h.add_element_attribute(attribute, "Alias")
        d.add_hierarchy(h)
        cls.tm1.dimensions.create(d)

        cls.added_attribute_name = "NewAttribute"
Beispiel #19
0
 def setup_class(cls):
     # Build Dimensions
     for i in range(3):
         elements = [Element('Element {}'.format(str(j)), 'Numeric') for j in range(1, 1001)]
         hierarchy = Hierarchy(dimension_names[i], dimension_names[i], elements)
         dimension = Dimension(dimension_names[i], [hierarchy])
         if not cls.tm1.dimensions.exists(dimension.name):
             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)
     # Write data into cube
     cellset = {}
     for i in range(20000):
         element1 = 'Element ' + str(random.randint(1, 1000))
         element2 = 'Element ' + str(random.randint(1, 1000))
         element3 = 'Element ' + str(random.randint(1, 1000))
         cellset[(element1, element2, element3)] = random.randint(1, 1000)
     cls.tm1.data.write_values(cube_name, cellset)
Beispiel #20
0
    def test_rename_dimension(self):
        original_dimension_name = self.prefix + "Original_Dimension"
        renamed_dimension_name = self.prefix + "Renamed_Dimension"

        # if dimensions exist in TM1.. delete them
        for dim_name in (original_dimension_name, renamed_dimension_name):
            if self.tm1.dimensions.exists(dim_name):
                self.tm1.dimensions.delete(dimension_name=dim_name)

        # create dimension
        original_dimension = Dimension(original_dimension_name)
        hierarchy = Hierarchy(name=original_dimension_name,
                              dimension_name=original_dimension_name)
        hierarchy.add_element(element_name="Total",
                              element_type="Consolidated")
        hierarchy.add_element(element_name="Elem1", element_type="Numeric")
        hierarchy.add_element(element_name="Elem2", element_type="Numeric")
        hierarchy.add_element(element_name="Elem3", element_type="Numeric")
        hierarchy.add_edge(parent="Total", component="Elem1", weight=1)
        hierarchy.add_edge(parent="Total", component="Elem2", weight=1)
        hierarchy.add_edge(parent="Total", component="Elem3", weight=1)
        original_dimension.add_hierarchy(hierarchy)
        self.tm1.dimensions.create(original_dimension)

        # rename
        renamed_dimension = self.tm1.dimensions.get(original_dimension.name)
        renamed_dimension.name = renamed_dimension_name
        self.tm1.dimensions.create(renamed_dimension)

        # challenge equality of dimensions
        summary1 = self.tm1.dimensions.hierarchies.get_hierarchy_summary(
            dimension_name=original_dimension_name,
            hierarchy_name=original_dimension_name)
        summary2 = self.tm1.dimensions.hierarchies.get_hierarchy_summary(
            dimension_name=renamed_dimension_name,
            hierarchy_name=renamed_dimension_name)
        self.assertEqual(summary1, summary2)

        # delete
        for dim_name in (original_dimension_name, renamed_dimension_name):
            self.tm1.dimensions.delete(dimension_name=dim_name)
    def setUpClass(cls):
        """
        Establishes a connection to TM1 and creates a dimensions and a cube 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)]
            hierarchy = Hierarchy(dimension_name=dimension_name,
                                  name=dimension_name,
                                  elements=elements)
            dimension = Dimension(dimension_name, [hierarchy])
            cls.tm1.dimensions.update_or_create(dimension)

        # Build Cube
        cube = Cube(cls.cube_name, cls.dimension_names)
        cls.tm1.cubes.update_or_create(cube)
Beispiel #22
0
def build_simple_dimension(tm1, dimension_name, dimension_elements, overwrite):
    elements = [
        Element(name=element_name, element_type='Numeric')
        for element_name in dimension_elements
    ]
    total_element = 'Total ' + dimension_name
    elements.append(Element(name=total_element, element_type='Consolidated'))

    edges = {(total_element, element): 1 for element in dimension_elements}

    # Build Hierarchy, Dimension
    hier = Hierarchy(name=dimension_name,
                     dimension_name=dimension_name,
                     elements=elements,
                     edges=edges)
    dim = Dimension(name=dimension_name, hierarchies=[hier])

    # Interaction with TM1
    exists = tm1.dimensions.exists(dimension_name)
    if not exists:
        tm1.dimensions.create(dim)
    elif exists and overwrite:
        tm1.dimensions.update(dim)
Beispiel #23
0
    def setup_class(cls):
        cls.tm1 = TM1Service(**test_config)

        # Do random stuff
        cls.private = bool(random.getrandbits(1))

        # Define Names
        cls.prefix = 'TM1py_unittest_dimension_'
        cls.dimension_name = cls.prefix + str(uuid.uuid4())
        cls.subset_name_static = cls.prefix + str(uuid.uuid4())
        cls.subset_name_dynamic = cls.prefix + str(uuid.uuid4())

        # Instantiate Subsets
        cls.static_subset = Subset(dimension_name=cls.dimension_name,
                                   subset_name=cls.subset_name_static,
                                   elements=['USD', 'EUR', 'NZD', 'Dum\'my'])
        cls.dynamic_subset = Subset(
            dimension_name=cls.dimension_name,
            subset_name=cls.subset_name_dynamic,
            expression='{ HIERARCHIZE( {TM1SUBSETALL( [' + cls.dimension_name +
            '] )} ) }')

        elements = [
            Element('USD', 'Numeric'),
            Element('EUR', 'Numeric'),
            Element('JPY', 'Numeric'),
            Element('CNY', 'Numeric'),
            Element('GBP', 'Numeric'),
            Element('NZD', 'Numeric'),
            Element('Dum\'my', 'Numeric')
        ]
        element_attributes = [ElementAttribute('Currency Name', 'String')]
        h = Hierarchy(cls.dimension_name, cls.dimension_name, elements,
                      element_attributes)
        d = Dimension(cls.dimension_name, hierarchies=[h])
        cls.tm1.dimensions.create(d)
Beispiel #24
0
    def setUpClass(cls):
        """
        Establishes a connection to TM1 and creates TM! 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'])

        # generate random coordinates
        cls.target_coordinates = list(
            zip(('Element ' + str(e) for e in range(1, 100)),
                ('Element ' + str(e) for e in range(1, 100)),
                ('Element ' + str(e) for e in range(1, 100))))

        # 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)
            attribute_cube = "}ElementAttributes_" + dimension_name
            attribute_values = dict()
            for element in elements:
                attribute_values[(element.name, "Attr1")] = "TM1py"
                attribute_values[(element.name, "Attr2")] = "2"
                attribute_values[(element.name, "Attr3")] = "3"
            cls.tm1.cubes.cells.write_values(attribute_cube, attribute_values)

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

        # Sum of all the values that we write in the cube. serves as a checksum.
        cls.total_value = 0

        # cellset of data that shall be written
        cls.cellset = {}
        for element1, element2, element3 in cls.target_coordinates:
            value = 1
            cls.cellset[(element1, element2, element3)] = value
            # update the checksum
            cls.total_value += value

        # Fill cube with values
        cls.tm1.cubes.cells.write_values(CUBE_NAME, cls.cellset)

        # Elements
        cls.years = ("No Year", "1989", "1990", "1991", "1992")
        cls.extra_year = "4321"
        # Element Attributes
        cls.attributes = ('Previous Year', 'Next Year')
        cls.alias_attributes = ("Financial Year", )

        # create dimension with a default hierarchy
        d = Dimension(DIMENSION_NAME)
        h = Hierarchy(DIMENSION_NAME, DIMENSION_NAME)
        h.add_element('Total Years', 'Consolidated')
        h.add_element('All Consolidations', 'Consolidated')
        h.add_edge("All Consolidations", "Total Years", 1)
        for year in cls.years:
            h.add_element(year, 'Numeric')
            h.add_edge('Total Years', year, 1)
        for attribute in cls.attributes:
            h.add_element_attribute(attribute, "String")
        for attribute in cls.alias_attributes:
            h.add_element_attribute(attribute, "Alias")
        d.add_hierarchy(h)
        cls.tm1.dimensions.update_or_create(d)

        # write attribute values
        cls.tm1.cubes.cells.write_value('1988',
                                        '}ElementAttributes_' + DIMENSION_NAME,
                                        ('1989', 'Previous Year'))
        cls.tm1.cubes.cells.write_value('1989',
                                        '}ElementAttributes_' + DIMENSION_NAME,
                                        ('1990', 'Previous Year'))
        cls.tm1.cubes.cells.write_value('1990',
                                        '}ElementAttributes_' + DIMENSION_NAME,
                                        ('1991', 'Previous Year'))
        cls.tm1.cubes.cells.write_value('1991',
                                        '}ElementAttributes_' + DIMENSION_NAME,
                                        ('1992', 'Previous Year'))

        cls.tm1.cubes.cells.write_value('1988/89',
                                        '}ElementAttributes_' + DIMENSION_NAME,
                                        ('1989', 'Financial Year'))
        cls.tm1.cubes.cells.write_value('1989/90',
                                        '}ElementAttributes_' + DIMENSION_NAME,
                                        ('1990', 'Financial Year'))
        cls.tm1.cubes.cells.write_value('1990/91',
                                        '}ElementAttributes_' + DIMENSION_NAME,
                                        ('1991', 'Financial Year'))
        cls.tm1.cubes.cells.write_value('1991/92',
                                        '}ElementAttributes_' + DIMENSION_NAME,
                                        ('1992', 'Financial Year'))
Beispiel #25
0
    # create elements objects
    elements = [
        Element(name='Europe', element_type='Consolidated'),
        Element(name='CH', element_type='Numeric'),
        Element(name='UK', element_type='Numeric'),
        Element(name='BE', element_type='Numeric')
    ]

    # create edge object
    edges = {('Europe', 'CH'): 1, ('Europe', 'UK'): 1, ('Europe', 'BE'): 1}

    # create the element_attributes
    element_attributes = [
        ElementAttribute(name='Name Long', attribute_type='Alias'),
        ElementAttribute(name='Name Short', attribute_type='Alias'),
        ElementAttribute(name='Currency', attribute_type='String')
    ]

    # create hierarchy object
    hierarchy = Hierarchy(name=name,
                          dimension_name=name,
                          elements=elements,
                          element_attributes=element_attributes,
                          edges=edges)

    # create dimension object
    d = Dimension(name=name, hierarchies=[hierarchy])

    # create dimension in TM1 !
    tm1.dimensions.create(d)
Beispiel #26
0
# Time magic with python generator
def daterange(start_date, end_date):
    for n in range(int((end_date - start_date).days)):
        yield start_date + timedelta(n)


# push data to TM1
with TM1Service(**config['tm1srv01']) as tm1:
    # ============================
    # create TM1 objects for fx rates sample
    currencies = ('RMB', 'EUR', 'JPY', 'CHF', 'USD', 'AUD', 'TWD', 'HKD',
                  'GBP', 'SGD', 'INR')
    elements = [Element(cur, 'Numeric') for cur in currencies]

    # create dimension TM1py Currency From
    hierarchy = Hierarchy('TM1py Currency From', 'TM1py Currency From',
                          elements)
    dimension = Dimension('TM1py Currency From', [hierarchy])
    if not tm1.dimensions.exists(dimension.name):
        tm1.dimensions.create(dimension)

    # create dimension TM1py Currency To
    hierarchy = Hierarchy('TM1py Currency To', 'TM1py Currency To', elements)
    dimension = Dimension('TM1py Currency To', [hierarchy])
    if not tm1.dimensions.exists(dimension.name):
        tm1.dimensions.create(dimension)

    # create dimension TM1py Date
    start_date = date(1990, 1, 1)
    end_date = date(2041, 1, 1)
    elements = [
        Element(str(single_date), 'Numeric')
Beispiel #27
0
    def setUpClass(cls):
        # Namings
        cls.expand_process_name = str(uuid.uuid4())
        cls.expand_process_name_obf = str(uuid.uuid4())
        cls.process_name = str(uuid.uuid4())
        cls.process_name_obf = str(uuid.uuid4())
        cls.dimension_name = str(uuid.uuid4())
        cls.dimension_name_cloned = str(uuid.uuid4())
        cls.cube_name = str(uuid.uuid4())
        cls.cube_name_cloned = str(uuid.uuid4())

        # Connect to TM1
        cls.tm1 = TM1Service(**config['tm1srv01'])

        # create process
        prolog = "\r\nSaveDataAll;\r\nsText='abcABC';\r\n"
        epilog = "SaveDataAll;"
        cls.process = Process(
            name=cls.process_name,
            prolog_procedure=prolog,
            epilog_procedure=epilog)
        # create process with expand in TM1
        if cls.tm1.processes.exists(cls.process.name):
            cls.tm1.processes.delete(cls.process.name)
        cls.tm1.processes.create(cls.process)

        # create process with expand
        prolog = "\r\nnRevenue = 20;\r\nsRevenue = EXPAND('%nrevenue%');\r\nIF(sRevenue @ <> '20.000');\r\n" \
                 "ProcessBreak;\r\nENDIF;"
        cls.expand_process = Process(
            name=cls.expand_process_name,
            prolog_procedure=prolog)
        # create process with expand in TM1
        if cls.tm1.processes.exists(cls.expand_process.name):
            cls.tm1.processes.delete(cls.expand_process.name)
        cls.tm1.processes.create(cls.expand_process)

        # create dimension that we clone through obfuscated bedrock as part of the test
        if not cls.tm1.dimensions.exists(cls.dimension_name):
            d = Dimension(cls.dimension_name)
            h = Hierarchy(cls.dimension_name, cls.dimension_name)
            h.add_element('Total Years', 'Consolidated')
            h.add_element('No Year', 'Numeric')
            for year in range(1989, 2040, 1):
                h.add_element(str(year), 'Numeric')
                h.add_edge('Total Years', str(year), 1)
            d.add_hierarchy(h)
            cls.tm1.dimensions.create(d)

            # Create 2 Attributes through TI
            ti_statements = ["AttrInsert('{}','','Previous Year', 'S')".format(cls.dimension_name),
                             "AttrInsert('{}','','Next Year', 'S');".format(cls.dimension_name)]
            ti = ';'.join(ti_statements)
            cls.tm1.processes.execute_ti_code(lines_prolog=ti)

        # create }ElementAttribute values
        cellset = {}
        for year in range(1989, 2040, 1):
            cellset[(str(year), 'Previous Year')] = year - 1
            cellset[(str(year), 'Next Year')] = year + 1
        cls.tm1.cubes.cells.write_values("}ElementAttributes_" + cls.dimension_name, cellset)

        # create a simple cube to be cloned through bedrock
        if not cls.tm1.cubes.exists(cls.cube_name):
            cube = Cube(cls.cube_name, ["}Dimensions", "}Cubes"], "[]=S:'TM1py';")
            cls.tm1.cubes.create(cube)

        # create bedrocks if they doesn't exist
        for bedrock in ("Bedrock.Dim.Clone", "Bedrock.Cube.Clone"):
            if not cls.tm1.processes.exists(bedrock):
                with open(os.path.join("resources", bedrock + ".json"), "r") as file:
                    process = Process.from_json(file.read())
                    cls.tm1.processes.create(process)
Beispiel #28
0
def build_date_dimension(tm1, dimension_name, first_date, last_date,
                         overwrite):
    date_span = last_date - first_date
    dates = [
        str(first_date + timedelta(day)) for day in range(date_span.days + 1)
    ]
    # Build Leaves
    leaves = [Element(name=date, element_type='Numeric') for date in dates]

    # Build Consolidations
    years = [str(year) for year in range(first_date.year, last_date.year + 1)]
    consolidations = [
        Element(name=year, element_type='Consolidated') for year in years
    ]

    for year in years:
        for month in range(1, 13):
            year_month = year + "-" + str(month).zfill(2)
            consolidations.append(
                Element(name=year_month, element_type="Consolidated"))

    # Build Elements
    elements = leaves + consolidations

    # Build Edges
    edges = CaseAndSpaceInsensitiveTuplesDict()
    for year in years:
        for month in range(1, 13):
            year_month = year + "-" + str(month).zfill(2)
            edges[(year, year_month)] = 1
        for date in filter(lambda d: d[0:4] == year, dates):
            year_month = date[0:7]
            edges[(year_month, date)] = 1

    # Build Attribute
    attributes = [
        ElementAttribute('Alias', 'Alias'),
        ElementAttribute('Year', 'String'),
        ElementAttribute('Month', 'String'),
        ElementAttribute('Day', 'String'),
        ElementAttribute('Weekday', 'String')
    ]

    # write Aliases
    attribute_values = {}
    for date in dates:
        # Year, Month, Day Attributes
        attribute_values[(date, 'Year')] = date.split('-')[0]
        attribute_values[(date, 'Month')] = date.split('-')[1]
        attribute_values[(date, 'Day')] = date.split('-')[2]
        attribute_values[(
            date, 'Weekday')] = dateutil.parser.parse(date).weekday() + 1
        # US Notation as Alias
        year, month, day = [str(int(ymd)) for ymd in date.split('-')]
        attribute_values[(date, 'Alias')] = month + "/" + day + "/" + year

    # Build Hierarchy, Dimension
    hier = Hierarchy(name=dimension_name,
                     dimension_name=dimension_name,
                     elements=elements,
                     edges=edges,
                     element_attributes=attributes)
    dim = Dimension(name=dimension_name, hierarchies=[hier])

    # Interaction with TM1
    exists = tm1.dimensions.exists(dimension_name)
    if not exists:
        tm1.dimensions.create(dim)
    elif exists and overwrite:
        tm1.dimensions.update(dim)
    if not exists or overwrite:
        tm1.cubes.cells.write_values(cube_name="}ElementAttributes_" +
                                     dimension_name,
                                     cellset_as_dict=attribute_values)

    # Year Subsets
    for year in years:
        expr = "{ FILTER ( {TM1SubsetAll([Date])}, [Date].[Year] = '" + year + "' ) }"
        subset = Subset(year,
                        dimension_name=dimension_name,
                        hierarchy_name=dimension_name,
                        expression=expr)
        if not tm1.dimensions.hierarchies.subsets.exists(
                year, dimension_name, dimension_name, private=False):
            tm1.dimensions.hierarchies.subsets.create(subset, private=False)
        else:
            tm1.dimensions.hierarchies.subsets.update(subset, private=False)
Beispiel #29
0
    elements.append(Element('Even', 'Consolidated'))
    elements.append(Element('Odd', 'Consolidated'))
    elements.append(Element('4 Digit', 'Consolidated'))
    elements.append(Element('3 Digit', 'Consolidated'))

    edges = Utils.CaseAndSpaceInsensitiveTuplesDict()
    for i in range(2, 100001, 2):
        parent_child = ('Even', 'Element {}'.format(i))
        edges[parent_child] = 1

    for i in range(1, 100001, 2):
        parent_child = ('Odd', 'Element {}'.format(i))
        edges[parent_child] = 1

    for i in range(1000, 9999, 1):
        parent_child = ('4 Digit', 'Element {}'.format(i))
        edges[parent_child] = 1

    for i in range(100, 999, 1):
        parent_child = ('3 Digit', 'Element {}'.format(i))
        edges[parent_child] = 1

    hierarchy = Hierarchy(name=DIMENSION_NAME,
                          dimension_name=DIMENSION_NAME,
                          elements=elements,
                          edges=edges)
    dimension = Dimension(name=DIMENSION_NAME, hierarchies=[hierarchy])

    # Send everything to TM1
    tm1.dimensions.create(dimension)
Beispiel #30
0
    def setup_class(cls):
        # Connection to TM1
        cls.tm1 = TM1Service(**config['tm1srv01'])

        # generate random coordinates
        cls.target_coordinates = list(
            zip(('Element ' + str(random.randint(1, 1000))
                 for _ in range(100)),
                ('Element ' + str(random.randint(1, 1000))
                 for _ in range(100)),
                ('Element ' + str(random.randint(1, 1000))
                 for _ in range(100))))

        # 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 not cls.tm1.dimensions.exists(dimension.name):
                cls.tm1.dimensions.create(dimension)
            attribute_cube = "}ElementAttributes_" + dimension_name
            attribute_values = dict()
            for element in elements:
                attribute_values[(element.name, "Attr1")] = "TM1py"
                attribute_values[(element.name, "Attr2")] = "2"
                attribute_values[(element.name, "Attr3")] = "3"
            cls.tm1.cubes.cells.write_values(attribute_cube, attribute_values)

        # 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)
        subset = AnonymousSubset(dimension_name=dimension_names[0],
                                 expression='{[' + dimension_names[0] +
                                 '].Members}')
        view.add_row(dimension_name=dimension_names[0], subset=subset)
        subset = AnonymousSubset(dimension_name=dimension_names[1],
                                 expression='{[' + dimension_names[1] +
                                 '].Members}')
        view.add_row(dimension_name=dimension_names[1], subset=subset)
        subset = AnonymousSubset(dimension_name=dimension_names[2],
                                 expression='{[' + dimension_names[2] +
                                 '].Members}')
        view.add_column(dimension_name=dimension_names[2], subset=subset)
        cls.tm1.cubes.views.create(view, private=False)

        # Sum of all the values that we write in the cube. serves as a checksum
        cls.total_value = 0

        # cellset of data that shall be written
        cls.cellset = {}
        for element1, element2, element3 in cls.target_coordinates:
            value = random.randint(1, 1000)
            cls.cellset[(element1, element2, element3)] = value
            # update the checksum
            cls.total_value += value