def __init__( self, name: str, dimension_name: str, elements: Optional[Iterable['Element']] = None, element_attributes: Optional[Iterable['ElementAttribute']] = None, edges: Optional['Dict'] = None, subsets: Optional[Iterable[str]] = None, structure: Optional[int] = None, default_member: Optional[str] = None): self._name = name self._dimension_name = None self.dimension_name = dimension_name self._elements = CaseAndSpaceInsensitiveDict() if elements: for elem in elements: self._elements[elem.name] = elem self._element_attributes = list( element_attributes) if element_attributes else [] self._edges = CaseAndSpaceInsensitiveTuplesDict( edges) if edges else CaseAndSpaceInsensitiveTuplesDict() self._subsets = list(subsets) if subsets else [] # balanced is true, false or None (in versions < TM1 11) self._balanced = False if not structure else structure == 0 self._default_member = default_member
def update_element_attributes(self, hierarchy: Hierarchy, **kwargs): """ Update the elementattributes of a hierarchy :param hierarchy: Instance of TM1py.Hierarchy :return: """ # get existing attributes first existing_element_attributes = self.elements.get_element_attributes( dimension_name=hierarchy.dimension_name, hierarchy_name=hierarchy.name, **kwargs) existing_element_attributes = CaseAndSpaceInsensitiveDict( {ea.name: ea for ea in existing_element_attributes}) attributes_to_create = list() attributes_to_delete = list() attributes_to_update = list() for element_attribute in hierarchy.element_attributes: if element_attribute.name not in existing_element_attributes: attributes_to_create.append(element_attribute) continue existing_element_attribute = existing_element_attributes[ element_attribute.name] if not existing_element_attribute.attribute_type == element_attribute.attribute_type: attributes_to_update.append(element_attribute) continue for existing_element_attribute in existing_element_attributes: if existing_element_attribute not in CaseAndSpaceInsensitiveSet( [ea.name for ea in hierarchy.element_attributes]): attributes_to_delete.append(existing_element_attribute) for element_attribute in attributes_to_create: self.elements.create_element_attribute( dimension_name=hierarchy.dimension_name, hierarchy_name=hierarchy.name, element_attribute=element_attribute, **kwargs) for element_attribute in attributes_to_delete: self.elements.delete_element_attribute( dimension_name=hierarchy.dimension_name, hierarchy_name=hierarchy.name, element_attribute=element_attribute, **kwargs) for element_attribute in attributes_to_update: self.elements.delete_element_attribute( dimension_name=hierarchy.dimension_name, hierarchy_name=hierarchy.name, element_attribute=element_attribute.name, **kwargs) self.elements.create_element_attribute( dimension_name=hierarchy.dimension_name, hierarchy_name=hierarchy.name, element_attribute=element_attribute, **kwargs)
def test_ne(self): _map = CaseAndSpaceInsensitiveDict() _map["key 1"] = "wrong" _map["key 2"] = "value2" _map["key3"] = "value3" self.assertNotEqual(self.map, _map) _map = CaseAndSpaceInsensitiveDict() _map["key1"] = "value1" _map["key 2"] = "wrong" _map["key3"] = "value3" self.assertNotEqual(self.map, _map) _map = CaseAndSpaceInsensitiveDict() _map["key1"] = "value1" _map["key2"] = "value2" _map["key4"] = "value4" self.assertNotEqual(self.map, _map)
def __init__(self, name, dimension_name, elements=None, element_attributes=None, edges=None, subsets=None, structure=None, default_member=None): self._name = name self._dimension_name = dimension_name self._elements = CaseAndSpaceInsensitiveDict() if elements: for elem in elements: self._elements[elem.name] = elem self._element_attributes = element_attributes if element_attributes else [] self._edges = CaseAndSpaceInsensitiveTuplesDict(edges) if edges else CaseAndSpaceInsensitiveTuplesDict() self._subsets = subsets if subsets else [] # balanced is true, false or None (in versions < TM1 11) self._balanced = structure if not structure else structure == 0 self._default_member = default_member
def __init__(self, name, dimension_name, elements=None, element_attributes=None, edges=None, subsets=None, default_member=None): self._name = name self._dimension_name = dimension_name self._elements = CaseAndSpaceInsensitiveDict() if elements: for elem in elements: self._elements[elem.name] = elem self._element_attributes = element_attributes if element_attributes else [] self._edges = edges if edges else CaseAndSpaceInsensitiveTuplesDict() self._subsets = subsets if subsets else [] self._default_member = default_member
from TM1py import TM1Service from TM1py.Utils.Utils import CaseAndSpaceInsensitiveDict import methods from utils import set_current_directory METHODS = CaseAndSpaceInsensitiveDict({ "IRR": methods.irr, "NPV": methods.npv, "STDEV": methods.stdev, "STDEV_P": methods.stdev_p, "FV": methods.fv, "FV_SCHEDULE": methods.fv_schedule, "PV": methods.pv, "XNPV": methods.xnpv, "PMT": methods.pmt, "PPMT": methods.ppmt, "MIRR": methods.mirr, "XIRR": methods.xirr, "NPER": methods.nper, "RATE": methods.rate, "EFFECT": methods.effect, "NOMINAL": methods.nominal, "SLN": methods.sln }) APP_NAME = "CubeCalc" CURRENT_DIRECTORY = set_current_directory() LOGFILE = os.path.join(CURRENT_DIRECTORY, APP_NAME + ".log") CONFIG = os.path.join(CURRENT_DIRECTORY, "config.ini")
def get_message_log_entries(self, reverse: bool = True, since: datetime = None, until: datetime = None, top: int = None, logger: str = None, level: str = None, msg_contains: Iterable = None, msg_contains_operator: str = 'and', **kwargs) -> Dict: """ :param reverse: Boolean :param since: of type datetime. If it doesn't have tz information, UTC is assumed. :param until: of type datetime. If it doesn't have tz information, UTC is assumed. :param top: Integer :param logger: string, eg TM1.Server, TM1.Chore, TM1.Mdx.Interface, TM1.Process :param level: string, ERROR, WARNING, INFO, DEBUG, UNKNOWN :param msg_contains: iterable, find substring in log message; list of substrings will be queried as AND statement :param msg_contains_operator: 'and' or 'or' :param kwargs: :return: Dict of server log """ msg_contains_operator = msg_contains_operator.strip().lower() if msg_contains_operator not in ("and", "or"): raise ValueError( "'msg_contains_operator' must be either 'AND' or 'OR'") reverse = 'desc' if reverse else 'asc' url = '/api/v1/MessageLogEntries?$orderby=TimeStamp {}'.format(reverse) if since or until or logger or level or msg_contains: log_filters = [] if since: # If since doesn't have tz information, UTC is assumed if not since.tzinfo: since = self.utc_localize_time(since) log_filters.append( format_url("TimeStamp ge {}", since.strftime("%Y-%m-%dT%H:%M:%SZ"))) if until: # If until doesn't have tz information, UTC is assumed if not until.tzinfo: until = self.utc_localize_time(until) log_filters.append( format_url("TimeStamp le {}", until.strftime("%Y-%m-%dT%H:%M:%SZ"))) if logger: log_filters.append(format_url("Logger eq '{}'", logger)) if level: level_dict = CaseAndSpaceInsensitiveDict({ 'ERROR': 1, 'WARNING': 2, 'INFO': 3, 'DEBUG': 4, 'UNKNOWN': 5 }) level_index = level_dict.get(level) if level_index: log_filters.append("Level eq {}".format(level_index)) if msg_contains: if isinstance(msg_contains, str): log_filters.append( format_url("contains(toupper(Message),toupper('{}'))", msg_contains)) else: msg_filters = [ format_url("contains(toupper(Message),toupper('{}'))", wildcard) for wildcard in msg_contains ] log_filters.append("({})".format( f" {msg_contains_operator} ".join(msg_filters))) url += "&$filter={}".format(" and ".join(log_filters)) if top: url += '&$top={}'.format(top) response = self._rest.GET(url, **kwargs) return response.json()['value']
def remove_all_elements(self): self._elements = CaseAndSpaceInsensitiveDict() self.remove_all_edges()
def test_eq_case_and_space_insensitive(self): _map = CaseAndSpaceInsensitiveDict() _map["key1"] = "value1" _map["KEY2"] = "value2" _map["K e Y 3"] = "value3" self.assertEqual(self.map, _map)
def test_eq(self): _map = CaseAndSpaceInsensitiveDict() _map["key1"] = "value1" _map["key2"] = "value2" _map["key3"] = "value3" self.assertEqual(self.map, _map)
def setUp(cls): cls.map = CaseAndSpaceInsensitiveDict() cls.map["key1"] = "value1" cls.map["key2"] = "value2" cls.map["key3"] = "value3"
METHODS = CaseAndSpaceInsensitiveDict({ "IRR": methods.irr, "NPV": methods.npv, "STDEV": methods.stdev, "STDEV_P": methods.stdev_p, "FV": methods.fv, "FV_SCHEDULE": methods.fv_schedule, "PV": methods.pv, "XNPV": methods.xnpv, "PMT": methods.pmt, "PPMT": methods.ppmt, "MIRR": methods.mirr, "XIRR": methods.xirr, "NPER": methods.nper, "RATE": methods.rate, "EFFECT": methods.effect, "NOMINAL": methods.nominal, "SLN": methods.sln, "MEAN": methods.mean, "SEM": methods.sem, "MEDIAN": methods.median, "MODE": methods.mode, "VAR": methods.var, "KURT": methods.kurt, "SKEW": methods.skew, "RNG": methods.rng, "MIN": methods.min_, "MAX": methods.max_, "SUM": methods.sum_, "COUNT": methods.count })