Example #1
0
def addStop(citibike, stationid, latitude, longitude, edad, s_ll, type):
    if m.contains(citibike['stops'], stationid):
        retorno = m.get(citibike['stops'], stationid)['value']
        m.remove(citibike['stops'], stationid)
    else:
        retorno = [
            latitude, longitude, {
                '0-10': 0,
                '11-20': 0,
                '21-30': 0,
                '31-40': 0,
                '41-50': 0,
                '51-60': 0,
                '60+': 0,
                'total': 0
            }, {
                '0-10': 0,
                '11-20': 0,
                '21-30': 0,
                '31-40': 0,
                '41-50': 0,
                '51-60': 0,
                '60+': 0,
                'total': 0
            }, type
        ]
    if s_ll == 's':
        a = 2
    else:
        a = 3

    if edad in range(0, 11):
        nuevo = retorno[a].get('0-10') + 1
        retorno[a]['0-10'] = nuevo
    elif edad in range(11, 21):
        nuevo = retorno[a].get('11-20') + 1
        retorno[a]['11-20'] = nuevo
    elif edad in range(21, 31):
        nuevo = retorno[a].get('21-30') + 1
        retorno[a]['21-30'] = nuevo
    elif edad in range(31, 41):
        nuevo = retorno[a].get('31-40') + 1
        retorno[a]['31-40'] = nuevo
    elif edad in range(41, 51):
        nuevo = retorno[a].get('41-50') + 1
        retorno[a]['41-50'] = nuevo
    elif edad in range(51, 61):
        nuevo = retorno[a].get('51-60') + 1
        retorno[a]['51-60'] = nuevo
    else:
        nuevo = retorno[a].get('60+') + 1
        retorno[a]['60+'] = nuevo

    nuevo = retorno[a].get('total') + 1
    retorno[a]['total'] = nuevo

    m.put(citibike['stops'], stationid, retorno)

    return citibike
Example #2
0
def add_director(catalog, director_name, id):
    existdirector = mp.contains(catalog['directors'], director_name)
    if existdirector:
        pareja = mp.get(catalog["directors"], director_name)
        nuevalista = lista = me.getValue(pareja)
        nuevalista.append(id)
        mp.remove(catalog["directors"], director_name)
        mp.put(catalog['directors'], director_name, nuevalista)
    else:
        nuevalista = []
        nuevalista.append(id)
        mp.put(catalog['directors'], director_name, nuevalista)
Example #3
0
def test_remove(map):
    assert ht.size(map) == 12
    assert ht.contains(map, '3') is True
    ht.remove(map, '3')
    assert ht.size(map) == 11
    assert ht.contains(map, '3') is False
    entry = ht.get(map, '110')
    assert entry is None
    ht.put(map, '110', 'title 110')
    ht.put(map, '111', 'title 111')
    ht.put(map, '112', 'title 112')
    ht.put(map, '113', 'title 113')
    ht.put(map, '114', 'title 114')
    ht.put(map, '115', 'title 115')
    assert ht.size(map) == 17
    ht.put(map, '110', 'title 110-new')
    ht.put(map, '111', 'title 111-new')
    ht.put(map, '112', 'title 112-new')
    ht.put(map, '113', 'title 113-new')
    ht.put(map, '114', 'title 114-new')
    ht.put(map, '115', 'title 115-new')
    assert ht.size(map) == 17
    entry = ht.get(map, '110')
    assert me.getValue(entry) == 'title 110-new'
    entry = ht.remove(map, '110')
    entry = ht.remove(map, '111')
    entry = ht.remove(map, '112')
    entry = ht.remove(map, '113')
    entry = ht.remove(map, '114')
    entry = ht.remove(map, '115')
    assert ht.size(map) == 11
Example #4
0
def hastags(catalog, evento):
    tiempo = datetime.datetime.strptime(evento['created_at'],
                                        '%Y-%m-%d %H:%M:%S')
    tupla = (evento['track_id'], evento['user_id'], tiempo)
    evento['created_at'] = tiempo
    if mp.contains(catalog['eventos'], tupla):
        aguacate = mp.get(catalog['eventos'], tupla)
        evento_map = me.getValue(aguacate)
        lt.addLast(evento_map['hashtag'], evento['hashtag'])
        mp.remove(catalog['eventos'], tupla),
        mp.put(catalog['eventos'], tupla, evento_map)
    else:
        hashtag = evento['hashtag']
        evento['hashtag'] = lt.newList(datastructure='SINGLE_LINKED')
        lt.addLast(evento['hashtag'], hashtag)
        mp.put(catalog['eventos'], tupla, evento)
    return catalog
