예제 #1
0
 def setUpClass(cls):
     cls.dimension1 = Dimension(
         name=DIMENSION_NAMES[0],
         hierarchies=[
             Hierarchy(name=DIMENSION_NAMES[0],
                       dimension_name=DIMENSION_NAMES[0],
                       elements=[
                           Element(name="Element_{}".format(i),
                                   element_type="Numeric")
                           for i in range(1, 101)
                       ])
         ])
     cls.dimension2 = Dimension(
         name=DIMENSION_NAMES[1],
         hierarchies=[
             Hierarchy(name=DIMENSION_NAMES[1],
                       dimension_name=DIMENSION_NAMES[1],
                       elements=[
                           Element(name="Element_{}".format(i),
                                   element_type="Numeric")
                           for i in range(1, 101)
                       ])
         ])
     cls.cube_source = Cube(name=CUBE_NAME_SOURCE,
                            dimensions=DIMENSION_NAMES)
     cls.cube_target = Cube(name=CUBE_NAME_TARGET,
                            dimensions=DIMENSION_NAMES)
예제 #2
0
    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
        cls.dimension_names = ("TM1py_tests_annotations_dimension1",
                               "TM1py_tests_annotations_dimension2",
                               "TM1py_tests_annotations_dimension3")

        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
        cls.cube_name = "TM1py_tests_annotations"

        cube = Cube(cls.cube_name, cls.dimension_names)
        cls.tm1.cubes.update_or_create(cube)
예제 #3
0
파일: Cube.py 프로젝트: jischebeck/TM1py
 def test1_create_cube(self):
     all_cubes_before = self.tm1.get_all_cube_names()
     c = Cube(self.cube_name,
              dimensions=['plan_version', 'plan_business_unit'],
              rules=Rules(''))
     self.tm1.create_cube(c)
     all_cubes_after = self.tm1.get_all_cube_names()
     self.assertEqual(len(all_cubes_before) + 1, len(all_cubes_after))
예제 #4
0
def build_cube(tm1: TM1Service):
    rules = """
    SKIPCHECK;
    ['{cube} Measure':'defaulted', 'Loan Status':'Default'] = N: 1; 
    ['{cube} Measure':'defaulted', 'Loan Status':'Charged Off'] = N: 1; 
    ['{cube} Measure':'total_pymnt_by_loan_amnt'] = N: ['{cube} Measure':'total_pymnt'] \\ ['{cube} Measure':'loan_amnt'];
    FEEDERS;
    ['{cube} Measure':'loan_amnt'] => ['{cube} Measure':'defaulted'], ['{cube} Measure':'total_pymnt_by_loan_amnt'];
    """.format(cube=CUBE_NAME)
    cube = Cube(name=CUBE_NAME, dimensions=DIMENSIONS, rules=rules)
    if not tm1.cubes.exists(cube.name):
        tm1.cubes.create(cube)
    else:
        tm1.cubes.update(cube)
예제 #5
0
    def setup_class(cls):
        # Connection to TM1
        cls.tm1 = TM1Service(**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])
            if not cls.tm1.dimensions.exists(dimension.name):
                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)

        cls.create_annotation()
예제 #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
    dimension.add_hierarchy(hierarchy)
    if not tm1.dimensions.exists(dimension.name):
        tm1.dimensions.create(dimension)

    dimension = Dimension(
        name="Py Project Summary Measure")
    hierarchy = Hierarchy(
        name="Py Project Summary Measure",
        dimension_name="Py Project Planning Measure",
        elements=[Element("IRR", "Numeric"), Element("NPV", "Numeric")])
    dimension.add_hierarchy(hierarchy)
    if not tm1.dimensions.exists(dimension.name):
        tm1.dimensions.create(dimension)

    # create cube 1
    cube = Cube(
        name="Py Project Planning", dimensions=["Py Project", "Py Quarter", "Py Project Planning Measure"])
    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,
예제 #9
0
from TM1py import TM1pyQueries as TM1, TM1pyLogin, Cube

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

with TM1(ip='', port=8001, login=login, ssl=False) as tm1:
    cube = Cube(name='Rubiks Cube',
                dimensions=['red', 'green', 'blue', 'yellow'],
                rules='')
    tm1.create_cube(cube)