def requerimiento4(info, nom1, nom2, nom3, nom4, des1, des2): gene1 = tablageneros(nom1) llave = mp.get(gene1, nom1) #Da la llave y el valor de la tabla de hash valor = me.getValue(llave) # El valor de la llave del genero rango1 = om.values(info["generos"], valor[0], valor[1]) diccionario = mp.newMap() diccionarionuevo = mp.newMap() iterador = it.newIterator(rango1) suma1 = 0 while it.hasNext(iterador): actu = it.next(iterador) suma1 += lt.size(actu) iterardentro = it.newIterator(actu) while it.hasNext(iterardentro): actual = it.next(iterardentro) if mp.contains(diccionario, actual["tempo"]): ola = mp.get(diccionario, actual["tempo"]) listo = me.getValue(ola) lt.addLast(listo, actual) else: listo = lt.newList() mp.put(diccionario, actual["tempo"], listo) lt.addLast(listo, actual) if mp.contains(diccionarionuevo, actual["artist_id"]): llaves = mp.get(diccionarionuevo, actual["artist_id"]) valores = me.getValue(llaves) lt.addLast(valores, actual) else: infor = lt.newList() mp.put(diccionarionuevo, actual["artist_id"], infor) lt.addLast(infor, actual) tamano1 = mp.size(diccionarionuevo) gene2 = tablageneros(nom2) llave = mp.get(gene2, nom2) valor2 = me.getValue(llave) rango2 = om.values(info["generos"], valor2[0], valor2[1]) diccionario2 = mp.newMap() diccionarionuevo2 = mp.newMap() iterador = it.newIterator(rango2) suma2 = 0 while it.hasNext(iterador): actu = it.next(iterador) suma2 += lt.size(actu) iterardentro = it.newIterator(actu) while it.hasNext(iterardentro): actual = it.next(iterardentro) if mp.contains(diccionario2, actual["tempo"]): ola = mp.get(diccionario2, actual["tempo"]) listo = me.getValue(ola) lt.addLast(listo, actual) else: listo = lt.newList() mp.put(diccionario2, actual["tempo"], listo) lt.addLast(listo, actual) if mp.contains(diccionarionuevo2, actual["artist_id"]): llaves = mp.get(diccionarionuevo2, actual["artist_id"]) valores = me.getValue(llaves) lt.addLast(valores, actual) else: infor = lt.newList() mp.put(diccionarionuevo2, actual["artist_id"], infor) lt.addLast(infor, actual) tamano2 = mp.size(diccionarionuevo2) gene3 = tablageneros(nom3) llave = mp.get(gene3, nom3) valor3 = me.getValue(llave) rango3 = om.values(info["generos"], valor3[0], valor3[1]) diccionario3 = mp.newMap() diccionarionuevo3 = mp.newMap() iterador = it.newIterator(rango3) suma3 = 0 while it.hasNext(iterador): actu = it.next(iterador) suma3 += lt.size(actu) iterardentro = it.newIterator(actu) while it.hasNext(iterardentro): actual = it.next(iterardentro) if mp.contains(diccionario3, actual["tempo"]): ola = mp.get(diccionario3, actual["tempo"]) listo = me.getValue(ola) lt.addLast(listo, actual) else: listo = lt.newList() mp.put(diccionario3, actual["tempo"], listo) lt.addLast(listo, actual) if mp.contains(diccionarionuevo3, actual["artist_id"]): llaves = mp.get(diccionarionuevo3, actual["artist_id"]) valores = me.getValue(llaves) lt.addLast(valores, actual) else: infor = lt.newList() mp.put(diccionarionuevo3, actual["artist_id"], infor) lt.addLast(infor, actual) tamano3 = mp.size(diccionarionuevo3) diccionarionuevo4 = mp.newMap() total = suma1 + suma2 + suma3 suma4 = 0 if nom4 != "": rango4 = om.values(info["generos"], des1, des2) diccionario4 = mp.newMap() iterador = it.newIterator(rango4) suma4 = 0 while it.hasNext(iterador): actu = it.next(iterador) suma4 += lt.size(actu) iterardentro = it.newIterator(actu) while it.hasNext(iterardentro): actual = it.next(iterardentro) if mp.contains(diccionario4, actual["tempo"]): ola = mp.get(diccionario4, actual["tempo"]) listo = me.getValue(ola) lt.addLast(listo, actual) else: listo = lt.newList() mp.put(diccionario4, actual["tempo"], listo) lt.addLast(listo, actual) if mp.contains(diccionarionuevo4, actual["artist_id"]): llaves = mp.get(diccionarionuevo4, actual["artist_id"]) valores = me.getValue(llaves) lt.addLast(valores, actual) else: infor = lt.newList() mp.put(diccionarionuevo4, actual["artist_id"], infor) lt.addLast(infor, actual) tamano4 = mp.size(diccionarionuevo4) llave1 = mp.keySet(diccionarionuevo) llave2 = mp.keySet(diccionarionuevo2) llave3 = mp.keySet(diccionarionuevo3) iterador = it.newIterator(llave1) primero = lt.newList() while it.hasNext(iterador): actu = it.next(iterador) lt.addLast(primero, actu) artistas1 = lt.subList(primero, 0, 12) iterador = it.newIterator(llave2) segundo = lt.newList() while it.hasNext(iterador): actu = it.next(iterador) lt.addLast(segundo, actu) artistas2 = lt.subList(segundo, 0, 12) iterador = it.newIterator(llave3) tercero = lt.newList() while it.hasNext(iterador): actu = it.next(iterador) lt.addLast(tercero, actu) artistas3 = lt.subList(tercero, 0, 12) return suma1, suma2, suma3, total, suma4, tamano1, tamano2, tamano3, tamano4, artistas1, artistas2, artistas3
def getVidsByCountry(catalog, country): country = mp.get(catalog["countries"], country) #Obtiene la lista de videos correspondientes a un pais, a partir de un mapa: O(1) if country: return me.getValue(country)["videos"] return None
def addRepGenre(cat, rep): m = cat["genres"] tempo = float(rep["tempo"]) hour = datetime.datetime.strptime(rep["created_at"][11:], '%H:%M:%S') date = datetime.datetime.strptime(rep["created_at"], '%Y-%m-%d %H:%M:%S') info = { "track_id": rep["track_id"], "created_at": date, "user_id": rep["user_id"] } if (tempo >= 60) and (tempo <= 90): name = "Reggae" a = mp.get(m, name) m_genre = me.getValue(a) m_genre_new = addMapKey(m_genre, hour, info) mp.put(m, name, m_genre_new) if (tempo >= 70) and (tempo <= 100): name = "Down-Tempo" a = mp.get(m, name) m_genre = me.getValue(a) m_genre_new = addMapKey(m_genre, hour, info) mp.put(m, name, m_genre_new) if (tempo >= 90) and (tempo <= 120): name = "Chill-Out" a = mp.get(m, name) m_genre = me.getValue(a) m_genre_new = addMapKey(m_genre, hour, info) mp.put(m, name, m_genre_new) if (tempo >= 85) and (tempo <= 115): name = "Hip-Hop" a = mp.get(m, name) m_genre = me.getValue(a) m_genre_new = addMapKey(m_genre, hour, info) mp.put(m, name, m_genre_new) if (tempo >= 120) and (tempo <= 125): name = "Jazz and Funk" a = mp.get(m, name) m_genre = me.getValue(a) m_genre_new = addMapKey(m_genre, hour, info) mp.put(m, name, m_genre_new) if (tempo >= 100) and (tempo <= 130): name = "Pop" a = mp.get(m, name) m_genre = me.getValue(a) m_genre_new = addMapKey(m_genre, hour, info) mp.put(m, name, m_genre_new) if (tempo >= 60) and (tempo <= 80): name = "R&B" a = mp.get(m, name) m_genre = me.getValue(a) m_genre_new = addMapKey(m_genre, hour, info) mp.put(m, name, m_genre_new) if (tempo >= 110) and (tempo <= 140): name = "Rock" a = mp.get(m, name) m_genre = me.getValue(a) m_genre_new = addMapKey(m_genre, hour, info) mp.put(m, name, m_genre_new) if (tempo >= 100) and (tempo <= 160): name = "Metal" a = mp.get(m, name) m_genre = me.getValue(a) m_genre_new = addMapKey(m_genre, hour, info) mp.put(m, name, m_genre_new)
t3 = process_time() tc = t3 - t2 T = tc + t print("Tiempo de carga de los directores y actores: ", tc) print("Tiempo total: ", T) elif int(inputs[0]) == 3: """ Econtrar las peliculas asociadas a una productora de cine """ productora = input( 'Ingrese el nombre de la productora de cine que desea consultar: ') t0 = process_time() llave_valor = mp.get(cont['productores'], productora) valor = me.getValue(llave_valor) print(valor) t1 = process_time() T = t1 - t0 print("Tiempo de carga: ", T) elif int(inputs[0]) == 4: nombre = input("Ingrese el nombre de un director: ") t0 = process_time() ids = controller.ids_peli_director(cont, nombre) controller.peliculas_por_director(cont, ids) t1 = process_time() t = t1 - t0 print("Tiempo de carga: ", t)
def suicidenme(catalog, landing_points, connections): mapa_traduccion = catalog["traduccion"] mapa_pais = catalog["paises"] mapa_landing = catalog["landing_points"] mapa_cables = catalog["cables"] mapa_cables_landing = catalog["cables_landing"] grafo = catalog["connections"] for landing_point in landing_points: id = landing_point["landing_point_id"] name = landing_point["name"] particion = name.split(",") nombre = particion[0] pais = particion[len(particion) - 1] if pais[0] == " ": pais = pais[1:] if nombre[0] == " ": nombre = nombre[1:] loc = (float(landing_point["latitude"]), float(landing_point["longitude"])) if not mp.contains(mapa_traduccion, nombre): mp.put(mapa_traduccion, nombre, lt.newList("SINGLE_LINKED")) lista = me.getValue(mp.get(mapa_traduccion, nombre)) lt.addLast(lista, id) else: lista = me.getValue(mp.get(mapa_traduccion, nombre)) lt.addLast(lista, id) mp.put(mapa_traduccion, id, nombre) if not mp.contains(mapa_pais, pais): mp.put(mapa_pais, pais, lt.newList(datastructure="SINGLE_LINKED")) lista = me.getValue(mp.get(mapa_pais, pais)) lt.addLast(lista, lt.newList(datastructure="SINGLE_LINKED")) sublista = lt.getElement(lista, 1) lt.addLast(sublista, id) else: lista = me.getValue(mp.get(mapa_pais, pais)) sublista = lt.getElement(lista, 1) lt.addLast(sublista, id) mp.put(mapa_landing, id, (loc, mp.newMap(maptype="PROBING", loadfactor=0.3), pais)) for num, connection in enumerate(connections): if num % 2 == 0: origin = connection["origin"] destination = connection["destination"] cable_name = connection["cable_name"] capacity = float(connection["capacityTBPS"]) mp.put(mapa_cables, cable_name, capacity) if not mp.contains(mapa_cables_landing, cable_name): mp.put(mapa_cables_landing, cable_name, mp.newMap(maptype="PROBING", loadfactor=0.3)) mp.put( mp.get(mapa_cables_landing, cable_name)["value"], origin, None) mp.put( mp.get(mapa_cables_landing, cable_name)["value"], destination, None) else: mp.put( mp.get(mapa_cables_landing, cable_name)["value"], origin, None) mp.put( mp.get(mapa_cables_landing, cable_name)["value"], destination, None) mapa = me.getValue(mp.get(mapa_landing, origin))[1] mp.put(mapa, cable_name, None) mapa = me.getValue(mp.get(mapa_landing, destination))[1] mp.put(mapa, cable_name, None) #Incersión de Vertices a Grafo con arcos: posOrigin = mp.get(mapa_landing, origin)["value"][0] posDestination = mp.get(mapa_landing, destination)["value"][0] costo = hs.haversine(posOrigin, posDestination) origin = origin + "|" + cable_name destination = destination + "|" + cable_name gr.insertVertex(grafo, origin) gr.insertVertex(grafo, destination) gr.addEdge(grafo, origin, destination, costo) idVertice1 = lt.getElement(gr.vertices(catalog["connections"]), 1).split("|")[0] #Creación de arcos entre vertices de un mismo Landing Point: llaves = mp.keySet(mapa_landing) for llave in lt.iterator(llaves): cables = mp.keySet(mp.get(mapa_landing, llave)["value"][1]) bwMenor = 100000000000000000000000000000000000000000000000000 for cable in lt.iterator(cables): bw = mp.get(mapa_cables, cable)["value"] if bw < bwMenor: bwMenor = bw for cable1 in lt.iterator(cables): if cable != cable1: origen = llave + "|" + cable destino = llave + "|" + cable1 if gr.getEdge(grafo, origen, destino) == None: gr.addEdge(grafo, origen, destino, 0.1) mp.put(mapa_cables, llave, bwMenor) return idVertice1
def getCountry(catalog, countryName): countryN = mo.get(catalog["countries"], countryName) if countryN == countryName: return me.getValue(countryN) return None
def getVideosByCountry(catalog, country): countryList = mp.get(catalog['videos'], country) if countryList: return me.getValue(countryList) return None
def getValue(map1,key): entry = mp.get(map1,key) return me.getValue(entry)
def getVideosByCategory(catalog,category_id): category_id = mp.get(catalog["category"], category_id) if category_id: return me.getValue(category_id)['videos']
def getMoviesbyGenre(catalogo, genre): gen = mp.get(catalogo['generos'], genre) if gen is not None: return me.getValue(gen) return None
def getMoviesbyCountry(catalogo, country): coun = mp.get(catalogo['paises'], country) if coun is not None: return me.getValue(coun) return None
def getActor_information(catalogo, actor_name): actor_entry = mp.get(catalogo["actores"], actor_name) if actor_entry is not None: return me.getValue(actor_entry) return None
def getMoviesbyCompany(catalogo, company_name): comp = mp.get(catalogo["productoras"], company_name) if comp is not None: return me.getValue(comp) return None
def requerimiento5(info, diccio, diccion, rangoinf, rangomay): vaya = lt.newList() senti = mp.valueSet(diccion["sentimiento"]) primero = it.newIterator(senti) while it.hasNext(primero): pasando = it.next(primero) lt.addLast(vaya, pasando) diccionarioo = mp.newMap() dumar = om.values(diccio["fecha"], rangoinf, rangomay) iteradorr = it.newIterator(dumar) while it.hasNext(iteradorr): act = it.next(iteradorr) iterardent = it.newIterator(act) while it.hasNext(iterardent): actuales = it.next(iterardent) id = actuales["created_at"] if not mp.contains(diccionarioo, id): mp.put(diccionarioo, id, actuales) gene = tablageneros("Metal") llave = mp.get(gene, "Metal") valor = me.getValue(llave) rango3 = om.values(info["generos"], valor[0], valor[1]) iterador = it.newIterator(rango3) suma = 0 diccionarios = mp.newMap() while it.hasNext(iterador): actu = it.next(iterador) iterardentro = it.newIterator(actu) while it.hasNext(iterardentro): actual = it.next(iterardentro) if mp.contains(diccionarioo, actual["created_at"]): suma += 1 gene = tablageneros("Rock") llave = mp.get(gene, "Rock") valor = me.getValue(llave) rango3 = om.values(info["generos"], valor[0], valor[1]) iterador = it.newIterator(rango3) suma2 = 0 while it.hasNext(iterador): actu = it.next(iterador) iterardentro = it.newIterator(actu) while it.hasNext(iterardentro): actual = it.next(iterardentro) if mp.contains(diccionarioo, actual["created_at"]): suma2 += 1 gene = tablageneros("Pop") llave = mp.get(gene, "Pop") valor = me.getValue(llave) rango3 = om.values(info["generos"], valor[0], valor[1]) iterador = it.newIterator(rango3) suma3 = 0 while it.hasNext(iterador): actu = it.next(iterador) iterardentro = it.newIterator(actu) while it.hasNext(iterardentro): actual = it.next(iterardentro) if mp.contains(diccionarioo, actual["created_at"]): suma3 += 1 gene = tablageneros("Chill-out") llave = mp.get(gene, "Chill-out") valor = me.getValue(llave) rango3 = om.values(info["generos"], valor[0], valor[1]) iterador = it.newIterator(rango3) suma4 = 0 while it.hasNext(iterador): actu = it.next(iterador) iterardentro = it.newIterator(actu) while it.hasNext(iterardentro): actual = it.next(iterardentro) if mp.contains(diccionarioo, actual["created_at"]): suma4 += 1 gene = tablageneros("Hip Hop") llave = mp.get(gene, "Hip Hop") valor = me.getValue(llave) rango3 = om.values(info["generos"], valor[0], valor[1]) iterador = it.newIterator(rango3) suma5 = 0 while it.hasNext(iterador): actu = it.next(iterador) iterardentro = it.newIterator(actu) while it.hasNext(iterardentro): actual = it.next(iterardentro) if mp.contains(diccionarioo, actual["created_at"]): suma5 += 1 gene = tablageneros("Down-tempo") llave = mp.get(gene, "Down-tempo") valor = me.getValue(llave) rango3 = om.values(info["generos"], valor[0], valor[1]) iterador = it.newIterator(rango3) suma6 = 0 while it.hasNext(iterador): actu = it.next(iterador) iterardentro = it.newIterator(actu) while it.hasNext(iterardentro): actual = it.next(iterardentro) if mp.contains(diccionarioo, actual["created_at"]): suma6 += 1 gene = tablageneros("Reggae") llave = mp.get(gene, "Reggae") valor = me.getValue(llave) rango3 = om.values(info["generos"], valor[0], valor[1]) iterador = it.newIterator(rango3) suma7 = 0 while it.hasNext(iterador): actu = it.next(iterador) iterardentro = it.newIterator(actu) while it.hasNext(iterardentro): actual = it.next(iterardentro) if mp.contains(diccionarioo, actual["created_at"]): suma7 += 1 gene = tablageneros("Jazz and Funk") llave = mp.get(gene, "Jazz and Funk") valor = me.getValue(llave) rango3 = om.values(info["generos"], valor[0], valor[1]) iterador = it.newIterator(rango3) suma8 = 0 while it.hasNext(iterador): actu = it.next(iterador) iterardentro = it.newIterator(actu) while it.hasNext(iterardentro): actual = it.next(iterardentro) if mp.contains(diccionarioo, actual["created_at"]): suma8 += 1 gene = tablageneros("R&B") llave = mp.get(gene, "R&B") valor = me.getValue(llave) rango3 = om.values(info["generos"], valor[0], valor[1]) iterador = it.newIterator(rango3) suma9 = 0 while it.hasNext(iterador): actu = it.next(iterador) iterardentro = it.newIterator(actu) while it.hasNext(iterardentro): actual = it.next(iterardentro) if mp.contains(diccionarioo, actual["created_at"]): suma9 += 1 total = suma + suma2 + suma3 + suma4 + suma5 + suma6 + suma7 + suma8 + suma9 return suma, suma2, suma3, suma4, suma5, suma6, suma7, suma8, suma9, total, diccionarioo
def addMax(intro, intro_num, origin): if intro_num > me.getValue(m.get(intro, "Max"))[0]: m.put(intro, "Max", [intro_num, origin])
def consultar_id(dic, categoria): entry = mp.get(dic, categoria) categoryID = me.getValue(entry) return categoryID
def getElement(entry): try: return me.getValue(entry) except: return None
def getdatesbyrange(cont): initialdate = input('ingrese la fecha inicial') finaldate = input('Ingrese la fecha final') n = int(input('Ingrese número de taxis:')) - 1 initialdate = datetime.datetime.strptime(initialdate, '%Y-%m-%d') initialdate = initialdate.date() finaldate = datetime.datetime.strptime(finaldate, '%Y-%m-%d') finaldate = finaldate.date() crimedates = om.values(cont, initialdate, finaldate) crimedates = crimedates['last'] crimedates = crimedates['info'] a = crimedates['taxiIndex'] millas1 = {} dinero1 = {} servicios1 = {} b = map.keySet(a) i = it.newIterator(b) puntajes = {} while it.hasNext(i): c = it.next(i) millas = 0 servicios = 0 dinero = 0 taxi = map.get(a, c) taxi = me.getValue(taxi) taxi = taxi['lsttrips'] x = it.newIterator(taxi) while it.hasNext(x): w = it.next(x) if float(w['trip_total']) > 0: milla = float(w['trip_miles']) millas += milla money = float(w['trip_total']) dinero += money servicios += 1 if dinero > 0: if not w['taxi_id'] in millas1: millas1[w['taxi_id']] = millas servicios1[w['taxi_id']] = servicios dinero1[w['taxi_id']] = dinero if w['taxi_id'] in millas1: millas1[w['taxi_id']] = millas1[w['taxi_id']] + millas servicios1[w['taxi_id']] = servicios1[w['taxi_id']] dinero1[w['taxi_id']] = dinero1[w['taxi_id']] b = map.keySet(a) i = it.newIterator(b) puntajes = {} millas = 0 dinero = 0 servicios = 0 while it.hasNext(i): c = it.next(i) if c in millas1: millas = millas1[c] dinero = dinero1[c] servicios = servicios1[c] puntaje = (millas / dinero) * servicios puntajes[c] = puntaje puntajes_ord = sorted(puntajes.items(), key=operator.itemgetter(1), reverse=True) num = 1 cent = 0 while n >= 0: print( str(num) + '.' + puntajes_ord[cent][0] + ' con un total de' + ' ' + str(puntajes_ord[cent][1])) num += 1 cent += 1 n -= 1
def getCategory(catalog, categoryId): category = mp.get(catalog['categoryIds'], categoryId) if category: return me.getValue(category) return None
def getMoviesByCompany(catalog, authorname): author = mp.get(catalog['production_companies'], authorname) if author: return me.getValue(author) return None
def getGenreByTime(analyzer,begtime,fintime): aux= {} auxlist= [] timesongs=om.keys(analyzer["char"], begtime, fintime) for value in lt.iterator(timesongs): charValue = om.get(analyzer["char"], value) ids = me.getValue(charValue)['lstTracks'] for track in lt.iterator(ids): CharValue = track["tempo"] entry = om.get(analyzer["char2"], CharValue) if entry is None: charentry = newDataEntry(track) om.put(analyzer["char2"], CharValue, charentry) else: charentry = me.getValue(entry) addCharIndex(charentry, track, 'track_id') aux["reggae"]= getTracksByRangeChar(analyzer, str(60), str(90), "char2") aux["downtempo"]= getTracksByRangeChar(analyzer, str(70), str(100), "char2") aux["chillout"]= getTracksByRangeChar(analyzer, str(90), str(120), "char2") aux["hiphop"]= getTracksByRangeChar(analyzer, str(85), str(115), "char2") aux["jazzfunk"]= getTracksByRangeChar(analyzer, str(120), str(125), "char2") aux["pop"]= getTracksByRangeChar(analyzer, str(100), str(130), "char2") aux["rnb"]= getTracksByRangeChar(analyzer, str(60), str(80), "char2") aux["rock"]= getTracksByRangeChar(analyzer, str(110), str(140), "char2") aux["metal"]= getTracksByRangeChar(analyzer, str(110), str(160), "char2") genre= max(aux, key=aux.get) print("El genero mas escuchado es "+genre+" con "+str(aux[genre])+" reproducciones") if genre == "reggae": minValue= 60 maxValue= 90 elif genre == "downtempo": minValue= 70 maxValue= 100 elif genre == "chillout": minValue= 90 maxValue= 120 elif genre == "hiphop": minValue= 85 maxValue= 115 elif genre == "jazzfunk": minValue= 120 maxValue= 125 elif genre == "pop": minValue= 100 maxValue= 130 elif genre == "rnb": minValue= 60 maxValue= 80 elif genre == "rock": minValue= 110 maxValue= 140 elif genre == "metal": minValue= 110 maxValue= 160 genrelist= om.values(analyzer["char2"], str(minValue), str(maxValue)) for i in lt.iterator(genrelist): for k in lt.iterator(i['lstTracks']): if k["track_id"] not in auxlist: auxlist.append(k["track_id"]) songsfile = cf.data_dir + "user_track_hashtag_timestamp-small.csv" input_file = csv.DictReader(open(songsfile, encoding="utf-8"), delimiter=",") for line in input_file: song= line["track_id"] entry= om.get(analyzer["char3"], song) if entry is None: hashtag= [] hashtag.append(line["hashtag"]) om.put(analyzer["char3"], song, hashtag) else: a= me.getValue(entry) if line["hashtag"] not in a: a.append(line["hashtag"]) songsfile2 = cf.data_dir + "sentiment_values.csv" input_file2 = csv.DictReader(open(songsfile2, encoding="utf-8"), delimiter=",") for line in input_file2: hashtag= line["hashtag"] if line["vader_avg"] == "" or line["vader_avg"] == " ": value= 0 else: value= float(line["vader_avg"]) mp.put(analyzer["char4"], hashtag, value) top10= {} tracks= {} for i in auxlist: vadersum= 0 cont= 0 hashtags=om.get(analyzer["char3"], i) hashtags=me.getValue(hashtags) top10[i]= len(hashtags) for k in hashtags: k= k.lower() vaderval=mp.get(analyzer["char4"], k) if vaderval != None: vaderval=me.getValue(vaderval) if vaderval > 0: cont+=1 vadersum += vaderval if cont != 0: vaderavg= vadersum/ cont else: vaderavg= 0 tracks[i]= vaderavg cont= 0 while cont < 10: a=max(top10, key=top10.get) print("\n TOP "+str(cont+1)+" track: "+a+" with "+str(top10[a])+" hashtags"+" and VADER = "+str(tracks[a])) del top10[a] cont +=1
def getMoviesByGenre(catalog, authorname): author = mp.get(catalog['genres'], authorname) if author: return me.getValue(author) return None
if all_valid: answer = controller.genreStudy(catalog, genres) print('\n \n++++++ Req No. 4 results... ++++++') totalReps = controller.getReps(answer) print('Total of reproductions: ', totalReps) statement1 = "======== {} ========" statement2 = "For {} the tempo is between {} and {} BPM" statememnt3 = "{} reproductions: {} with {} different artists" statememnt4 = "----- Some artists for {} -----" statememnt5 = "Artist {}: {}" for genre in genres: print('\n', statement1.format(genre)) ranges = me.getValue(mp.get(catalog['genre_dictionary'], genre)) print(statement2.format(genre, ranges['min'], ranges['max'])) reps_tot = controller.listSize(me.getValue(mp.get(answer, genre))['list']) arts_tot = controller.mapSize(me.getValue(mp.get(answer, genre))['unique_artists']) print(statememnt3.format(genre, reps_tot, arts_tot)) print(statememnt4.format(genre)) for n in range(1, 11): element = lt.getElement(me.getValue(mp.get(answer, genre))['list'], n) print(statememnt5.format(n, element['artist_id'])) elif int(inputs[0]) == 7: min_time = (input('El valor mínimo de la hora del día: ')) max_time = (input('El valor máximo de la hora del día: ')) min_time = dt.datetime.strptime(min_time, ("%H:%M:%S")) max_time = dt.datetime.strptime(max_time, ("%H:%M:%S"))
def getBooksByTag(catalog, tagname): tag = mp.get(catalog['director_name'], tagname) if tag: return me.getValue(tag) return None
def getChar(charList, charPos): bestChar = mp.get(charList, charPos) return me.getValue(bestChar)
def getMovieByActor(catalog, tagname): tag = mp.get(catalog['actores'], tagname) if tag: return me.getValue(tag) return None
def generotiempo(cat, hora_1, hora_2): m_g = cat["genres"] l_gen_name = mp.keySet(m_g) l_gen_reps = lt.newList(datastructure="ARRAY_LIST") l_max_tracks_genres = "" max_reps_genre = 0 tot_reps = 0 for gen in lt.iterator(l_gen_name): a = mp.get(m_g, gen) m_gen = me.getValue(a) l_reps = om.values(m_gen, hora_1, hora_2) reps = 0 l_gen = lt.newList(datastructure="ARRAY_LIST", cmpfunction=compareValue) for e in lt.iterator(l_reps): size = lt.size(e) reps += size for i in lt.iterator(e): if lt.isPresent(l_gen, i["track_id"]) == 0: lt.addLast(l_gen, i["track_id"]) if reps > max_reps_genre: max_reps_genre = reps l_max_tracks_genres = l_gen tot_reps += reps dic = {"nombre": gen, "reps": reps} lt.addLast(l_gen_reps, dic) unique_tracks = lt.size(l_max_tracks_genres) sorted_gen = sortReps(l_gen_reps, compareReps) top_genre = lt.getElement(sorted_gen, 0) r = lt.newList(datastructure="ARRAY_LIST") m_h = cat["hashtags"] m_s = cat["sentiment"] for i in lt.iterator(l_max_tracks_genres): num_hashtags = 0 sum_vader = 0 a = mp.get(m_h, i) l_hashtags = me.getValue(a) for e in lt.iterator(l_hashtags): h = e["hashtag"].lower() if (e["created_at"] >= hora_1) and (e["created_at"] <= hora_2): if mp.contains(m_s, h): b = mp.get(m_s, h) vader = me.getValue(b) if vader != 100: num_hashtags += 1 sum_vader += vader if num_hashtags == 0: num_hashtags = 1 vader_avg = sum_vader / num_hashtags dic = {} dic["track_id"] = i dic["numero hashtags"] = num_hashtags dic["vader promedio"] = vader_avg lt.addLast(r, dic) sorted_ht = sortReps(r, compareTrackHashtags) top_tracks = lt.subList(sorted_ht, 1, 10) return (tot_reps, sorted_gen, unique_tracks, top_tracks)
def getMoviesByCountry(catalog, authorname): author = mp.get(catalog['pais'], authorname) if author: return me.getValue(author) return None
def getValue(entry): return me.getValue(entry)
def requerimiento3(dicci, i1, i2, t1, t2): d = om.values(dicci["instrumentalness"], i1, i2) diccionario = mp.newMap() iterador = it.newIterator(d) while it.hasNext(iterador): actual = it.next(iterador) ite = it.newIterator(actual) while it.hasNext(ite): actual = it.next(ite) if float(actual["tempo"]) >= t1 and float(actual["tempo"]) <= t2: if mp.contains(diccionario, actual["track_id"]): ola = mp.get(diccionario, actual["track_id"]) listo = me.getValue(ola) lt.addLast(listo, actual) else: listo = lt.newList() mp.put(diccionario, actual["track_id"], listo) lt.addLast(listo, actual) alejita = mp.size(diccionario) spiderman = mp.valueSet(diccionario) jefa = lt.size(spiderman) besos = random.randint(1, jefa) pecas = random.randint(1, jefa) bruno = random.randint(1, jefa) armando = random.randint(1, jefa) jamaica = lt.getElement(spiderman, besos) sos = lt.getElement(spiderman, pecas) xavi = lt.getElement(spiderman, bruno) armando = lt.getElement(spiderman, armando) pelea = jamaica["first"]["info"] sos = sos["first"]["info"] xavi = xavi["first"]["info"] armando = armando["first"]["info"] pelele = ("Track 1: " + str(pelea["track_id"]) + " with instrumentalness of " + str(pelea["instrumentalness"]) + " and tempo of " + str(pelea["tempo"])) messi = ("Track 1: " + str(sos["track_id"]) + " with instrumentalness of " + str(sos["instrumentalness"]) + " and tempo of " + str(sos["tempo"])) xavi = ("Track 1: " + str(xavi["track_id"]) + " with instrumentalness of " + str(xavi["instrumentalness"]) + " and tempo of " + str(xavi["tempo"])) armando = ("Track 1: " + str(armando["track_id"]) + " with instrumentalness of " + str(armando["instrumentalness"]) + " and tempo of " + str(armando["tempo"])) pep = (messi, pelele, xavi, armando) return alejita, pep