def insert(minpq, element):
    """
    Guarda el elemento 'element' en la cola de prioridad.
    Lo guarda en la última posición y luego hace swim del elemento
    Args:
        minpq: El arreglo con la informacion
        element: El elemento a guardar
    Returns:
        La MinPQ con el nuevo elemento
    Raises:
        Exception
    """
    try:
        minpq['heap'] = h.insert(minpq['heap'], element)
        return minpq
    except Exception as exp:
        error.reraise(exp, 'minpq:insert')
Beispiel #2
0
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))