def TM(analyzer,M): rank=oms.newMap('BST',comparefunction=comparerMap) rankp=oms.newMap('BST',comparefunction=comparerMap) sancocho=om.valueSet(analyzer["indice"]) for papa in sancocho: if oms.contains(rank,papa["company"])==True: new=oms.get(rank,papa["company"]) nueva=lt.newList(new.values()) lt.addLast(nueva,papa["taxi_id"]) oms.put(rank,str(new.keys()),nueva) if papa["company"]=="" and oms.contains(rank,"Independent Owner")==True: news=oms.get(rank,"Independent Owner") nuevas=lt.newList(news.values()) lt.addLast(nuevas,papa["taxi_id"]) oms.put(rank,str(news.keys()),nuevas) else: if papa["company"]=="": oms.put(rank,"Independent Owner",1) oms.put(rank,papa["company"],1) for com in list(rank): oms.put(rankp,lt.size(set(list(com.values()))),str(com.keys())) ranki=lt.newList() for puesto in range(M): p=oms.maxKey(rankp) lt.addLast(ranki,dict(om.keySet(rank)[om.valueSet(rank).index(p)],p)) oms.deleteMax(rankp) return ranki
def TN(analyzer,N): rank=oms.newMap('BST',comparefunction=comparerMap) rankp=oms.newMap('BST',comparefunction=comparerMap) sancocho=om.valueSet(analyzer["indice"]) for papa in sancocho: if oms.contains(rank,papa["company"])==True: new=oms.get(rank,papa["company"]) nueva=int(new.values())+1 oms.put(rank,str(new.keys()),nueva) if papa["company"]=="" and oms.contains(rank,"Independent Owner")==True: news=oms.get(rank,"Independent Owner") nuevas=int(news.values())+1 oms.put(rank,str(news.keys()),nuevas) else: if papa["company"]=="": oms.put(rank,"Independent Owner",1) oms.put(rank,papa["company"],1) for com in list(rank): oms.put(rankp,int(com.values()),str(com.keys())) rankesito=lt.newList() for puesto in range(N): p=oms.maxKey(rankp) lt.addLast(rankesito,dict(list(rank.keys())[list(rank.values()).index(p)],p)) oms.deleteMax(rankp) return rankesito
def newAnalyzer(tipo): """ Inicializa el analizador Crea una lista vacia para guardar todos los crimenes Se crean indices (Maps) por los siguientes criterios: -Fechas Retorna el analizador inicializado. """ analyzer = { 'numAccidents': 0, 'dateIndex': om.newMap(omaptype=tipo, comparefunction=compareOmpLst), 'timeIndex': om.newMap(omaptype=tipo, comparefunction=compareOmpLst), 'ZoneIndexLatLng': om.newMap(omaptype=tipo, comparefunction=compareOmpLst) } return analyzer
def newMap(omaptype='RBT', comparefunction=None): """ Crea una tabla de simbolos ordenada. Args: maptype: El tipo de map ordenado a utilizar 'BST' o 'RBT' Returns: La tabla de símbolos ordenada sin elementos Raises: Exception """ return om.newMap(omaptype, comparefunction)