def theTop(mapa):
    res = []
    while len(res) < 3:
        topv = 0
        keys = m.keySet(mapa)
        values = m.valueSet(mapa)
        itv = it.newIterator(values)
        itk = it.newIterator(keys)
        while it.hasNext(itv):
            value = it.next(itv)
            key = it.next(itk)
            if value > topv:
                topv = value
                topk = key
        res.append(topk)
        m.remove(mapa, topk)
    return res
def addCompany(analyzer, company_name, taxiid, trip):
    exist_company = m.contains(analyzer['mapcompany'], company_name)
    if exist_company:
        entry = m.get(analyzer['mapcompany'], company_name)
        entry = me.getValue(entry)
        entry["Cantidad de servicios: "] += 1
        if not m.contains(analyzer["taxids"], taxiid):
            entry["taxis: "] += 1
            m.remove(analyzer["taxids"], taxiid)
    else:
        company = Newcompany(company_name)
        m.put(analyzer['mapcompany'], company_name, company)
        entry = m.get(analyzer['mapcompany'], company_name)
        entry = me.getValue(entry)
        if not m.contains(analyzer["taxids"], taxiid):
            entry["taxis: "] += 1
            m.remove(analyzer["taxids"], taxiid)
def theNoTop(mapa, mayor):
    res = []
    while len(res) < 3:
        couple = m.get(mapa, mayor)
        ntopv = couple['value']
        keys = m.keySet(mapa)
        values = m.valueSet(mapa)
        itv = it.newIterator(values)
        itk = it.newIterator(keys)
        while it.hasNext(itv):
            value = it.next(itv)
            key = it.next(itk)
            if value < ntopv:
                ntopv = value
                ntopk = key
        res.append(ntopk)
        m.remove(mapa, ntopk)

    return res
def req4(catalog, country, tag, n):
    delta_time = -1.0
    delta_memory = -1.0

    tracemalloc.start()
    start_time = getTime()
    start_memory = getMemory()

    lista = model.getvidsby(catalog, 'countries', country)
    if lista == None:
        print('\nNO HAY INFORMACIÓN PARA ESTE PAÍS\n')
    else:
        lista2 = model.tags(catalog, lista, tag)
        if lt.size(lista2) == 0:
            print('\nNO HAY INFORMACIÓN PARA ESTE TAG\n')
        else:
            mapa = model.titleporidc('likes', lista2, 'title')
            i = 1
            print('\nINFORMACIÓN DE LOS ' + str(n) +
                  ' VIDEOS CON MÁS LIKES EN ' + country.upper() +
                  ' CON EL TAG ' + tag.upper())
            while i <= n and mp.size(mapa) != 0:
                x = model.dlv(catalog, mapa, 'likes')
                info = x[1]
                print('\nPUESTO ' + str(i) + '\ntitle: ' + info['title'] +
                      ' || channel_title: ' + info['channel_title'] +
                      ' || publish_time: ' + info['publish_time'] +
                      ' || views: ' + info['views'] + ' || likes: ' +
                      str(x[2]) + ' || dislikes: ' + info['dislikes'] +
                      '\ntags: ' + info['tags'])
                print(info['video_id'])
                mp.remove(mapa, x[0])
                i += 1
                print('\n')

    stop_memory = getMemory()
    stop_time = getTime()
    tracemalloc.stop()

    delta_time = stop_time - start_time
    delta_memory = deltaMemory(start_memory, stop_memory)

    return delta_time, delta_memory
