def test_get_ancestors_recursive(self): hierarchy = Hierarchy(name="NotRelevant", dimension_name="NotRelevant", elements=[ Element("Total", "Consolidated"), Element("Europe", "Consolidated"), Element("DACH", "Consolidated"), Element("Germany", "Numeric"), Element("Switzerland", "Numeric"), Element("Austria", "Numeric"), Element("France", "Numeric"), Element("Other", "Numeric") ], edges={ ("Total", "Europe"): 1, ("Europe", "DACH"): 1, ("DACH", "Germany"): 1, ("DACH", "Switzerland"): 1, ("DACH", "Austria"): 1, ("Europe", "France"): 1, }) elements = hierarchy.get_ancestors("Germany", recursive=True) self.assertEqual( { Element("DACH", "Consolidated"), Element("Europe", "Consolidated"), Element("Total", "Consolidated") }, elements)
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)
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)
def setUpClass(cls): 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) c = Cube(cls.cube_name, dimensions=cls.dimension_names, rules=Rules('')) if cls.tm1.cubes.exists(c.name): cls.tm1.cubes.delete(c.name) cls.tm1.cubes.create(c)
def setUp(cls): # Connection to TM1 cls.config = configparser.ConfigParser() cls.config.read(Path(__file__).parent.joinpath('config.ini')) cls.tm1 = TM1Service(**cls.config['tm1srv01']) 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) c = Cube(cls.cube_name, dimensions=cls.dimension_names, rules=Rules('')) if cls.tm1.cubes.exists(c.name): cls.tm1.cubes.delete(c.name) cls.tm1.cubes.create(c) # Build Control Cube control_cube = Cube(cls.control_cube_name, cls.dimension_names) if not cls.tm1.cubes.exists(cls.control_cube_name): cls.tm1.cubes.create(control_cube) c = Cube(cls.control_cube_name, dimensions=cls.dimension_names, rules=Rules('')) if cls.tm1.cubes.exists(c.name): cls.tm1.cubes.delete(c.name) cls.tm1.cubes.create(c)
def test_add_component_parent_is_string(self): hierarchy = Hierarchy(name="NotRelevant", dimension_name="NotRelevant") hierarchy.add_element(element_name="c1", element_type="String") hierarchy.add_element(element_name="e1", element_type="Numeric") with self.assertRaises(ValueError) as error: hierarchy.add_component(parent_name="c1", component_name="e1", weight=1) print(str(error))
def test_add_component_component_existing(self): hierarchy = Hierarchy(name="NotRelevant", dimension_name="NotRelevant") hierarchy.add_element(element_name="c1", element_type="Consolidated") hierarchy.add_element(element_name="e1", element_type="Numeric") hierarchy.add_component(parent_name="c1", component_name="e1", weight=1) self.assertIn(("c1", "e1"), hierarchy.edges) self.assertEqual(hierarchy.edges[("c1", "e1")], 1)
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.append( Edge(parent_name='Root', component_name=element_name, weight=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.create_dimension(d) # Test dimensions = self.tm1.get_all_dimension_names() self.assertIn(self.dimension_name, dimensions)
def test3_update_dimension(self): # get dimension from tm1 d = self.tm1.get_dimension(dimension_name=self.dimension_name) # create element objects elements = [ Element(name='e1', element_type='Consolidated'), Element(name='e2', element_type='Numeric'), Element(name='e3', element_type='Numeric'), Element(name='e4', element_type='Numeric') ] # create edge objects edges = [ Edge(parent_name='e1', component_name='e2', weight=1), Edge(parent_name='e1', component_name='e3', weight=1), Edge(parent_name='e1', component_name='e4', weight=1) ] # create the element_attributes objects 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=self.dimension_name, dimension_name=self.dimension_name, elements=elements, element_attributes=element_attributes, edges=edges) # replace existing hierarchy with new hierarchy d.remove_hierarchy(self.dimension_name) d.add_hierarchy(hierarchy) # update dimension in TM1 self.tm1.update_dimension(d) # Test dimension = self.tm1.get_dimension(self.dimension_name) self.assertEqual(len(dimension.hierarchies[0].elements), len(elements))
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()
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)
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)
from TM1py import TM1Service, Dimension, Hierarchy, Element, Cube, NativeView, AnonymousSubset CONFIG = "config.ini" config = configparser.ConfigParser() config.read(CONFIG) with TM1Service(**config['tm1srv01']) as tm1: # create dimensions dimension = Dimension( name="Py Project") hierarchy = Hierarchy( name="Py Project", dimension_name="Py Project", elements=[ Element("Project1", "Numeric"), Element("Project2", "Numeric"), Element("Project3", "Numeric")]) dimension.add_hierarchy(hierarchy) if not tm1.dimensions.exists(dimension.name): tm1.dimensions.create(dimension) dimension = Dimension( name="Py Quarter") hierarchy = Hierarchy( name="Py Quarter", dimension_name="Py Quarter", elements=[ Element("2018-Q1", "Numeric"), Element("2018-Q2", "Numeric"),
def build_dimensions(tm1: TM1Service, loans: list): dimension_name = "Time" dimension = Dimension(name=dimension_name) hierarchy_name = dimension_name hierarchy = Hierarchy(name=hierarchy_name, dimension_name=dimension_name) total_element = "Total " + dimension_name hierarchy.add_element(element_name=total_element, element_type="Consolidated") for year in range(2005, 2020, 1): hierarchy.add_element(element_name=str(year), element_type="Consolidated") hierarchy.add_edge(parent=total_element, component=str(year), weight=1) for month in ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"): hierarchy.add_element(element_name="{}-{}".format( month, str(year)), element_type="Numeric") hierarchy.add_edge(parent=str(year), component="{}-{}".format(month, str(year)), weight=1) dimension.add_hierarchy(hierarchy) update_or_create_dimension(tm1, dimension) dimension_name = "Loan" dimension = Dimension(name=dimension_name) hierarchy_name = dimension_name hierarchy = Hierarchy(name=hierarchy_name, dimension_name=dimension_name) dimension.add_hierarchy(hierarchy) total_element = "Total " + dimension_name hierarchy.add_element(element_name=total_element, element_type="Consolidated") element_names = [loan.loan_id for loan in loans] # send elements and edges separately to avoid strange firewall connection abortion from server side for element_name in element_names: hierarchy.add_element(element_name=element_name, element_type="Numeric") update_or_create_dimension(tm1, dimension) for element_name in element_names: hierarchy.add_edge(parent=total_element, component=element_name, weight=1) update_or_create_dimension(tm1, dimension) dimension_name = "LC Rating" dimension = Dimension(name=dimension_name) hierarchy_name = dimension_name hierarchy = Hierarchy(name=hierarchy_name, dimension_name=dimension_name) total_element = "Total " + dimension_name hierarchy.add_element(element_name=total_element, element_type="Consolidated") for rating in ("A", "B", "C", "D", "E", "F", "G"): element_name = rating hierarchy.add_element(element_name=element_name, element_type="Consolidated") hierarchy.add_edge(parent=total_element, component=element_name, weight=1) for sub_rating in ("1", "2", "3", "4", "5"): element_name = rating + sub_rating hierarchy.add_element(element_name=element_name, element_type="Numeric") hierarchy.add_edge(parent=rating, component=element_name, weight=1) dimension.add_hierarchy(hierarchy) update_or_create_dimension(tm1, dimension) dimension_name = "FICO Score" dimension = Dimension(name=dimension_name) hierarchy_name = dimension_name hierarchy = Hierarchy(name=hierarchy_name, dimension_name=dimension_name) total_element = "Total " + dimension_name hierarchy.add_element(element_name=total_element, element_type="Consolidated") for element_name in range(300, 851, 1): hierarchy.add_element(element_name=str(element_name), element_type="Numeric") hierarchy.add_edge(parent=total_element, component=str(element_name), weight=1) dimension.add_hierarchy(hierarchy) update_or_create_dimension(tm1, dimension) dimension_name = "Employment" if tm1.dimensions.exists(dimension_name=dimension_name): dimension = tm1.dimensions.get(dimension_name=dimension_name) else: dimension = Dimension(name=dimension_name) hierarchy_name = dimension_name if hierarchy_name in dimension: hierarchy = dimension.get_hierarchy(hierarchy_name=hierarchy_name) else: hierarchy = Hierarchy(name=hierarchy_name, dimension_name=dimension_name) dimension.add_hierarchy(hierarchy) total_element = "Total " + dimension_name if total_element not in hierarchy.elements: hierarchy.add_element(element_name=total_element, element_type="Consolidated") employments = CaseAndSpaceInsensitiveSet() for loan in loans: employments.add(loan.emp_title) employments.add("None") for employment in employments: if employment and employment not in hierarchy.elements: employment = employment.strip() hierarchy.add_element(element_name=employment, element_type="Numeric") hierarchy.add_edge(parent=total_element, component=employment, weight=1) update_or_create_dimension(tm1, dimension) dimension_name = "Term" dimension = Dimension(name=dimension_name) hierarchy_name = dimension_name hierarchy = Hierarchy(name=hierarchy_name, dimension_name=dimension_name) total_element = "Total " + dimension_name hierarchy.add_element(element_name=total_element, element_type="Consolidated") for element_name in ("36 months", "60 months"): hierarchy.add_element(element_name=element_name, element_type="Numeric") hierarchy.add_edge(parent=total_element, component=element_name, weight=1) dimension.add_hierarchy(hierarchy) update_or_create_dimension(tm1, dimension) dimension_name = "Income" dimension = Dimension(name=dimension_name) hierarchy_name = dimension_name hierarchy = Hierarchy(name=hierarchy_name, dimension_name=dimension_name) total_element = "Total " + dimension_name hierarchy.add_element(element_name=total_element, element_type="Consolidated") for element_name in ("10000", "20000", "30000", "40000", "50000", "60000", "70000", "80000", "90000", "100000", "110000", "120000", "130000", "140000", "150000", "160000", "170000", "180000", "190000"): hierarchy.add_element(element_name=element_name, element_type="Numeric") hierarchy.add_edge(parent=total_element, component=element_name, weight=1) dimension.add_hierarchy(hierarchy) update_or_create_dimension(tm1, dimension) dimension_name = "Purpose" dimension = Dimension(name=dimension_name) hierarchy_name = dimension_name hierarchy = Hierarchy(name=hierarchy_name, dimension_name=dimension_name) total_element = "Total " + dimension_name hierarchy.add_element(element_name=total_element, element_type="Consolidated") for element_name in ("other", "debt_consolidation", "medical", "major_purchase", "home_improvement", "credit_card", "vacation", "house", "car", "small_business", "moving", "renewable_energy", "wedding", "educational"): hierarchy.add_element(element_name=element_name, element_type="Numeric") hierarchy.add_edge(parent=total_element, component=element_name, weight=1) dimension.add_hierarchy(hierarchy) update_or_create_dimension(tm1, dimension) dimension_name = "Loan Status" dimension = Dimension(name=dimension_name) hierarchy_name = dimension_name hierarchy = Hierarchy(name=hierarchy_name, dimension_name=dimension_name) total_element = "Total " + dimension_name hierarchy.add_element(element_name=total_element, element_type="Consolidated") for element_name in ("Current", "Fully Paid", "Late (31-120 days)", "Late (16-30 days)", "Charged Off", "In Grace Period", "Default"): hierarchy.add_element(element_name=element_name, element_type="Numeric") hierarchy.add_edge(parent=total_element, component=element_name, weight=1) dimension.add_hierarchy(hierarchy) update_or_create_dimension(tm1, dimension) dimension_name = "State" dimension = Dimension(name=dimension_name) hierarchy_name = dimension_name hierarchy = Hierarchy(name=hierarchy_name, dimension_name=dimension_name) total_element = "Total " + dimension_name hierarchy.add_element(element_name=total_element, element_type="Consolidated") states = CaseAndSpaceInsensitiveSet() for loan in loans: states.add(loan.addr_state) states.add("None") for state in states: if state: state = state.strip() hierarchy.add_element(element_name=state, element_type="Numeric") hierarchy.add_edge(parent=total_element, component=state, weight=1) dimension.add_hierarchy(hierarchy) update_or_create_dimension(tm1, dimension) dimension_name = "Home Ownership" dimension = Dimension(name=dimension_name) hierarchy_name = dimension_name hierarchy = Hierarchy(name=hierarchy_name, dimension_name=dimension_name) total_element = "Total " + dimension_name hierarchy.add_element(element_name=total_element, element_type="Consolidated") for element_name in ("Rent", "Own", "Mortgage", "Any", "None"): hierarchy.add_element(element_name=element_name, element_type="Numeric") hierarchy.add_edge(parent=total_element, component=element_name, weight=1) dimension.add_hierarchy(hierarchy) update_or_create_dimension(tm1, dimension) dimension_name = "Application Type" dimension = Dimension(name=dimension_name) hierarchy_name = dimension_name hierarchy = Hierarchy(name=hierarchy_name, dimension_name=dimension_name) total_element = "Total " + dimension_name hierarchy.add_element(element_name=total_element, element_type="Consolidated") for element_name in ("Individual", "Joint App"): hierarchy.add_element(element_name=element_name, element_type="Numeric") hierarchy.add_edge(parent=total_element, component=element_name, weight=1) dimension.add_hierarchy(hierarchy) update_or_create_dimension(tm1, dimension) dimension_name = "Income To Loan Ratio" dimension = Dimension(name=dimension_name) hierarchy_name = dimension_name hierarchy = Hierarchy(name=hierarchy_name, dimension_name=dimension_name) total_element = "Total " + dimension_name hierarchy.add_element(element_name=total_element, element_type="Consolidated") for counter in range(0, 100000, 1): dti = counter / 100 element_name = "%.2f" % dti hierarchy.add_element(element_name=element_name, element_type="Numeric") hierarchy.add_edge(parent=total_element, component=element_name, weight=1) dimension.add_hierarchy(hierarchy) update_or_create_dimension(tm1, dimension) dimension_name = "Delinquency Events" dimension = Dimension(name=dimension_name) hierarchy_name = dimension_name hierarchy = Hierarchy(name=hierarchy_name, dimension_name=dimension_name) total_element = "Total " + dimension_name hierarchy.add_element(element_name=total_element, element_type="Consolidated") for element_name in range(0, 51): hierarchy.add_element(element_name=str(element_name), element_type="Numeric") hierarchy.add_edge(parent=total_element, component=str(element_name), weight=1) dimension.add_hierarchy(hierarchy) update_or_create_dimension(tm1, dimension) dimension_name = " ".join([CUBE_NAME, "Measure"]) dimension = Dimension(name=dimension_name) hierarchy_name = dimension_name hierarchy = Hierarchy(name=hierarchy_name, dimension_name=dimension_name) for element_name in ("loan_amnt", "int_rate", "installment", "out_prncp", "total_pymnt", "last_pymnt_amnt", "total_pymnt_by_loan_amnt", "emp_length", "num_personal_inquiries", "inquiries_in_last_12m", "mths_since_last_delinq", "mths_since_recent_bc_dlq", "mths_since_recent_inq", "mths_since_recent_revol_delinq", "defaulted", "defaulted_or_delayed"): hierarchy.add_element(element_name=element_name, element_type="Numeric") for element_name in ("last_pymnt_d", ): hierarchy.add_element(element_name=element_name, element_type="String") hierarchy.add_element_attribute(name="Description", attribute_type="Alias") dimension.add_hierarchy(hierarchy) update_or_create_dimension(tm1, dimension) attributes = { ("loan_amnt", "Description"): "Listed amount of the loan", ("int_rate", "Description"): "Interest rate", ("installment", "Description"): "Monthly payment", ("out_prncp", "Description"): "Remaining outstanding amount", ("total_pymnt", "Description"): "Payments received to date", ("total_pymnt_by_loan_amnt", "Description"): "Total Payments devided by total Loan", ("last_pymnt_amnt", "Description"): "Last payment amount received", ("last_pymnt_d", "Description"): "Last month payment was received", ("defaulted", "Description"): "Loan is defaulted" } tm1.cubes.cells.write_values(cube_name="}ElementAttributes_" + dimension_name, cellset_as_dict=attributes)
Element(name='UK', element_type='Numeric'), Element(name='BE', element_type='Numeric') ] # create edge object edges = [ Edge(parent_name='Europe', component_name='CH', weight=1), Edge(parent_name='Europe', component_name='UK', weight=1), Edge(parent_name='Europe', component_name='BE', weight=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.create_dimension(d)