def newInit(): Inite = { "mapa_companies": None, "Taxis sin repetir": None, "mapa_fecha": None, "Graph": None, } Inite["Inicio"] = m.newMap(maptype="PROBING", comparefunction=compareStationsv2) Inite["mapa_fecha"] = om.newMap("BST", comparefunction=compareStations) Inite["mapa_companies"] = m.newMap(maptype="PROBING", comparefunction=compareStationsv2) Inite["Graph"] = gr.newGraph( datastructure="ADJ_LIST", directed=True, size=1000, comparefunction=compareStationsv2, ) Inite["Taxis sin repetir"] = [] return Inite
def new_graph(): citibike = {} citibike["graph"] = gr.newGraph(datastructure='ADJ_LIST', directed=True, size=1000, comparefunction=compareStations) citibike['Estaciones'] = m.newMap(numelements=2107, maptype='PROBING', comparefunction=compararEstaciones) return (citibike)
def initAnalyzer(): analyzer = { 'connections': None, 'countries': None, 'landingpoints': None, 'countrypoints' : None } analyzer['countries'] = mp.newMap(numelements=236, maptype='PROBING') analyzer['landingpoints'] = mp.newMap(numelements=2000, maptype='PROBING') analyzer['countrypoints'] = mp.newMap(numelements=236, maptype='PROBING') analyzer['connections'] = gr.newGraph(datastructure='ADJ_LIST', directed=True, size=5000, comparefunction=cmpVertex) return analyzer
def dfsVertexCicles(search, graph, vertex): """ Funcion auxiliar para calcular un recorrido DFS Args: search: Estructura para almacenar el recorrido vertex: Vertice de inicio del recorrido. Returns: Una estructura para determinar los vertices conectados a source Raises: Exception """ try: search = { 'source': source, 'visited': None, "camino":{} } search['visited'] = map.newMap(numelements=g.numVertices(graph), maptype='PROBING', comparefunction=graph['comparefunction'] ) map.put(search['visited'], source, {'marked': True, 'edgeTo': None}) dfsVertex2(search,graph,source,time) return search except Exception as exp: error.reraise(exp, 'dfs:DFS') ruta = 0 adjlst = g.adjacents(graph, vertex) adjslstiter = it.newIterator(adjlst) while (it.hasNext(adjslstiter)): w = it.next(adjslstiter) visited = map.get(search['visited'], w) if visited == vertex: ruta += 1 map.put(search['cicles'], str(ruta), search['visited']) if visited is None: map.put(search['visited'], w, {'marked': True, 'edgeTo': vertex}) dfsVertex(search, graph, w) return search except Exception as exp: error.reraise(exp, 'dfs:dfsVertex')
def newCatalog(): catalog = { 'details': None, 'casting': None, 'compañias': None, } catalog['details'] = lt.newList('SINGLE_LINKED', CompareIdsMovies) catalog['compañias'] = mp.newMap(329045, maptype='CHAINING', loadfactor=0.4, comparefunction=compareCompanyByName) return catalog
def newCatalog(): catalog = { 'videos': None, 'categoryVideos': None, 'categoryNames': None, "countryVideos": None } catalog["videos"] = lt.newList('SINGLE_LINKED', cmpVideoIds) catalog["categoryVideos"] = mp.newMap(67, maptype='PROBING', loadfactor=0.5, comparefunction=cmpCategoryIds) catalog["categoryNames"] = lt.newList(datastructure='ARRAY_LIST') catalog["countryVideos"] = mp.newMap(23, maptype="PROBING", loadfactor=0.5, comparefunction=cmpMapCountries) return catalog
def newCatalog(): catalog={"videos": None, "videos-id": None, "categorias": None, "category-id": None, "country": None} catalog["videos"]=lt.newList(datastructure="ARRAY_LIST") catalog["videos-id"]=mp.newMap(10000, maptype="CHAINING", loadfactor=4.0) catalog["categorias"]=mp.newMap(37, maptype="PROBING", loadfactor=0.5) catalog["category-id"]=mp.newMap(37, maptype="CHAINING", loadfactor=4.0) catalog["country"]=mp.newMap(20, maptype="PROBING", loadfactor=0.5) return catalog
def state_accidents(analyzer, fechaInicial, fechaFinal): llaves = om.keys(analyzer['dateIndex'], fechaInicial, fechaFinal) cant_llaves = lt.size(llaves) tamanio = lt.size( om.values(analyzer['dateIndex'], fechaInicial, fechaFinal)) i = 1 estados = m.newMap(numelements=0, maptype='CHAINING', loadfactor=0.5, comparefunction=comparar_estados) if (lt.isPresent(llaves, fechaFinal) == 0 or lt.isPresent(llaves, fechaInicial) == 0): return None else: while i <= cant_llaves: llave = lt.getElement(llaves, i) tree = om.get(analyzer['dateIndex'], llave) stateIndex = tree['value']['stateIndex'] llaves_stateIndex = m.keySet(stateIndex) tamanio_llaves = lt.size(llaves_stateIndex) j = 1 while j <= tamanio_llaves: estado = lt.getElement(llaves_stateIndex, j) stat = m.get(stateIndex, estado) exist_state = m.contains(estados, estado) if not exist_state: m.put(estados, estado, 0) cant = m.get(estados, estado) cant = cant['value'] cant += tamanio m.put(estados, estado, cant) j += 1 i += 1 z = 1 mayor = 0 stat = ' ' llaves_estados = m.keySet(estados) while z <= lt.size(llaves_estados): estadod = lt.getElement(llaves_estados, z) valor = m.get(estados, estadod) valor = valor['value'] if (valor > mayor): mayor = valor stat = estadod z += 1 return stat
def setup_genres(): genre_map = mp.newMap() mp.put(genre_map, "Reggae", (60, 90)) mp.put(genre_map, "Down-tempo", (70, 100)) mp.put(genre_map, "Chill-out", (90, 120)) mp.put(genre_map, "Hip-Hop", (85, 115)) mp.put(genre_map, "Jazz and Funk", (120, 125)) mp.put(genre_map, "Pop", (100, 130)) mp.put(genre_map, "R&B", (60, 80)) mp.put(genre_map, "Rock", (110, 140)) mp.put(genre_map, "Metal", (100, 160)) return genre_map
def newHourEntry(crime): entry = { "hora_del_accidente": None, "severidades_reportadas": None, "Date": None } entry["hora_del_accidente"] = m.newMap(numelements=30, maptype='PROBING', comparefunction=compareSeverity) entry["severidades_reportadas"] = [] return entry
def create_cable_map(self): self.cable_bandwith = mp.newMap(numelements=3268) cable_it = al_it.newIterator(self.connections_list) i = 1 while al_it.hasNext(cable_it): cable = al_it.next(cable_it) self.add_country_cable(cable, i) i += 1 cable_it = ll_it.newIterator(mp.keySet(self.cable_bandwith)) while ll_it.hasNext(cable_it): cable = ll_it.next(cable_it) self.cable_map_to_list(cable)
def newCatalog(): """ Inicializa el catálogo de peliculas Crea una lista vacia para guardar todas las peliculas Se crean indices (Maps) por los siguientes criterios: Título de las películas Fecha de estreno Promedio votacion Numero de votos Idioma Retorna el catalogo inicializado. """ catalog = { 'movies1': None, 'movies2': None, 'moviesID1': None, 'moviesID2': None, 'production_companies': None } catalog['movies1'] = lt.newList('ARRAY_LIST', compareMovieIds) catalog['movies2'] = lt.newList('ARRAY_LIST', compareMovieIds) catalog['moviesID1'] = mp.newMap(2000, maptype='PROBING', loadfactor=0.5, comparefunction=compareMapMovieIds) catalog['moviesID2'] = mp.newMap(2000, maptype='PROBING', loadfactor=0.5, comparefunction=compareMapMovieIds) catalog['production_companies'] = mp.newMap( 2000, maptype='PROBING', loadfactor=0.5, comparefunction=compareProductionCompanies) catalog['directors'] = mp.newMap(2000, maptype='PROBING', loadfactor=0.5, comparefunction=compareDirectors) catalog['actors'] = mp.newMap(2000, maptype='PROBING', loadfactor=0.5, comparefunction=compareActors) catalog['genres'] = mp.newMap(2000, maptype='PROBING', loadfactor=0.5, comparefunction=compareGenres) catalog['country'] = mp.newMap(2000, maptype='PROBING', loadfactor=0.5, comparefunction=compareCountry) return catalog
def iniCatalogo(): catalogo = {"movies": None, "production_company": None} catalogo["movies"] = mp.newMap(numelements=PARAMS["numelements"], maptype=PARAMS["maptype"], loadfactor=PARAMS["loadfactor"], comparefunction=Comp.compareMoviesIds) catalogo["production_company"] = mp.newMap( numelements=PARAMS["numelements"], maptype=PARAMS["maptype"], loadfactor=PARAMS["loadfactor"], comparefunction=Comp.compareProductionCompanies) catalogo["director"] = mp.newMap(numelements=PARAMS["numelements"], maptype=PARAMS["maptype"], loadfactor=PARAMS["loadfactor"], comparefunction=Comp.compareActors) catalogo["actor"] = mp.newMap(numelements=PARAMS["numelements"], maptype=PARAMS["maptype"], loadfactor=PARAMS["loadfactor"], comparefunction=Comp.compareActors) catalogo["genre"] = mp.newMap(numelements=PARAMS["numelements"], maptype=PARAMS["maptype"], loadfactor=PARAMS["loadfactor"], comparefunction=Comp.compareGenres) catalogo["country"] = mp.newMap(numelements=PARAMS["numelements"], maptype=PARAMS["maptype"], loadfactor=PARAMS["loadfactor"], comparefunction=Comp.compareCountries) return catalogo
def unique_tracks(catalog, genero, lista_mapas_reps): tracks = mp.newMap(maptype='PROBING') mapa_generos = catalog['Generos'] limites = me.getValue(mp.get(mapa_generos, genero))[0] lim_inf = limites[0] lim_sup = limites[1] vaders = catalog['Hashtags'] #contador_prueba = 0 for mapa_reps in lt.iterator(lista_mapas_reps): for rep in lt.iterator(mp.valueSet(mapa_reps)): tempo_rep = rep['tempo'] if lim_inf <= tempo_rep and tempo_rep <= lim_sup: track_id = rep['track_id'] # print('track_id:') # print(track_id) if not mp.contains(tracks, track_id): hashtags_track = mp.newMap(loadfactor=4.0) for hashtag in lt.iterator(rep['hashtags']): if mp.contains(vaders, hashtag): vader_hashtag = me.getValue(mp.get( vaders, hashtag)) else: vader_hashtag = -1 mp.put(hashtags_track, hashtag, vader_hashtag) mp.put(tracks, track_id, hashtags_track) #contador_prueba = contador_prueba + 1 else: hashtags_track = me.getValue(mp.get(tracks, track_id)) for hashtag in lt.iterator(rep['hashtags']): if mp.contains(vaders, hashtag): vader_hashtag = me.getValue(mp.get( vaders, hashtag)) else: vader_hashtag = -1 mp.put(hashtags_track, hashtag, vader_hashtag) #print(contador_prueba) return tracks
def newAnalyzer(): """ 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 = { 'crimes': None, 'dateIndex': None, 'autors': None, 'instrumentalness': None, 'tempo': None, 'liveness': None, 'speechiness': None, 'danceability': None, 'valence': None, 'loudness': None, 'acousticness': None, 'energy': None, 'generos': None } analyzer['crimes'] = lt.newList('ARRAY_LIST', compareIds) analyzer['ids'] = lt.newList('ARRAY_LIST', compareIds) analyzer['dateIndex'] = om.newMap(omaptype='RBT', comparefunction=compareDates) analyzer['autors'] = om.newMap(omaptype='RBT', comparefunction=compareAUTOR) analyzer['instrumentalness'] = om.newMap(omaptype='RBT', comparefunction=compareInt) analyzer['tempo'] = om.newMap(omaptype='RBT', comparefunction=compareInt) analyzer['liveness'] = om.newMap(omaptype='RBT', comparefunction=compareInt) analyzer['speechiness'] = om.newMap(omaptype='RBT', comparefunction=compareInt) analyzer['danceability'] = om.newMap(omaptype='RBT', comparefunction=compareInt) analyzer['valence'] = om.newMap(omaptype='RBT', comparefunction=compareInt) analyzer['loudness'] = om.newMap(omaptype='RBT', comparefunction=compareInt) analyzer['acousticness'] = om.newMap(omaptype='RBT', comparefunction=compareInt) analyzer['energy'] = om.newMap(omaptype='RBT', comparefunction=compareInt) analyzer['generos'] = m.newMap(11, maptype='CHAINING', loadfactor=4.0) return analyzer
def req4(catalog): grafo = catalog["connections"] initSearch = prim.initSearch(grafo) search = prim.prim(grafo, initSearch, "Washington, D.C.") mst = gr.newGraph(datastructure="ADJ_LIST", size=3000, directed=False, comparefunction=compareIds) landing_points = mp.newMap(numelements=1249, maptype="PROBING", loadfactor=0.3) vertices = mp.keySet(search["marked"]) for vertice in lt.iterator(vertices): lp = vertice.split("|")[0] mp.put(landing_points, lp, None) gr.insertVertex(mst, vertice) listaArcos = mp.keySet(search["edgeTo"]) pesoTotal = 0 for verticeB in lt.iterator(listaArcos): verticeA = mp.get(search["edgeTo"], verticeB)["value"]["vertexA"] peso = mp.get(search["edgeTo"], verticeB)["value"]["weight"] gr.addEdge(mst, verticeA, verticeB, peso) pesoTotal += peso dfsSearch = dfs.DepthFirstSearch(mst, "Washington, D.C.") maxArcos = 0 arcos = None for vertice in lt.iterator(vertices): pathTo = dfs.pathTo(dfsSearch, vertice) if pathTo: numArcos = lt.size(pathTo) if numArcos > maxArcos: maxArcos = numArcos arcos = pathTo numLanding_points = gr.numEdges(mst) + 1 return numLanding_points, pesoTotal, arcos
def getHashtags(catalog, lstGenre): lstOfElements = lt.newList(datastructure='SINGLE_LINKED') localHash = mp.newMap(numelements=40000, prime=20011, maptype="CHAINING", loadfactor=2.0) for rep in lt.iterator(lstGenre): existsEntry = mp.get(localHash, (rep[0])['track_id']) if existsEntry == None: dataentry = lt.newList("SINGLE_LINKED") mp.put(localHash, (rep[0])['track_id'], dataentry) else: dataentry = me.getValue(existsEntry) if lt.isPresent(dataentry, rep[1]) == 0: lt.addLast(dataentry, rep[1]) for element in lt.iterator(lstGenre): catalogForElement = {'numHashtags': 0, 'avg': 0, 'id': None} sumOfVader = 0 counterOfValidVaderValues = 0 track = (element[0])['track_id'] listOfHashtags = me.getValue(mp.get(localHash, track)) listOfHashtags = eliminateRepeated(listOfHashtags) numHashtags = lt.size(listOfHashtags) for hashtag in lt.iterator(listOfHashtags): feelRep = mp.get(catalog['feelings'], hashtag) if feelRep != None: feelRep = me.getValue(feelRep) if feelRep != None: if feelRep['vader_avg'] != '': vaderAvg = float(feelRep['vader_avg']) sumOfVader = sumOfVader + vaderAvg counterOfValidVaderValues = counterOfValidVaderValues + 1 if counterOfValidVaderValues != 0: catalogForElement['avg'] = (sumOfVader / counterOfValidVaderValues) else: catalogForElement[ 'avg'] = 'Ninguno de los hashtags tiene vader avg' catalogForElement['id'] = track catalogForElement['numHashtags'] = numHashtags lt.addLast(lstOfElements, catalogForElement) newList = merge.sort(lstOfElements, cmpVideosByHash) return newList
def ListReps_to_HashPistasUnicas(lista_listas_reps): hashTable = mp.newMap(maptype='PROBING') for lista_reps in lt.iterator(lista_listas_reps): for reproduccion in lt.iterator(lista_reps): track_id = reproduccion['track_id'] valor_agregar = { 'artist_id': reproduccion['artist_id'], 'energy': reproduccion['energy'], 'danceability': reproduccion['danceability'], 'track_id': track_id } mp.put(hashTable, track_id, valor_agregar) return hashTable
def orderednums(catalog, tuplas): mapafinal = mp.newMap(maptype="PROBING", loadfactor=0.5) tracksmap = mp.newMap(maptype="PROBING", loadfactor=0.5) i = it.newIterator(tuplas) while it.hasNext(i): tupla = it.next(i) track = tupla[0] mp.put(tracksmap, track, None) prom = promedio(catalog, track) if prom != None: num = prom[0] par = mp.get(mapafinal, num) tup = (track, prom[1]) if par != None: lista = me.getValue(par) lt.addLast(lista, tup) else: lista = lt.newList(datastructure="ARRAY_LIST") lt.addLast(lista, tup) mp.put(mapafinal, num, lista) return mapafinal, tracksmap
def newAnalyzer(): """ Inicializa el analizador Retorna el analizador inicializado. """ analyzer = { 'events': None, 'artists': None, 'tracks': None, 'instrumentalness': None, 'acousticness': None, 'liveness': None, 'speechiness': None, 'energy': None, 'danceability': None, 'valence': None, 'tempo': None, 'created_at': None, 'hashtags': None, 'vaders': None } analyzer['events'] = lt.newList(datastructure='LINKED_LIST', cmpfunction=compareIds) analyzer['artists'] = mp.newMap(maptype='PROBING') analyzer['tracks'] = om.newMap(omaptype='RBT') analyzer['instrumentalness'] = om.newMap(omaptype='RBT') analyzer['acousticness'] = om.newMap(omaptype='RBT') analyzer['liveness'] = om.newMap(omaptype='RBT') analyzer['speechiness'] = om.newMap(omaptype='RBT') analyzer['energy'] = om.newMap(omaptype='RBT') analyzer['danceability'] = om.newMap(omaptype='RBT') analyzer['valence'] = om.newMap(omaptype='RBT') analyzer['tempo'] = om.newMap(omaptype='RBT') analyzer['created_at'] = om.newMap(omaptype='RBT') analyzer['hashtag_vader'] = mp.newMap(maptype='PROBING') # analyzer['vaders'] = mp.newMap(maptype='PROBING') return analyzer
def getVaderByHashtag(map, mapHashtag, analyzer): """ Retorna el vader promedio usando el hashtag """ trackHashMap = mp.newMap(maptype='PROBING') keys = mp.keySet(map) keysHash = mp.keySet(mapHashtag) for key in lt.iterator(keys): for keyHash in lt.iterator(keysHash): if key == keyHash: entry0 = mp.get(mapHashtag, keyHash) value0 = me.getValue(entry0) entry = mp.get(trackHashMap, key) if entry is None: value = value0 mp.put(trackHashMap, key, value) else: value = me.getValue(entry) keysMap = mp.keySet(trackHashMap) hashtagVader = mp.newMap(maptype='PROBING') for key in lt.iterator(keysMap): average = 0 size = 0 entry1 = mp.get(trackHashMap, key) value1 = me.getValue(entry1) for hashtag in lt.iterator(value1): size = lt.size(value1) entry2 = mp.get(analyzer['sentiment_value'], hashtag) if entry2 != None: value2 = me.getValue(entry2) if value2 == "": average += 0 else: average += float(value2) rValue = (size, average / size) mp.put(hashtagVader, key, rValue) return hashtagVader
def createAgesMap(lstAges): """ Se crea una lista donde cada posicion va a representar un rango de edad y crea un mapa para almacenar las rutas """ for i in range(0, 7): age_entry = m.newMap(1000, maptype='CHAINING', loadfactor=5, comparefunction=compareNameInEntry) lt.addLast(lstAges, age_entry) return lstAges
def dfscircular(graph, source, sc): try: search = {'source': source, 'visited': None, 'cycles': None} search['visited'] = m.newMap(numelements=gr.numVertices(graph), maptype='PROBING', comparefunction=graph['comparefunction']) search['cycles'] = lt.newList() m.put(search['visited'], source, {'marked': True, 'edgeTo': None}) dfsVertexc(search, graph, source, source, sc) return search except Exception as exp: error.reraise(exp, 'dfs:DFS')
def count_artists_2(rango, reproducciones) -> int: artists_ids = mp.newMap(numelements=reproducciones) rango_it = ll_it.newIterator(rango) while ll_it.hasNext(rango_it): mp.put(artists_ids, ll_it.next(rango_it), 1) artist_list = lt.newList() artist_full_list = mp.keySet(artists_ids) iterator = ll_it.newIterator(artist_full_list) for i in range(0, 10): if not ll_it.hasNext(iterator): break lt.addLast(artist_list, ll_it.next(iterator)) return mp.size(artists_ids), artist_list
def severities(lst): severities=m.newMap(5, maptype='CHAINING', loadfactor=0.7, comparefunction=compareSeverities) iterator=it.newIterator(lst) while it.hasNext(iterator): date=it.next(iterator) it2=it.newIterator(date["lstaccidents"]) while it.hasNext(it2): accident=it.next(it2) addSeverity(severities,accident) return(severities)
def ReqDos(catalog, country): videitos = mp.get(catalog["videos-pais"], country) #print(mp.valueSet(catalog["videos-pais"])) #print(videitos) videillos = me.getValue(videitos)["videos"] ceteras = mp.newMap(numelements=500, maptype="CHAINING", loadfactor=4.0) dickss = mp.newMap(numelements=500, maptype="CHAINING", loadfactor=4.0) iterator = it.newIterator(videillos) while it.hasNext(iterator): tierra = it.next(iterator) if mp.contains(ceteras,tierra['title']): pareja = mp.get(ceteras,tierra['title']) valor = me.getValue(pareja) + 1 mp.put(ceteras,tierra["title"],valor) else: mp.put(ceteras,tierra["title"],1) mp.put(dickss,tierra["title"],tierra) k = None mx = -1 varx = mp.keySet(ceteras) itr = varx["first"] if itr == None: return None while itr: element = itr["info"] cnt = mp.get(ceteras, element) cnts = me.getValue(cnt) if cnts > mx: mx = cnts k = element itr = itr["next"] zzz = mp.get(dickss,k) b = me.getValue(zzz) result = {'Title': b["title"], 'Channel_title': b['channel_title'], 'Country': country, 'Número de días': mx} return result
def newCatalog(): catalog = { 'videos': None, 'country': None, 'category': None, 'categories': None } catalog['videos'] = lt.newList('ARRAY_LIST') catalog['category'] = mp.newMap(50, maptype='PROBING', loadfactor=0.5, comparefunction=cmpCategoryNames) catalog['country'] = mp.newMap(10, maptype='PROBING', loadfactor=0.5, comparefunction=cmpVideosCountry) catalog['categories'] = lt.newList('ARRAY_LIST') return catalog
def addHashByTrack(analyzer, track): mapa = analyzer['#ByTrack'] key = track['track_id'] entry = mp.get(mapa, key) if entry is not None: mapa_1 = me.getValue(entry) mp.put(mapa_1, track['hashtag'].lower(), 0) mp.put(mapa, key, mapa_1) else: mapa_1 = mp.newMap(maptype='PROBING', comparefunction=cmpByCarac) mp.put(mapa_1, track['hashtag'].lower(), 0) mp.put(mapa, key, mapa_1) return None
def newCatalog(): catalogo = { "viajes": None, "viajesId": None, "taxisIds": None, "companias": None } catalogo['viajes'] = lt.newList('SINGLE_LINKED', compareviajesByName) catalogo["viajesIds"] = mp.newMap(200, maptype='CHAINING', loadfactor=0.4, comparefunction=compareviajesIds) catalogo["taxisIds"] = mp.newMap(200, maptype='CHAINING', loadfactor=0.4, comparefunction=compareviajesIds) catalogo["companias"] = mp.newMap(200, maptype='CHAINING', loadfactor=0.4, comparefunction=compareviajesIds) return catalogo
def analyzer(): analyzer = {"index": None, "graph": None} analyzer["index"] = m.newMap(numelements=1000, prime=109345121, maptype="CHAINING", loadfactor=1.0, comparefunction=None) analyzer["graph"] = gr.newGraph(datastructure='ADJ_LIST', directed=True, size=1000, comparefunction=comparer) return analyzer