def req1(catalog, country, category, n):
    delta_time = -1.0
    delta_memory = -1.0

    tracemalloc.start()
    start_time = getTime()
    start_memory = getMemory()

    lista = model.getvidsby(catalog, 'countries', country)
    ide = model.idporcategory(category, catalog)
    if lista == None or ide == None:
        print('\nNO HAY INFORMACIÓN PARA ESTE PAÍS O CATEGORÍA\n')
    else:
        mapa = model.countryid(lista, ide)
        i = 1
        print('\nINFORMACIÓN DE LOS ' + str(n) + ' VIDEOS CON MÁS VIEWS EN ' +
              country.upper() + ' PARA LA CATEGORÍA ' + category.upper())
        while i <= n and mp.size(mapa) != 0:
            x = model.dlv(catalog, mapa, 'views')
            info = x[1]
            print('\nPUESTO ' + str(i) + '\ntrending_date: ' +
                  str(info['trending_date']) + ' || title: ' + info['title'] +
                  ' || channel_title: ' + info['channel_title'] +
                  ' || publish_time: ' + info['publish_time'] + ' || views: ' +
                  str(x[2]) + ' || likes: ' + info['likes'] +
                  ' || dislikes: ' + info['dislikes'])
            mp.remove(mapa, x[0])
            i += 1
            print('\n')

    stop_memory = getMemory()
    stop_time = getTime()
    tracemalloc.stop()

    delta_time = stop_time - start_time
    delta_memory = deltaMemory(start_memory, stop_memory)

    return delta_time, delta_memory
Example #10
0
def getFirstVideoByTrendDays(catalog):
    """
    Retorna el video con mayor número de trending days
    """
    videoidsmap = mp.newMap(200000,
                            maptype='CHAINING',
                            loadfactor=4.0,
                            comparefunction=compareMapVideosids)
    try:
        for video in lt.iterator(catalog):
            videoid = video['video_id']
            existvideoid = mp.contains(videoidsmap, videoid)
            if existvideoid:
                entry = mp.get(videoidsmap, videoid)
                id = me.getValue(entry)
            else:
                id = newVideoid(videoid)
                mp.put(videoidsmap, videoid, id)
            lt.addLast(id['videos'], video)
            id['trendingdays'] = lt.size(id['videos'])
    except Exception:
        return None

    mp.remove(videoidsmap, '#NAME?')
    videoids = mp.keySet(videoidsmap)

    try:
        maxTrendDays = 0
        firstVideo = None
        for videoid in lt.iterator(videoids):
            entry = mp.get(videoidsmap, videoid)
            trendDays = me.getValue(entry)['trendingdays']
            if trendDays > maxTrendDays:
                maxTrendDays = trendDays
                firstVideo = entry
        return firstVideo
    except Exception:
        return None
Example #11
0
def delMin(iheap):
    """
    Retorna el menor elemento del heap y lo elimina.
    Se reemplaza con el último elemento y se hace sink.

    Args:
        iheap: El heap a revisar
    Returns:
       La llave asociada al mayor indice
    Raises:
        Exception
    """
    try:
        if (iheap['size'] > 0):
            minIdx = lt.getElement(iheap['elements'], 1)
            exchange(iheap, 1, iheap['size'])
            iheap['size'] -= 1
            sink(iheap, 1)
            map.remove(iheap['qpMap'], minIdx['key'])
            return minIdx['key']
        return None
    except Exception as exp:
        error.reraise(exp, 'indexheap:delMin')
Example #12
0
def obtainValues(citibike,lst,method):
    """
    Agrega los ID de las estaciones a su lista correspondiente
    """
    if method == 'e':
        exitValues = m.valueSet(citibike['exitStations'])
        stationId = ''
        value = 0
        iterator = it.newIterator(exitValues)
        while it.hasNext(iterator):
            info = it.next(iterator)
            if info['trips'] > value:
                value = info['trips']
                stationId = info['name']
        m.remove(citibike['exitStations'],stationId)
        lt.addLast(lst,stationId)
    elif method == 'a':
        arriveValues = m.valueSet(citibike['arriveStations'])
        stationId = ''
        value = 0
        iterator = it.newIterator(arriveValues)
        while it.hasNext(iterator):
            info = it.next(iterator)
            if info['trips'] > value:
                value = info['trips']
                stationId = info['name']
        m.remove(citibike['arriveStations'],stationId)
        lt.addLast(lst,stationId)
    elif method == 't':
        totalValues = m.valueSet(citibike['totalStations'])
        stationId = ''
        value = 1000000
        iterator = it.newIterator(totalValues)
        while it.hasNext(iterator):
            info = it.next(iterator)
            if info['trips'] < value:
                value = info['trips']
                stationId = info['name']
        m.remove(citibike['totalStations'],stationId)
        lt.addLast(lst,stationId)
