def pointsInRange(analyzer, n, in_date, fi_date): arbol=analyzer["arbol_dates"] taxis = lt.newList("ARRAY_LIST",compare) lista=om.values(arbol, in_date, fi_date) if lt.isEmpty(lista): return None iterator=it.newIterator(lista) mapTaxis = m.newMap(100,maptype='CHAINING',loadfactor=5,comparefunction=compareMap) while it.hasNext(iterator): date=it.next(iterator) for i in range(1,lt.size(date)+1): element = lt.getElement(date,i) num,taxiId = element entry = m.get(mapTaxis,taxiId) if entry == None: lt.addLast(taxis, taxiId) m.put(mapTaxis,taxiId,num) else: num2 = entry["value"] numNew = num2 + num entry["value"] = numNew max_pq=hp.newHeap(compare) for j in range (1, lt.size(taxis)+1): taxiId = lt.getElement(taxis,j) points = me.getValue(m.get(mapTaxis,taxiId)) hp.insertMax(max_pq,points, taxiId) lst = max_pq['elements'] size = lt.size(lst) while size>1: lt.exchange(lst,1,size) size -=1 sinksort(lst,1,size) return (lst,lt.size(lst))
def newMinPQ(cmpfunction): """ Crea un cola de prioridad orientada a menor Args: cmpfunction: La funcion de comparacion size: El numero de elementos Returns: El heap Raises: Exception """ try: pq = {'heap': None} pq['heap'] = h.newHeap(cmpfunction) return pq except Exception as exp: error.reraise(exp, 'newMinPQ')
def orderPoints(analyzer): lista=analyzer["list_dates"] mapa= analyzer["date"] arbol= analyzer["arbol_dates"] for i in range(1, lt.size(lista)+1): date=lt.getElement(lista, i) taxis=me.getValue(m.get(mapa, date)) taxisLst = taxis["taxis"] taxisMap = taxis["map"] max_pq=hp.newHeap(compare) for j in range (1, lt.size(taxisLst)+1): taxiId = lt.getElement(taxisLst,j) taxiDict = me.getValue(m.get(taxisMap,taxiId)) point=(taxiDict["millas"]/taxiDict["money"])*taxiDict["services"] hp.insertMax(max_pq,point, taxiId) lst = max_pq['elements'] size = lt.size(lst) while size>1: lt.exchange(lst,1,size) size -=1 sinksort(lst,1,size) om.put(arbol,date, lst)
stop=False while (rs in range(1, size)) and (ls in range(1,size)) and not stop: root=lt.getElement(lst,follower) Right_son=lt.getElement(lst, rs) Left_son=lt.getElement(lst, ls) if cmpfunction(root, Right_son): lt.exchange(lst, follower, rs) if cmpfunction(Right_son, Left_son): lt.exchange(lst, follower, ls) follower=rs elif cmpfunction(root, Left_son): lt.exchange(lst, follower, ls) follower=ls else: stop=True rs=follower*2 ls=follower*2+1 example=hp.newHeap(cmpfunction) lst=lt.newList() def cmpfunction(a,b ): """ Compara dos números. """ if a < b: return -1 elif a == b: return 0 else: return 1
def req_5_v_2(analyzer, start_time, end_time): keys = om.valueSet(analyzer['sentiment_values']) list_of_maps = om.values(analyzer['hash_generos'], start_time, end_time) registropy = mp.newMap(numelements=65, maptype='PROBING', loadfactor=0.3) for hash_table in lt.iterator(list_of_maps): keyset = mp.keySet(hash_table['mapContent']) for key in lt.iterator(keyset): entry = mp.get(hash_table['mapContent'], key) videos_list = me.getValue(entry) size = lt.size(videos_list['lstContent']) lamborghini = mp.get(registropy, key) if lamborghini is not None: lamborghini = me.getValue(lamborghini) lamborghini += size mp.put(registropy, key, lamborghini) elif lamborghini is None: mp.put(registropy, key, size) totalreps = 0 genres = mp.keySet(registropy) mayor = '' repsmax = 0 repstemp = 0 for genre in lt.iterator(genres): repstemp = me.getValue(mp.get(registropy, genre)) if repstemp > repsmax: repsmax = repstemp mayor = genre if 'unique' not in genre: totalreps += repstemp print('There is a total of ' + str(totalreps) + ' reproductions between ' + start_time + ' and ' + end_time) print( '================================ GENRES SORTED REPRODUCTIONS ================================' ) print('Metal unique: ' + str(me.getValue(mp.get(registropy, 'Metal_unique')))) print('Metal: ' + str(me.getValue(mp.get(registropy, 'Metal')))) print('Reggae: ' + str(me.getValue(mp.get(registropy, 'Reggae')))) print('Down-tempo: ' + str(me.getValue(mp.get(registropy, 'Down-tempo')))) print('Chill-out: ' + str(me.getValue(mp.get(registropy, 'Chill-out')))) print('Hip-hop: ' + str(me.getValue(mp.get(registropy, 'Hip-hop')))) print('Pop: ' + str(me.getValue(mp.get(registropy, 'Pop')))) print('R&B: ' + str(me.getValue(mp.get(registropy, 'R&B')))) print('Rock: ' + str(me.getValue(mp.get(registropy, 'Rock')))) print('Jazz and Funk: ' + str(me.getValue(mp.get(registropy, 'Jazz and Funk')))) all_videos = hp.newHeap(heap_compare) for hash_table in lt.iterator(list_of_maps): keyset = mp.keySet(hash_table['mapContent']) for key in lt.iterator(keyset): if key == mayor: entry = mp.get(hash_table['mapContent'], key) videos_list = me.getValue(entry) for video in lt.iterator(videos_list['lstContent']): hp.insert(all_videos, video) print('The TOP GENRE is ' + mayor + ' with ' + str(repsmax) + ' reproductions...') print(mayor + 'SENTIMENT ANALYSIS') if mayor == 'Metal': print('Metal has ' + str(me.getValue(mp.get(registropy, 'Metal_unique'))) + ' unique tracks...') for i in range(1, 11): video = hp.delMin(all_videos) vader_avg = 0 count = 0 for hashtag in lt.iterator(video['hashtag']): entry = om.get(analyzer['sentiment_values'], hashtag) if entry is not None: value = me.getValue(entry) lst = value['lstContent']['elements'][0]['vader_avg'] if lst != '': vader_avg += float(lst) count += 1 if count > 0: vader_avg /= count else: vader_avg = 0 print('TOP ' + str(i) + ' track: ' + video['track_id'] + ' with ' + str(lt.size(video['hashtag'])) + ' and VADER = ' + str(vader_avg))
def newAnalyzer(): """ Inicializa el analizador stops: Tabla de hash para guardar los vertices del grafo connections: Grafo para representar las rutas entre estaciones components: Almacena la informacion de los componentes conectados paths: Estructura que almancena los caminos de costo minimo desde un vertice determinado a todos los otros vértices del grafo """ try: analyzer = { 'agestartrank': None, 'agefinishrank': None, 'stops': None, 'connections': None, 'components': None, 'paths': None, 'nameverteces':None, 'countllegada':None, 'countsalida':None, 'heapsalida':None, 'heapllegada':None, 'heapllegadasalida':None, 'countllegadasalida':None } analyzer['stops'] = m.newMap(numelements=14000, maptype='PROBING', comparefunction=compareStopIds) analyzer['coordinates']= m.newMap(numelements=2000, maptype='PROBING', comparefunction=compareStopIds) analyzer['coordinates_destiny']= m.newMap(numelements=2000, maptype='PROBING', comparefunction=compareStopIds) analyzer['agestartrank'] = m.newMap(numelements=2000, maptype='PROBING', comparefunction=compareStopIds) analyzer['countllegada'] = m.newMap(numelements=2000, maptype='PROBING', comparefunction=compareStopIds) analyzer['countllegadasalida'] = m.newMap(numelements=2000, maptype='PROBING', comparefunction=compareStopIds) analyzer['countsalida'] = m.newMap(numelements=2000, maptype='PROBING', comparefunction=compareStopIds) analyzer['heapsalida'] = heap.newHeap(comparadorheap) analyzer['heapllegada'] = heap.newHeap(comparadorheap) analyzer['heapllegadasalida'] = heap.newHeap(comparadorheap) analyzer['agefinishrank'] = m.newMap(numelements=2000, maptype='PROBING', comparefunction=compareStopIds) analyzer['connections'] = gr.newGraph(datastructure='ADJ_LIST', directed=True, size=14000, comparefunction=compareStopIds) analyzer['nameverteces'] = m.newMap(numelements=2000, maptype='PROBING', comparefunction=compareStopIds) analyzer['bikeid'] = m.newMap(numelements=1000, maptype='PROBING', comparefunction=compareStopIds) return analyzer except Exception as exp: error.reraise(exp, 'model:newAnalyzer')