def musica(cat, carac_1, carac_2, min_1, max_1, min_2, max_2): m = cat["features"] m_reps = mp.newMap(4000, maptype='PROBING', loadfactor=0.5) m_tracks = om.newMap(omaptype='RBT', comparefunction=compareValue) a = mp.get(m, carac_1) m_1 = me.getValue(a) l_1 = om.values(m_1, min_1, max_1) for lists in lt.iterator(l_1): for e in lt.iterator(lists): mp.put(m_reps, e["track_id"], "") b = mp.get(m, carac_2) m_2 = me.getValue(b) l_2 = om.values(m_2, min_2, max_2) for lists in lt.iterator(l_2): for e in lt.iterator(lists): if mp.contains(m_reps, e["track_id"]): om.put(m_tracks, e["track_id"], e) n_tracks = om.size(m_tracks) if n_tracks >= 5: num = 5 else: num = n_tracks random_tracks = random.sample(range(0, n_tracks), num) keys = lt.newList(datastructure="ARRAY_LIST") l_tracks = lt.newList(datastructure="ARRAY_LIST") for n in random_tracks: key = om.select(m_tracks, n) lt.addLast(keys, key) for a in lt.iterator(keys): rep = om.get(m_tracks, a) rep_info = me.getValue(rep) lt.addLast(l_tracks, rep_info) return (n_tracks, l_tracks)
def newCatalog(): """Crea un catalogo con las siguientes entradas: 1. halfList: Una lista con las entradas del primer archivo csv. 2. completeList: Una lista de todas las entradas que estan en ambos archivos csv combinadas 3. Una lista de diccionarios con los artistas y el numero de veces que cada uno se repite en el completeList 4. Una lista de diccionarios con las pistas y el numero de veces que cada una se repite en el completeList 5. Un RBT creado para ordenar las entradas del primer archivo csv y poderlas combinar con el segundo archivo.""" catalog = { "halfList": None, "completeList": None, "artistList": None, "trackList": None, "trackMap": None } catalog["halfList"] = lt.newList("SINGLE_LINKED") catalog["completeList"] = lt.newList("SINGLE_LINKED") catalog["artistList"] = lt.newList("SINGLE_LINKED") catalog["trackList"] = lt.newList("SINGLE_LINKED") catalog["trackMap"] = om.newMap(omaptype='RBT') return catalog
def ServiciosPorCompania(analyzer): ServiciosXCompania = om.newMap(omaptype='RBT', comparefunction=compareIds) total_servicios = 0 nombres = om.keySet(analyzer['companias']) # print(nombres) iter = it.newIterator(nombres) while it.hasNext(iter): cada_compania = it.next(iter) nombre_compania = om.get(analyzer['companias'], cada_compania) # print(nombre_compania) if nombre_compania['key'] is not None: servicios = me.getValue(nombre_compania)['servicios'] # print(servicios) if servicios is not None: num_servicios = m.size(servicios) total_servicios += num_servicios om.put(ServiciosXCompania, num_servicios, cada_compania) # print(nombre_compania['key'], num_servicios) # print(taxis) # print("TOTAL SERVICIOS: "+ str(total_servicios)) return (ServiciosXCompania)
def newAnalyzer2(): """ Inicializa el analizador Crea una lista vacia para guardar todos los tracks Se crean indices (Maps) por los siguientes criterios: -Fechas Retorna el analizador inicializado. """"instrumentalness","liveness","speechiness","danceability","valence" analyzer = {'tracks': None, 'tempo':None, 'artist_id':None, 'track_id':None, 'cantidad':None, 'vader_avg':None #Para poder usarlos, necesitamos tenerlos como arboles para que se identifiquen (aparezcan en los tracks) } analyzer['tracks'] = lt.newList('SINGLE_LINKED', compareIds) for parte in analyzer: if parte!='tracks': analyzer[parte]=om.newMap(omaptype='RBT', comparefunction=compareTracks) return analyzer
def Arbolde(catalog, Pistas, criterio): content = catalog['Content'] characteristic = mp.get(content, criterio) arbol = me.getValue(characteristic) if arbol is None: arbol = om.newMap(omaptype='RBT', comparefunction=compareValue) keyset = mp.keySet(Pistas) for num in range(0, lt.size(keyset)): llave = lt.getElement(keyset, num) pair = mp.get(Pistas, llave) if pair != None: cancion = me.getValue(pair) val_crit = float(cancion[criterio]) entry = om.get(arbol, val_crit) if entry is None: songs = lt.newList() lt.addLast(songs, cancion) om.put(arbol, val_crit, songs) else: lt.addLast(me.getValue(entry), cancion) mp.put(content, criterio, arbol) return arbol
def newAnalyzer(): analyzer = { 'artists': None, 'info': None, 'tracks': None, 'created_at': None, 'instrumentalness': None, 'acousticness': None, 'liveness': None, 'speechiness': None, 'energy': None, 'danceability': None, 'valence': None, 'tempo': None } analyzer['info'] = mp.newMap(130000, maptype='PROBING') analyzer['tracks'] = lt.newList('SINGLE_LINKED') analyzer['artists'] = lt.newList('SINGLE_LINKED') for car in analyzer: if car != 'tracks' and car != 'info' and car != 'artists': analyzer[car] = om.newMap(omaptype='RBT', comparefunction=compare) return analyzer
def getEventsByRangeTempoReturn(analyzer, criteria, initial, final): ''' Retorna el tempo de los eventos organizados en un arbol RBT dado un criterio y rango en el mismo, buscándolos en un árbol Args: analyzer: Analizador de eventos criteria: Llave del analyzer a analizar initial: Inicio del rango final: Fin del rango ''' lst = om.values(analyzer[criteria], initial, final) minimap = {'tempo_map': None} minimap['tempo_map'] = om.newMap(omaptype='RBT') for lstevents in lt.iterator(lst): for soundtrackyourtimeline in lt.iterator(lstevents['events']): addEventOnOrderedRBTMap(minimap, float(soundtrackyourtimeline['tempo']), soundtrackyourtimeline, 'tempo_map') return minimap
def addTracksByHourTempo(analyzer, track): hora = hour_int(track) tempo = float(track['tempo']) arbol_hora = analyzer['EvByHour'] #arbol principal entry_hora = om.get(arbol_hora, hora) #llave-valor con hora if entry_hora is not None: arbol_tempo = me.getValue(entry_hora) entry_tempo = om.get(arbol_tempo, tempo) if entry_tempo is not None: estructura = me.getValue(entry_tempo) lt.addLast(estructura['mapa_completo'], track) mp.put(estructura['mapa_unicos'], track['track_id'], track) om.put(arbol_tempo, tempo, estructura) else: estructura = { 'mapa_completo': lt.newList(datastructure="SINGLE_LINKED", cmpfunction=compareTracks), 'mapa_unicos': mp.newMap(maptype='PROBING', comparefunction=cmpByCarac) } lt.addLast(estructura['mapa_completo'], track) mp.put(estructura['mapa_unicos'], track['track_id'], track) om.put(arbol_tempo, tempo, estructura) else: arbol_tempo = om.newMap(omaptype='RBT', comparefunction=cmpInts) estructura = { 'mapa_completo': lt.newList(datastructure="SINGLE_LINKED", cmpfunction=compareTracks), 'mapa_unicos': mp.newMap(maptype='PROBING', comparefunction=cmpByCarac) } lt.addLast(estructura['mapa_completo'], track) mp.put(estructura['mapa_unicos'], track['track_id'], track) om.put(arbol_tempo, tempo, estructura) om.put(arbol_hora, hora, arbol_tempo) return None
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 = { 'events': None, 'artists': None, 'tracks': None, 'sentiments': None, 'hashtagsbytrack': None } analyzer['events'] = lt.newList('ARRAY_LIST') analyzer['sentiments'] = lt.newList('ARRAY_LIST') analyzer['hashtagsbytrack'] = mp.newMap(31000, maptype='PROBING', comparefunction=None) analyzer['artists'] = mp.newMap(11000, maptype='PROBING', comparefunction=None) analyzer['tracks'] = mp.newMap(31000, maptype='PROBING', comparefunction=None) for content in contenttuple: analyzer[content] = om.newMap(omaptype='RBT', comparefunction=compareFloat) return analyzer
def newAnalyzer(): bikes = { "Stations": None, "Trips": None, "grafo": None, 'paths': None, "table": None } bikes["grafo"] = gr.newGraph(datastructure="ADJ_LIST", directed=True, size=1000, comparefunction=compareStations) bikes["topsalida"] = iminpq.newIndexMinPQ(cmpfunction=cmpimin) bikes["topllegada"] = iminpq.newIndexMinPQ(cmpfunction=cmpimin) bikes["topuso"] = iminpq.newIndexMinPQ(cmpfunction=cmpimin) bikes["stationtree"] = om.newMap(omaptype='', comparefunction=comparebycoord) bikes["tablesalida"] = m.newMap(maptype='', comparefunction=compareIds) bikes["tablellegada"] = m.newMap(maptype='', comparefunction=compareIds) bikes["mayoressalida"] = m.newMap(maptype='', comparefunction=compareIds) bikes["mayoresllegada"] = m.newMap(maptype='', comparefunction=compareIds) bikes["names"] = m.newMap(maptype='', comparefunction=compareIds) bikes["BikesIDs"] = m.newMap(50000, maptype='PROBING', loadfactor=0.5, comparefunction=compareIds) bikes["ageVertexAHash"] = m.newMap(maptype='', comparefunction=compareIds) bikes["ageVertexBHash"] = m.newMap(maptype='', comparefunction=compareIds) bikes["stationVertexAHash"] = m.newMap(maptype='', comparefunction=compareIds) bikes["stationVertexBHash"] = m.newMap(maptype='', comparefunction=compareIds) bikes["ageTrips"] = m.newMap(maptype='', comparefunction=compareIds) bikes["agesA"] = lt.newList('SINGLE_LINKED') bikes["agesB"] = lt.newList('SINGLE_LINKED') return bikes
def getCar(analyzer, car: str): datos = analyzer['eventos'] newTree = om.newMap(omaptype='RBT', comparefunction=cmpCarValue) for audio in lt.iterator(datos): valor = audio[car] entry = om.get(newTree, valor) if not entry: lista = lt.newList("ARRAY_LIST") lt.addLast(lista, audio) om.put(newTree, valor, lista) else: lt.addLast(entry['value'], audio) return newTree
def getEventsByTimeRange(analyzer, initialValue, finalValue): """ Retorna el número de eventos y el map de eventos en un rango determinado de tiempo en horas, minutos y segundos (%H:%M:%S) """ map = om.newMap('RBT') initialTime = datetime.datetime.strptime(initialValue, '%H:%M:%S').time() finalTime = datetime.datetime.strptime(finalValue, '%H:%M:%S').time() lstevents = om.values(analyzer['time'], initialTime, finalTime) totalevents = 0 for lstevents in lt.iterator(lstevents): totalevents += lt.size(lstevents['events']) for event in lt.iterator(lstevents['events']): key = float(event['tempo']) existkey = om.contains(map, key) if existkey: entry = om.get(map, key) value = me.getValue(entry) else: value = newValue(key) om.put(map, key, value) lt.addLast(value['events'], event) return map, totalevents
def newCatalog(): """ Inicializa el catalogo crea una lista vacia para guardar todas las musicas Se crean indices (Maps) por los siguientes criterios: -Caracterista de contenido -Genero de la musica -Fecha de la musica Retorna el catalogo inicializado. """ catalog = { 'videosContext': None, 'caraContenido': None, 'musicalGenero': None, 'fechaMusica': None } catalog['videosContext'] = lt.newList('ARRAY_LIST') catalog['caraContenido'] = mp.newMap(30, maptype='PROBING', loadfactor=0.4) catalog['musicaGenero'] = mp.newMap(30, maptype='PROBING', loadfactor=0.4) catalog['fechaMusica'] = om.newMap('RBT') return catalog
def newAnalyzer(): Taxis = {"Hash": None} Taxis["Hash"] = m.newMap(maptype='', comparefunction=compareStopIds) Taxis["lst"] = [ "00:00", "00:15", "00:30", "00:45", "01:00", "01:15", "01:30", "01:45", "02:00", "02:15", "02:30", "02:45", "03:00", "03:15", "03:30", "03:45", "04:00", "04:15", "04:30", "04:45", "05:00", "05:15", "05:30", "5:45", "06:00", "06:15", "06:30", "06:45", "07:00", "07:15", "07:30", "07:45", "08:00", "08:15", "08:30", "08:45", "09:00", "09:15", "09:30", "09:45", "10:00", "10:15", "10:30", "10:45", "11:00", "11:15", "11:30", "11:45", "12:00", "12:15", "12:30", "12:45", "13:00", "13:15", "13:30", "13:45", "14:00", "14:15", "14:30", "14:45", "15:00", "15:15", "15:30", "15:45", "16:00", "16:15", "16:30", "16:45", "17:00", "17:15", "17:30", "17:45", "18:00", "18:15", "18:30", "18:45", "19:00", "19:15", "19:30", "19:45", "20:00", "20:15", "20:30", "20:45", "21:00", "21:15", "21:30", "21:45", "22:00", "22:15", "22:30", "22:45", "23:00", "23:15", "23:30", "23:45" ] Taxis["dateIndex"] = om.newMap(omaptype='BST', comparefunction=compareDates) Taxis["Brand"] = m.newMap(maptype='', comparefunction=compareStopIds) Taxis["ids"] = m.newMap(maptype='', comparefunction=compareStopIds) Taxis["afiliado"] = imaxpq.newIndexMaxPQ(cmpimin) Taxis["servicio"] = imaxpq.newIndexMaxPQ(cmpimin) return Taxis
def top3salida(analyzer): outree = om.newMap(omaptype="RBT", comparefunction=compareIds) pqiterator = it.newIterator(vertexNames(analyzer)) while it.hasNext(pqiterator): vert = int(it.next(pqiterator)) salidas = gr.outdegree(analyzer["graph"], str(vert)) if not om.contains(outree, salidas): om.put(outree, salidas, str(vert)) else: A = om.get(outree, salidas) B = me.getValue(A) om.put(outree, salidas, str(B)+","+str(vert)) estaciones = lt.newList(datastructure="ARRAY_LIST") while lt.size(estaciones) < 3: val = om.get(outree, om.maxKey(outree)) val1 = me.getValue(val) mayorsalida = val1.split(",") for i in mayorsalida: if lt.size(estaciones) < 3: K = m.get(analyzer["nameIndex"], i) L = me.getValue(K) lt.addLast(estaciones, L) om.deleteMax(outree) return estaciones
def companyRanking(analyzer, M): companies = om.keySet(analyzer["companiesRanking"]) taxis = om.valueSet(analyzer["companiesRanking"]) mapa = om.newMap(omaptype="BST", comparefunction=cmpCompanies) for i in range(lt.size(companies)): empresa = lt.getElement(companies, i) numtaxi = lt.getElement(taxis, i) if om.contains(mapa, numtaxi) == True: infonum = om.get(mapa, numtaxi) empresas = infonum["value"] lt.addLast(empresas, empresa) om.put(mapa, numtaxi, empresas) else: empresas = lt.newList("ARRAY_LIST", None) lt.addLast(empresas, empresa) om.put(mapa, numtaxi, empresas) tam = om.size(mapa) tam = tam - 1 for i in range(M): k = tam - i emp = om.select(mapa, k) pareja = om.get(mapa, emp) lista = pareja["value"] numt = lista["elements"] info = str(tam - k + 1) + ". " + str(numt[0]) + ": " + str(emp) print(info) result = ".." return result
def caracterizarrep(cat, carac, minimo, maximo): m = cat["features"] a = mp.get(m, carac) m_carac = me.getValue(a) l_reps = om.values(m_carac, minimo, maximo) t_artists = om.newMap(omaptype='RBT', comparefunction=compareValue) num_reps = 0 for lists in lt.iterator(l_reps): size = lt.size(lists) num_reps += size for reps in lt.iterator(lists): artist = reps["artist_id"] if om.contains(t_artists, artist): c = om.get(t_artists, artist) l_artist = me.getValue(c) else: l_artist = lt.newList(datastructure="SINGLE_LINKED") lt.addLast(l_artist, reps) om.put(t_artists, artist, l_artist) artists = om.size(t_artists) return (num_reps, artists, t_artists)
def newAnalyzer(): """ Inicializa el analizador """ analyzer = { "lista": None, "mapcompany": None, "taxids": None, } analyzer["lista"] = lt.newList("ARRAY_LIST") analyzer["mapcompany"] = m.newMap(numelements=37, maptype="CHAINING", loadfactor=0.4, comparefunction=comparecompany) analyzer["MapaId"] = op.newMap(omaptype='RBT', comparefunction=compareDates) analyzer["taxids"] = m.newMap(numelements=37, maptype="CHAINING", loadfactor=0.4, comparefunction=comparecompany) analyzer['grafo'] = gr.newGraph(datastructure='ADJ_LIST', directed=True, size=300, comparefunction=comparecompany) return analyzer
def newMapOrdenado(): dicci = {} dicci['instrumentalness'] = om.newMap(omaptype='BRT', comparefunction=compareDates) dicci['acousticness'] = om.newMap(omaptype='BRT', comparefunction=compareDates) dicci['liveness'] = om.newMap(omaptype='BRT', comparefunction=compareDates) dicci['speechiness'] = om.newMap(omaptype='BRT', comparefunction=compareDates) dicci['energy'] = om.newMap(omaptype='BRT', comparefunction=compareDates) dicci['danceability'] = om.newMap(omaptype='BRT', comparefunction=compareDates) dicci['valence'] = om.newMap(omaptype='BRT', comparefunction=compareDates) return dicci
def __init__(self): self.Route = orderedmap.newMap(comparefunction=cmp.compareDate)
def analyzer_context(): analyzer_context = { "eventos": None, "index": None, "userid": None, "track_id": None, "instrumentalness": None, "liveness": None, "speechiness": None, "danceability": None, "valence": None, "loudness": None, "tempo": None, "acousticness": None, "energy": None, "artist_id": None, "created_at": None, "time_zone": None } analyzer_context["eventos"] = m.newMap(numelements=63400, prime=109345121, maptype="CHAINING", loadfactor=1, comparefunction=comparer) analyzer_context["index"] = om.newMap(omaptype="RBT", comparefunction=compareDates) analyzer_context["artist_id"] = om.newMap(omaptype="RBT", comparefunction=compareDates) analyzer_context["userid"] = om.newMap(omaptype="RBT", comparefunction=compareDates) analyzer_context["track_id"] = om.newMap(omaptype="RBT", comparefunction=compareDates) analyzer_context["created_at"] = om.newMap(omaptype="RBT", comparefunction=compareTime) analyzer_context["instrumentalness"] = om.newMap( omaptype="RBT", comparefunction=compareLat) analyzer_context["liveness"] = om.newMap(omaptype="RBT", comparefunction=compareLiv) analyzer_context["speechiness"] = om.newMap(omaptype="RBT", comparefunction=compareLiv) analyzer_context["danceability"] = om.newMap(omaptype="RBT", comparefunction=compareLiv) analyzer_context["valence"] = om.newMap(omaptype="RBT", comparefunction=compareLiv) analyzer_context["loudness"] = om.newMap(omaptype="RBT", comparefunction=compareLiv) analyzer_context["tempo"] = om.newMap(omaptype="RBT", comparefunction=compareLiv) analyzer_context["acousticness"] = om.newMap(omaptype="RBT", comparefunction=compareLiv) analyzer_context["energy"] = om.newMap(omaptype="RBT", comparefunction=compareLiv) analyzer_context["time_zone"] = om.newMap(omaptype="RBT", comparefunction=compareZone) return analyzer_context
def position(): return { 'latitude': orderedmap.newMap('RBT', Comparation.compareIdTree), 'longitude': orderedmap.newMap('RBT', Comparation.compareIdTree), }
def newCatalogo(): """ 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. """ catalogo = {'events': None, 'artistas': None, 'pistas': None} catalogo['events'] = lt.newList('SINGLE_LINKED', compareIds) catalogo['eventos_id'] = om.newMap(omaptype='RBT', comparefunction=compareIds) catalogo['artistas'] = om.newMap(omaptype='RBT', comparefunction=compareIds) catalogo['pistas'] = om.newMap(omaptype='RBT', comparefunction=compareIds) catalogo['instrumentalness'] = om.newMap(omaptype='RBT', comparefunction=compareIds) catalogo['liveness'] = om.newMap(omaptype='RBT', comparefunction=compareIds) catalogo['speechiness'] = om.newMap(omaptype='RBT', comparefunction=compareIds) catalogo['danceability'] = om.newMap(omaptype='RBT', comparefunction=compareIds) catalogo['valence'] = om.newMap(omaptype='RBT', comparefunction=compareIds) catalogo['loudness'] = om.newMap(omaptype='RBT', comparefunction=compareIds) catalogo['tempo'] = om.newMap(omaptype='RBT', comparefunction=compareIds) catalogo['acousticness'] = om.newMap(omaptype='RBT', comparefunction=compareIds) catalogo['energy'] = om.newMap(omaptype='RBT', comparefunction=compareIds) catalogo['mode'] = om.newMap(omaptype='RBT', comparefunction=compareIds) catalogo['key'] = om.newMap(omaptype='RBT', comparefunction=compareIds) catalogo['hashtags'] = om.newMap(omaptype='RBT', comparefunction=None) catalogo['dates'] = om.newMap(omaptype='RBT', comparefunction=None) return catalogo
def New_list(): lista = {"Accidentes": None, "Fechas": None, "Horas": None} lista['Accidentes'] = lt.newList('SINGLE_LINKED', compareAccidentes) lista['Fechas'] = om.newMap(omaptype='RBT', comparefunction=compararFechas) lista['Horas'] = om.newMap(omaptype='RBT', comparefunction=compararHoras) return lista
def newAnalyzer(): analyzer = { 'content_features': None, 'track_hashtag': None, 'Sentiment_values': None, 'instrumentalness': None, 'liveness': None, 'speechiness': None, 'danceability': None, 'valence': None, 'acousticness': None, 'energy': None, 'Nombre_generos': None } #Lists analyzer['content_features'] = lt.newList('ARRAY_LIST') analyzer['track_hashtag_lst'] = lt.newList('ARRAY_LIST') #Binary Trees #analyzer['content_features_req5'] = lt.newList('ARRAY_LIST') analyzer['track_hashtag'] = lt.newList('ARRAY_LIST') analyzer['Sentiment_values'] = lt.newList('ARRAY_LIST') #Binary Trees analyzer['time_of_event'] = om.newMap(omaptype='BST') analyzer['instrumentalness'] = om.newMap(omaptype='BST') analyzer['liveness'] = om.newMap(omaptype='BST') analyzer['speechiness'] = om.newMap(omaptype='BST') analyzer['danceability'] = om.newMap(omaptype='BST') analyzer['valence'] = om.newMap(omaptype='BST') analyzer['acousticness'] = om.newMap(omaptype='BST') analyzer['energy'] = om.newMap(omaptype='BST') analyzer['artistas'] = mp.newMap(numelements=65, maptype='PROBING', loadfactor=0.3) analyzer['unique_tracks_init'] = mp.newMap(numelements=65, maptype='PROBING', loadfactor=0.3) #Binary Trees para generos analyzer['generos'] = om.newMap(omaptype='BST') analyzer['Reggae'] = mp.newMap(numelements=65, maptype='PROBING', loadfactor=0.3) analyzer['Down-tempo'] = mp.newMap(numelements=65, maptype='PROBING', loadfactor=0.3) analyzer['Chill-out'] = mp.newMap(numelements=65, maptype='PROBING', loadfactor=0.3) analyzer['Hip-hop'] = mp.newMap(numelements=65, maptype='PROBING', loadfactor=0.3) analyzer['Jazz and Funk'] = mp.newMap(numelements=65, maptype='PROBING', loadfactor=0.3) analyzer['Pop'] = mp.newMap(numelements=65, maptype='PROBING', loadfactor=0.3) analyzer['R&B'] = mp.newMap(numelements=65, maptype='PROBING', loadfactor=0.3) analyzer['Rock'] = mp.newMap(numelements=65, maptype='PROBING', loadfactor=0.3) analyzer['Metal'] = mp.newMap(numelements=65, maptype='PROBING', loadfactor=0.3) #Lista para generos analyzer['Nombre_generos'] = lt.newList('ARRAY_LIST') analyzer['generos_tempos'] = mp.newMap(numelements=65, maptype='PROBING', loadfactor=0.3) #arbol binario hash table analyzer['track_hashtag'] = om.newMap(omaptype='RBT') analyzer['Sentiment_values'] = om.newMap(omaptype='BST') analyzer['ferrari'] = mp.newMap(numelements=65, maptype='PROBING', loadfactor=0.3) #Árbol Binario Hashtags analyzer['track_hashtags'] = om.newMap(omaptype='BST') #Árbol Binario Sentiment analyzer['sentiment_values'] = om.newMap(omaptype='BST') #Árbol Binario Llave Tempo Valor Género analyzer['tempo_genero'] = om.newMap(omaptype='BST') #Arbol Binario Completo Req 5 analyzer['hash_generos'] = om.newMap(omaptype='BST') return analyzer
def tree(): tree = om.newMap(omaptype='BST') return tree
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 = { 'events': None, 'dateIndex': None, 'sentiments': None, 'content': None, } analyzer['sentiments'] = mp.newMap(maptype='PROBING') analyzer['content'] = mp.newMap(maptype="PROBING") #Instrumentalness: Crea un tree con los valores instrumentalnessTree = om.newMap(comparefunction=compareValues) mp.put(analyzer['content'], 'instrumentalness', instrumentalnessTree) #Liveness: Crea un tree con los valores livenessTree = om.newMap(comparefunction=compareValues) mp.put(analyzer['content'], 'liveness', livenessTree) #Speechiness: Crea un tree con los valores speechinessTree = om.newMap(comparefunction=compareValues) mp.put(analyzer['content'], 'speechiness', speechinessTree) #Danceability: Crea un tree con los valores danceabilityTree = om.newMap(comparefunction=compareValues) mp.put(analyzer['content'], 'danceability', danceabilityTree) #Valence: Crea un tree con los valores valenceTree = om.newMap(comparefunction=compareValues) mp.put(analyzer['content'], 'valence', valenceTree) #Loudness: Crea un tree con los valores loudnessTree = om.newMap(comparefunction=compareValues) mp.put(analyzer['content'], 'loudness', loudnessTree) #Tempo: Crea un tree con los valores tempoTree = om.newMap(comparefunction=compareValues) mp.put(analyzer['content'], 'tempo', tempoTree) #Acousticness: Crea un tree con los valores acousticnessTree = om.newMap(comparefunction=compareValues) mp.put(analyzer['content'], 'acousticness', acousticnessTree) #Energy: Crea un tree con los valores energyTree = om.newMap(comparefunction=compareValues) mp.put(analyzer['content'], 'energy', energyTree) analyzer['events'] = lt.newList("ARRAY_LIST", cmpfunction=compareIds2) analyzer['track_id'] = om.newMap(omaptype='RBT') analyzer['artists'] = om.newMap(omaptype='RBT', comparefunction=compareIds1) analyzer['created_at'] = om.newMap(omaptype='RBT', comparefunction=compareTime) analyzer['created_at-hashtag'] = om.newMap(omaptype='RBT', comparefunction=compareTime) return analyzer
def Req5(analyzer, time1, time2): arbolHoras = analyzer["created_at"] #Sacamos el arbol organizado por horas valoresHoras = om.values( arbolHoras, time1, time2) #Sacar los valores del arbol en el rango de horas arbolPorTempo = om.newMap(omaptype="RBT", comparefunction=compareValues ) #Crear un arbol vacio organizado por tempo for lista in lt.iterator(valoresHoras): #Recorrer la lista de listas for evento in lt.iterator(lista): #Recorrer cada lista de eventos tempo = float(evento['tempo']) #Abstraer el tempo del evento existe = om.get( arbolPorTempo, tempo) #Revisar si el tempo ya fue creado en el arbol de tempo if existe is None: #Si no esta creado eventList = lt.newList( 'ARRAY_LIST', cmpfunction=compareValues) # Crear una lista vacia om.put( arbolPorTempo, tempo, eventList) #Agregar la lista al nodo de tempo respectivo else: #Si está creado eventList = me.getValue(existe) #Recuperar la lista del nodo lt.addLast( eventList, evento ) #Agregar el evento del rango de horas a la lista del respectivo nodo de tempo mapaPorGenero = mp.newMap(maptype="PROBING") #Se crea un diccionario vacio mapaPorSize = om.newMap(omaptype="RBT") #Se crea un arbol vacio for genero in [ "Reggae", "Down-tempo", "Chill-out", "Hip-hop", "Jazz and Funk", "Pop", "R&B", "Rock", "Metal" ]: #Por cada genero que existe pistas, minTempo, maxTempo = pistasPorGenero( arbolPorTempo, genero, None, None) #Se saca la lista de listas con los eventos por genero listaEventos = lt.newList( "ARRAY_LIST", cmpfunction=compareIds2 ) #Se crea una lista vacia donde se guardaran los eventos por genero for lista in lt.iterator(pistas): #Se recorre la lista de listas for evento in lt.iterator( lista): #Se recorre cada lista de eventos lt.addLast(listaEventos, evento) #Se añade el evento a la lista del genero sizeLista = lt.size( listaEventos) #Se saca el tamaño de la lista del genero mp.put( mapaPorGenero, genero, listaEventos ) #Se agrega la lista de eventos al mapa con llave el respectivo genero om.put( mapaPorSize, sizeLista, genero ) #Se agrega al mapaPorSize el numero de reps del genero como llave y el genero como valor mayorsize = om.maxKey(mapaPorSize) entry = om.get(mapaPorSize, mayorsize) mayorGenero = me.getValue(entry) entry = mp.get( mapaPorGenero, mayorGenero) #Se sacan los eventos del genero que más se repitió eventosMayorGenero = me.getValue(entry) uniqueTracks = mp.newMap( maptype="PROBING" ) #Se crea un mapa vacio para sacar los track_id unicos for evento in lt.iterator(eventosMayorGenero): existe = mp.get(uniqueTracks, evento["track_id"]) if existe is None: lista_hashtags = lt.newList() mp.put(uniqueTracks, evento["track_id"], lista_hashtags) else: lista_hashtags = me.getValue(existe) for hashtag in lt.iterator( evento["hashtag"] ): #Se recorre la lista de hashtags del evento lt.addLast( lista_hashtags, hashtag) #Se agrega cada ht a la lista de ht de la pista única llavesTrackId = mp.keySet(uniqueTracks) totalUniqueTracks = lt.size(llavesTrackId) random10Tracks = lt.subList(llavesTrackId, random.randint(1, totalUniqueTracks - 10), 10) sample = lt.newList() for trackId in lt.iterator(random10Tracks): entry = mp.get(uniqueTracks, trackId) hashtagsEvento = me.getValue(entry) vaderAvg = 0 totalHt = 0 for hashtag in lt.iterator(hashtagsEvento): entry = mp.get(analyzer["sentiments"], hashtag.lower()) if entry is not None: vader = me.getValue(entry) if vader is not None: vaderAvg += vader totalHt += 1 if totalHt > 0: vaderAvg /= totalHt lt.addLast(sample, (trackId, totalHt, round(vaderAvg, 1))) return om.size(arbolPorTempo), mapaPorSize, totalUniqueTracks, sample
def newCatalog(): """ Inicializa el catálogo Retorna el catálogo inicializado. """ catalog = { 'RepsPor_instrumentalness': None, } #----------------------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------------------- #Carga: catalog['Artistas_Unicos'] = mp.newMap(maptype='PROBING') catalog['Pistas_Unicas'] = mp.newMap(maptype='PROBING') #----------------------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------------------- #Req1: #por cada caracteristica se hace un mapa ordenado que tiene los valores de la caracteristica como llaves y a la lista de # las reproducciones con el valor correspondiente a la caracteristica catalog['RepsPor_instrumentalness'] = om.newMap( omaptype='RBT', comparefunction=MAPcompareDecimals) catalog['RepsPor_liveness'] = om.newMap(omaptype='RBT', comparefunction=MAPcompareDecimals) catalog['RepsPor_speechiness'] = om.newMap( omaptype='RBT', comparefunction=MAPcompareDecimals) catalog['RepsPor_energy'] = om.newMap(omaptype='RBT', comparefunction=MAPcompareDecimals) catalog['RepsPor_acousticness'] = om.newMap( omaptype='RBT', comparefunction=MAPcompareDecimals) catalog['RepsPor_danceability'] = om.newMap( omaptype='RBT', comparefunction=MAPcompareDecimals) catalog['RepsPor_valence'] = om.newMap(omaptype='RBT', comparefunction=MAPcompareDecimals) #----------------------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------------------- #Req 4 #Generos: Aqui se guardaran las reproducciones partidas por generos: # es decir: esto es un mapa/hashTable donde una llave es un genero(nombre del genero) y su valor es una tupla: # 1: una tupla de los limites del rango 2. la lista de reproducciones que segun su tempo/bpm corresponden a ese genero #OJO una MISMA EXACTA REPRODUCCION puede estar en la lista de distintos generos porque puede pertenecer a mas de un genero a la vez generos = mp.newMap(loadfactor=4.0) mp.put(generos, 'Reggae', ((60, 90), lt.newList(datastructure='ARRAY_LIST'))) mp.put(generos, 'Down-Tempo', ((70, 100), lt.newList(datastructure='ARRAY_LIST'))) mp.put(generos, 'Chill-Out', ((90, 120), lt.newList(datastructure='ARRAY_LIST'))) mp.put(generos, 'Hip-Hop', ((85, 115), lt.newList(datastructure='ARRAY_LIST'))) mp.put(generos, 'Jazz and Funk', ((120, 125), lt.newList(datastructure='ARRAY_LIST'))) mp.put(generos, 'Pop', ((100, 130), lt.newList(datastructure='ARRAY_LIST'))) mp.put(generos, 'R&B', ((60, 80), lt.newList(datastructure='ARRAY_LIST'))) mp.put(generos, 'Rock', ((110, 140), lt.newList(datastructure='ARRAY_LIST'))) mp.put(generos, 'Metal', ((100, 160), lt.newList(datastructure='ARRAY_LIST'))) catalog['Generos'] = generos #reproducciones totales: catalog['Reproducciones_totales'] = mp.newMap(loadfactor=4.0) #----------------------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------------------- # REQ 5: catalog['RepsPor_hora'] = om.newMap(omaptype='RBT', comparefunction=MAPCompararHoras) catalog['Hashtags'] = mp.newMap(maptype='PROBING') return catalog
def newCatalog(): """ 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. """ catalog = { 'eventos': None, 'energy': None, 'instrumentalness': None, 'danceability': None, 'tempo': None, 'acousticness': None, 'hashtags': None, 'time': None } catalog['eventos'] = lt.newList(datastructure='ARRAY_LIST') catalog['energy'] = om.newMap(omaptype="RBT") catalog['instrumentalness'] = om.newMap(omaptype="RBT") catalog['danceability'] = om.newMap(omaptype="RBT") catalog['tempo'] = om.newMap(omaptype="RBT") catalog['acousticness'] = om.newMap(omaptype="RBT") catalog['liveness'] = om.newMap(omaptype="RBT") catalog['speechiness'] = om.newMap(omaptype="RBT") catalog['valence'] = om.newMap(omaptype="RBT") catalog['time'] = om.newMap(omaptype="RBT") catalog["energy"] = om.newMap(omaptype="RBT") catalog["hashtags"] = mp.newMap(maptype="PROBING", loadfactor=0.5) catalog['hashtagsportrack'] = mp.newMap(maptype="PROBING", loadfactor=0.5) catalog['tiempo'] = om.newMap(omaptype="RBT") return catalog