Example #13
0
        return 0
    elif (key > key2):
        return 1
    else:
        return -1

tablaDeSimbolos = mp.newMap(numelements=2,
                            maptype='PROBING',
                            comparefunction=cmpFunction)
#put
mp.put(tablaDeSimbolos, 'llave1', 'valor1')
mp.put(tablaDeSimbolos, 'llave2', 'valor2')
mp.put(tablaDeSimbolos, 'llave3', 'valor3')

#contains
print(mp.contains(tablaDeSimbolos, 'x'))

#get
v = mp.get(tablaDeSimbolos, 'llave1')
print(v['value'])

# #delete
mp.remove(tablaDeSimbolos, 'llave2')


# #Iterar
print()

for key in lt.iterator(mp.keySet(tablaDeSimbolos)):
  print(key, ': ', mp.get(tablaDeSimbolos, key)['value'])
Example #14
0
def removeGender(analyzer, name_gen):
    mp.remove(analyzer['Genders'], name_gen)
    return None
Example #15
0
#Buscar un valor, GET
print(map.get(comidas, "manzana")["value"])

print()

# #Recorrer todas las llaves, KEYS
keys = map.keySet(comidas)
i = listiterator.newIterator(keys)
while listiterator.hasNext(i):
    k = listiterator.next(i)
    print(k)

print()

# #Recorrer las llaves y los valores
keys = map.keySet(comidas)
i = listiterator.newIterator(keys)
while listiterator.hasNext(i):
    k = listiterator.next(i)
    v = map.get(comidas, k)["value"]
    print(k, v)

# #Remplazar un valor, PUT
map.put(comidas, "espinaca", "comida verde")

# #Eliminar un valor, DELETE
# del comidas["espinaca"]
map.remove(comidas, "espinaca")

print()
Example #16
0
def TaxisbyRange(catalog, initialDate,
                 finalDate):  # Taxis de acuerdo a la fecha seleccionada
    lst = om.values(catalog['date_index'], initialDate, finalDate)
    listiterator = it.newIterator(lst)
    while it.hasNext(listiterator):
        lstdate = it.next(listiterator)['lsttaxis']
        iterator_2 = it.newIterator(lstdate)
        while it.hasNext(iterator_2):
            taxis_id = it.next(iterator_2)['taxi_id']
            money = it.next(iterator_2)['trip_total']
            miles = it.next(iterator_2)['trip_miles']
            if money != "" and miles != "" and taxis_id != "" and taxis_id != 'NA':
                existtaxi = m.contains(catalog['taxis_filter'], taxis_id)
                taxis = catalog['taxis_filter']
                if existtaxi:
                    entry = m.get(taxis, taxis_id)
                    taxiss = me.getValue(entry)
                else:
                    taxiss = new_taxi(taxis_id)
                    m.put(taxis, taxis_id, taxiss)

                taxiss['services'] += 1
                taxiss['money'] += float(money)
                taxiss['miles'] += float(miles)

                # Cálculo de puntos

                puntos = alpha_fuction(taxiss['miles'], taxiss['money'],
                                       taxiss['services'])
                taxiss['points'] = puntos
            else:
                None

    lst = m.keySet(catalog['taxis_filter'])
    iterator = it.newIterator(lst)
    lista_taxis = []
    mayor = []

    while it.hasNext(iterator):
        taxis = it.next(iterator)
        points = m.get(catalog['taxis_filter'], taxis)['value']
        if points['miles'] != 0.0 and points['money'] != 0.0:
            lista_taxis.append(points)
            m.remove(catalog['taxis_filter'], taxis)

    if len(lista_taxis) == 0:
        print('No se registran taxis, vuelva a intentarlo')
        mayor = None
    else:
        while len(lista_taxis) - 1 != 0:
            for i in range(len(lista_taxis) - 1):
                if lista_taxis[i]['points'] >= lista_taxis[i + 1]['points']:
                    aux = lista_taxis[i]
                    lista_taxis[i] = lista_taxis[i + 1]
                    lista_taxis[i + 1] = aux

            mayor_taxi = lista_taxis.pop(len(lista_taxis) - 1)
            mayor.append(mayor_taxi)
        print('\nSe tienen ' + str(len(mayor)) +
              ' taxis, seleccione un número menor o igual\n')
    return mayor