예제 #1
0
def count_intervalINF(main, m, M):
    ans = {'events': 0, 'idlist': lt.newList('SINGLE_LINKED')}
    y = 1
    nums = om.keySet(main)

    while y <= lt.size(nums):
        num = lt.getElement(nums, y)
        pair = om.get(main, num)
        mini = me.getValue(pair)

        if float(om.minKey(mini)) > m: m == float(om.minKey(mini))
        if float(om.maxKey(mini)) < M: M == float(om.maxKey(mini))
        sub_nums = get_inter(om.keySet(mini), m, M)

        x = 1
        while x <= lt.size(sub_nums):
            sub_num = lt.getElement(sub_nums, x)
            sub_pair = om.get(mini, sub_num)
            events = me.getValue(sub_pair)

            z = 1
            while z <= lt.size(events):
                e = lt.getElement(events, z)
                id = e['artist_id']
                ans['events'] += 1
                ans['idlist'][id] = 1

                z += 1
            x += 1
        y += 1
    return ans
예제 #2
0
def reque2(main, e, E, d, D):
    if float(om.minKey(main)) > e: e == float(om.minKey(main))
    if float(om.maxKey(main)) < E: E == float(om.maxKey(main))
    nums = get_inter(om.keySet(main), e, E)

    ans = {'idlist': {}, 'for_show': lt.newList('SINGLE_LINKED')}
    y = 1
    while y <= lt.size(nums):
        num = lt.getElement(nums, y)
        pair = om.get(main, num)
        mini = me.getValue(pair)

        if float(om.minKey(mini)) > d: d == float(om.minKey(mini))
        if float(om.maxKey(mini)) < D: D == float(om.maxKey(mini))
        sub_nums = get_inter(om.keySet(mini), d, D)
        x = 1
        while x <= lt.size(sub_nums):
            sub_num = lt.getElement(sub_nums, x)
            sub_pair = om.get(mini, sub_num)
            events = me.getValue(sub_pair)

            z = 1
            while z <= lt.size(events):
                e = lt.getElement(events, z)
                id = e['track_id']
                lt.addFirst(ans['for_show'], e)
                ans['idlist'][id] = 1

                z += 1
            x += 1
        y += 1
    return ans
예제 #3
0
def reque1_SUP(main, m, M):
    if (float(om.minKey(main))) > m: m == (float(om.minKey(main)))
    if (float(om.maxKey(main))) < M: M == (float(om.maxKey(main)))
    nums = get_inter(om.keySet(main), m, M)
    dans = count_intervalSUP(main, nums)
    k = len(dans['id_list'].keys())
    ans = {'t_eve': dans['events'], 't_art': k}
    return ans
예제 #4
0
def auxiliardelaauxiliar(catalog, initial_date, final_date):
    """
    Retorna una tupla dependiendo si el rango abarca uno o dos años
    """
    initial_year = str(initial_date.year)
    final_year = str(final_date.year)

    initial_date_accidents = om.contains(catalog[initial_year], initial_date)
    final_date_accidents = om.contains(catalog[final_year], final_date)

    i = 0

    if i == 0 and initial_date_accidents and final_date_accidents:

        if initial_year == final_year:

            keylow = om.get(catalog[initial_year], initial_date)["key"]
            keyhigh = om.get(catalog[initial_year], final_date)["key"]

            return 0, om.keys(catalog[initial_year], keylow, keyhigh)

        else:

            keymax = om.maxKey(catalog[initial_year])
            dates_initial_year = om.keys(catalog[initial_year], initial_date,
                                         keymax)

            keymin = om.minKey(catalog[final_year])
            dates_final_year = om.keys(catalog[final_year], final_date, keymin)
            return 1, dates_initial_year, dates_final_year

    return None
예제 #5
0
def getAccidentsInRange(catalog, initial_date, final_date):
    """
    Reto3 - Req3
    Retorna el número de accidentes ocurridos en un rango de fechas
    """
    initial_year = str(initial_date.year)
    final_year = str(final_date.year)

    if initial_date == None and final_date == None:
        print("La fecha ingresada es errónea")
    else:

        if initial_year == final_year:

            keylow = om.get(catalog[initial_year], initial_date)["key"]
            keyhigh = om.get(catalog[initial_year], final_date)["key"]

            return 0, om.values(catalog[initial_year], keylow, keyhigh)
        else:

            keymax = om.maxKey(catalog[initial_year])
            dates_initial_year = om.values(catalog[initial_year], initial_date,
                                           keymax)

            keymin = om.minKey(catalog[final_year])
            dates_final_year = om.values(catalog[final_year], final_date,
                                         keymin)
            return 1, dates_initial_year, dates_final_year

    return None
예제 #6
0
def getAccidentsByRangeHour(analyzer, initialDate, fecha_final):
    lst = om.values(analyzer['hourIndex'], initialDate, fecha_final)
    lstiterator = it.newIterator(lst)
    tot_accidents = 0
    mapa = om.newMap(comparefunction=compareIds)
    mapa2 = om.newMap(comparefunction=compareIds)
    while (it.hasNext(lstiterator)):
        lstdate = it.next(lstiterator)
        accidentes_max = 0
        i = 1
        while i <= 4:
            num = getaccidentesByRangeCodeHour(analyzer, lstdate, str(i))
            tot_accidents += num
            accidentes_max += num
            i += 1
            if om.contains(mapa2, i):
                om.put(mapa2, i, int(om.get(mapa2, i)['value']) + num)
            else:
                om.put(mapa2, i, num)
        om.put(mapa, accidentes_max, str(lstdate))
    resu = om.newMap(comparefunction=compareIds)
    max_sev = 0
    sev = 0
    for i in range(1, 6):
        if om.contains(mapa2, i):
            val = om.get(mapa2, i)
            if val['value'] > max_sev:
                max_sev = val['value']
                sev = i
            om.put(resu, i, val['value'])
        else:
            om.put(resu, i, 0)
    om.put(resu, sev, max_sev)

    return tot_accidents, om.get(mapa, om.maxKey(mapa)), resu
예제 #7
0
def genero_escuchados(catalog, valor_minHora, valor_maxHora):
    """
    """
    total_reproducciones = lt.newList('ARRAY_LIST')
    lista_listas_reproducciones = lt.newList('ARRAY_LIST')
    generos = mp.keySet(catalog['musicaGenero'])
    iteratorgenero = it.newIterator(generos)
    while it.hasNext(iteratorgenero):
        genero = it.next(iteratorgenero)
        cantidad_genero = lt.newList('ARRAY_LIST')
        MapGeneros = mp.get(catalog['musicaGenero'], genero)
        RBTgenero = me.getValue(MapGeneros)
        valor_min = om.minKey(RBTgenero)
        valor_max = om.maxKey(RBTgenero)
        lista_listas_musica = om.values(RBTgenero, valor_min, valor_max)
        lista_lista_musica = it.newIterator(lista_listas_musica)
        while it.hasNext(lista_lista_musica):
            lista_musica = it.next(lista_lista_musica)
            musicas = it.newIterator(lista_musica)
            while it.hasNext(musicas):
                musica = it.next(musicas)
                fecha = musica['created_at']
                fecha = fecha[11:]
                if fecha >= valor_minHora and fecha <= valor_maxHora:
                    if lt.isPresent(cantidad_genero,
                                    (musica['created_at'] + musica['user_id'] +
                                     musica['track_id'])) == 0:
                        lt.addLast(cantidad_genero,
                                   (musica['created_at'] + musica['user_id'] +
                                    musica['track_id']))
                        if lt.isPresent(
                                total_reproducciones,
                            (musica['created_at'] + musica['user_id'] +
                             musica['track_id'])):
                            lt.addLast(
                                total_reproducciones,
                                (musica['created_at'] + musica['user_id'] +
                                 musica['track_id']))
                    else:
                        if lt.isPresent(
                                total_reproducciones,
                            (musica['created_at'] + musica['user_id'] +
                             musica['track_id'])):
                            lt.addLast(
                                total_reproducciones,
                                (musica['created_at'] + musica['user_id'] +
                                 musica['track_id']))
        lt.addLast(lista_listas_reproducciones,
                   (genero, lt.size(cantidad_genero)))
    print('Total of repruductions between ' + valor_minHora + ' and ' +
          valor_maxHora + ' is ' + str(lt.size(total_reproducciones)))
    sa.sort(lista_listas_reproducciones, cmptamanio)
    print('================= GENRES SORTED REPRODUCTIONS ===============')
    i = 1
    while i <= lt.size(lista_listas_reproducciones):
        print('TOP ' + str(i) + ': ' +
              str(lt.getElement(lista_listas_reproducciones, i)[0]) +
              ' with ' +
              str(lt.getElement(lista_listas_reproducciones, i)[1]) + ' reps')
        i += 1
예제 #8
0
def maxKey(analyzer):
    """
    Llave mas grande
    """

    respuesta = om.maxKey(analyzer['fechas'])

    return (respuesta)
예제 #9
0
def generos_existentes(catalog, generos):
    """
    Retorna en modo print la informacion de los generos
    """
    lista_repetidos_total = lt.newList('ARRAY_LIST')
    list_generos = generos.split(",")
    for genero in list_generos:
        artistasNoRepetidos = lt.newList('ARRAY_LIST')
        artistasRepetidos = lt.newList('ARRAY_LIST')
        MapGeneros = mp.get(catalog['musicaGenero'], genero)
        RBTgenero = me.getValue(MapGeneros)
        valor_min = om.minKey(RBTgenero)
        valor_max = om.maxKey(RBTgenero)
        lista_listas_musica = om.values(RBTgenero, valor_min, valor_max)
        lista_lista_musica = it.newIterator(lista_listas_musica)
        while it.hasNext(lista_lista_musica):
            lista_musica = it.next(lista_lista_musica)
            musicas = it.newIterator(lista_musica)
            while it.hasNext(musicas):
                musica = it.next(musicas)
                if int(lt.isPresent(artistasNoRepetidos,
                                    musica['artist_id'])) == 0:
                    lt.addLast(artistasNoRepetidos, musica['artist_id'])
                    if int(
                            lt.isPresent(
                                artistasRepetidos,
                                (musica['created_at'] + musica['user_id'] +
                                 musica['track_id']))) == 0:
                        lt.addLast(artistasRepetidos,
                                   (musica['created_at'] + musica['user_id'] +
                                    musica['track_id']))
                        #if int(lt.isPresent(lista_repetidos_total, (musica['created_at'] + musica['user_id'] + musica['track_id']))) == 0:
                        #   lt.addLast(lista_repetidos_total, (musica['created_at'] + musica['user_id'] + musica['track_id']))
                else:
                    if int(
                            lt.isPresent(
                                artistasRepetidos,
                                (musica['created_at'] + musica['user_id'] +
                                 musica['track_id']))) == 0:
                        lt.addLast(artistasRepetidos,
                                   (musica['created_at'] + musica['user_id'] +
                                    musica['track_id']))
                        #if int(lt.isPresent(lista_repetidos_total, (musica['created_at'] + musica['user_id'] + musica['track_id']))) == 0:
                        #   lt.addLast(lista_repetidos_total, (musica['created_at'] + musica['user_id'] + musica['track_id']))

        print(
            str(genero) + ' is between ' + str(valor_min) + ' and ' +
            str(valor_max))
        print('Total of reproduction: ' + str(lt.size(artistasRepetidos)) +
              ' Total of unique artists: ' + str(lt.size(artistasNoRepetidos)))
        print('---------------  Some artists for ' + str(genero) +
              ' -----------')
        i = 0
        while i <= 9:
            print('Artist ' + str(i) + ': ' +
                  lt.getElement(artistasNoRepetidos, i))
            i += 1
    print('Total of reproduction is ' + str(lt.size(lista_repetidos_total)))
예제 #10
0
def Req5Anexo(arbol):
    i = 0
    while i < 3:
        mayorVader = om.maxKey(arbol)
        evento = me.getValue(om.get(arbol, mayorVader))
        print('El evento con track_id:', evento['track_id'], 'con un Vader de',
              mayorVader)
        om.deleteMax(arbol)
        i += 1
def infAnalyzer(analyzer):
    """
    Dado un analizador retorna informacion sobre este.
    """
    high = om.height(analyzer['dateIndex'])
    nodes = om.size(analyzer['dateIndex'])
    min_key = om.minKey(analyzer['dateIndex'])
    max_key = om.maxKey(analyzer['dateIndex'])
    return (high, nodes, min_key, max_key)
예제 #12
0
def tercera_consulta(citibike):
    tree = om.newMap(omaptype='RBT', comparefunction=compareroutes)
    diccionario = {}
    list_vertext = gr.vertices(citibike["graph"])
    ite = it.newIterator(list_vertext)
    while it.hasNext(ite):
        vertex = it.next(ite)
        arrive = gr.indegree(citibike["graph"], vertex)
        if arrive > 0:
            om.put(tree, arrive, vertex)
    l = []
    number = om.size(tree)
    resta = abs(number - 3)
    less = om.select(tree, resta)
    greater = om.maxKey(tree)
    ran = om.values(tree, less, greater)
    i = it.newIterator(ran)
    while it.hasNext(i):
        name = it.next(i)
        l.append(name)
    diccionario["llegadas"] = l

    tree_1 = om.newMap(omaptype='RBT', comparefunction=compareroutes)
    list_vertext_1 = gr.vertices(citibike["graph"])
    ite_1 = it.newIterator(list_vertext_1)
    while it.hasNext(ite_1):
        vertex_1 = it.next(ite_1)
        arrive_1 = gr.outdegree(citibike["graph"], vertex_1)
        if arrive_1 > 0:
            om.put(tree_1, arrive_1, vertex_1)
    print((citibike["graph"]))
    l_1 = []
    number_1 = om.size(tree_1)
    resta_1 = abs(number_1 - 3)
    less_1 = om.select(tree_1, resta_1)
    greater_1 = om.maxKey(tree_1)
    ran_1 = om.values(tree_1, less_1, greater_1)
    iterar = it.newIterator(ran_1)
    while it.hasNext(iterar):
        name_1 = it.next(iterar)
        l_1.append(name_1)
    diccionario["salidas"] = l_1

    return diccionario
예제 #13
0
def AccidentesPorZona(
    analyzer,
    RadioParametro,
    LongitudParametro,
    LatitudParametro,
):
    TotalAccidentes = 0
    Fechas = om.keys(analyzer["Llaves"], om.minKey(analyzer["Llaves"]),
                     om.maxKey(analyzer["Llaves"]))
    Lunes = 0
    Martes = 0
    Miercoles = 0
    Jueves = 0
    Viernes = 0
    Sabado = 0
    Domingo = 0
    for i in range(1, (lt.size(Fechas) + 1)):
        Fecha = lt.getElement(Fechas, i)
        Pareja = om.get(analyzer["Llaves"], Fecha)
        Accidentes = me.getValue(Pareja)
        Numero = lt.size(Accidentes)
        TotalAccidentes = TotalAccidentes + Numero
        for j in range(1, (lt.size(Accidentes) + 1)):
            Accidente = lt.getElement(Accidentes, j)
            if CalculoDeRadio(RadioParametro, LongitudParametro,
                              LatitudParametro, float(Accidente["Start_Lng"]),
                              float(Accidente["Start_Lat"])):
                dia = Dia(Fecha)
                if dia == "Lunes":
                    Lunes += 1
                elif dia == "Martes":
                    Martes += 1
                elif dia == "Miercoles":
                    Miercoles += 1
                elif dia == "Jueves":
                    Jueves += 1
                elif dia == "Viernes":
                    Viernes += 1
                elif dia == "Sabado":
                    Sabado += 1
                elif dia == "Domingo":
                    Domingo += 1

    Total = Lunes + Martes + Miercoles + Jueves + Viernes + Sabado + Domingo
    Retorno = lt.newList("ARRAY_LIST", compareIds)
    lt.addLast(Retorno, Lunes)
    lt.addLast(Retorno, Martes)
    lt.addLast(Retorno, Miercoles)
    lt.addLast(Retorno, Jueves)
    lt.addLast(Retorno, Viernes)
    lt.addLast(Retorno, Sabado)
    lt.addLast(Retorno, Domingo)
    lt.addLast(Retorno, Total)
    return Retorno
예제 #14
0
def test_contains(tree):
    tree = om.put(tree, 21, 'book21')
    tree = om.put(tree, 7, 'book7')
    tree = om.put(tree, 30, 'book30')
    tree = om.put(tree, 5, 'book5')
    tree = om.put(tree, 4, 'book4')
    tree = om.put(tree, 3, 'book3')
    tree = om.put(tree, 20, 'book20')
    tree = om.put(tree, 25, 'book25')
    tree = om.put(tree, 35, 'book35')
    tree = om.put(tree, 29, 'book29')
    tree = om.put(tree, 11, 'book11')
    tree = om.put(tree, 15, 'book15')
    tree = om.put(tree, 10, 'book10')
    tree = om.put(tree, 10, 'book10A')
    assert om.contains(tree, 29) is True
    assert om.contains(tree, 50) is False
    assert om.minKey(tree) == 3
    assert om.maxKey(tree) == 35
    tree = om.put(tree, 50, 'book50')
    assert om.contains(tree, 50) is True
    assert om.maxKey(tree) == 50
예제 #15
0
def majorDestiny(grafo):
    intree = om.newMap(omaptype="RBT", comparefunction=compareIds)
    pqiterator = it.newIterator(vertexNamesAge(grafo))
    while it.hasNext(pqiterator):
        vert = it.next(pqiterator)
        salidas = gr.indegree(grafo, vert)
        om.put(intree, salidas, vert)
    if om.isEmpty(intree):
        return None
    else:
        mayor = om.get(intree, om.maxKey(intree))
        mayornombre = me.getValue(mayor)
        return mayornombre
예제 #16
0
def bono(mapa, punto_referencia1, punto_referencia2, radio):
    fecha1 = om.minKey(mapa["a-fecha"])
    fecha2 = om.maxKey(mapa["a-fecha"])
    a_iterar = om.values(mapa["a-fecha"], fecha1, fecha2)
    a_comparar = Bono.distance(punto_referencia1, punto_referencia2, radio)
    xd = lt.newList("ARRAY_LIST")
    for i in range(1, lt.size(a_iterar) + 1):
        accidentes = lt.getElement(a_iterar, i)["accidentes_en_esta_fecha"]
        for e in range(1, lt.size(accidentes) + 1):
            elemento = lt.getElement(accidentes, e)
            if (Bono.distance(punto_referencia1,
                              elemento["Start_Lat"] + elemento["Start_Lng"],
                              radio) == a_comparar):
                lt.addLast(elemento["Start_Time"])
예제 #17
0
def failImpact(analyzer, landingPoint):
    delta_time = -1.0
    delta_memory = -1.0

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

    landingPoint = landingPoint.replace(' ', '').lower()

    answer = model.failImpact(analyzer, landingPoint)

    result = answer[1]

    countries = []

    while om.size(result) > 0:
        distance = om.maxKey(result)
        countriesList = me.getValue(om.get(result, om.maxKey(result)))

        for country in lt.iterator(countriesList):
            countries.append({'country': country, 'distance': distance})

        om.remove(result, distance)

        # country = me.getValue(om.get(result, om.maxKey(result)))
        # countries.append({'country': country, 'distance': om.maxKey(result)})
        # om.deleteMax(result)

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

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

    return analyzer, answer[0], countries, delta_time, delta_memory
예제 #18
0
def auxiliarYearIterator(catalog,year_iterator,criteria,down_limit_date,up_limit_date):
    """
    Función Axuiliar de las funciones Auxiliares.
    """
    if criteria == 0:                   #Caso único para getInRange cuando el rango no soprepasa un año. 
        keylow = om.get(catalog[year_iterator],down_limit_date)['key']
        keyhigh =  om.get(catalog[year_iterator],up_limit_date)['key']
        Year_Dates = om.keys(catalog[year_iterator],keylow,keyhigh)

    elif criteria == 1:                 #Caso en el que se necesita las fechas de todo el año. 
        keyhigh = om.maxKey(catalog[year_iterator])
        keylow = om.minKey(catalog[year_iterator])
        Year_Dates = om.keys(catalog[year_iterator],keylow,keyhigh)
    
    elif criteria == 2:                 #Caso en el que dada una fecha límite superior, se busca la menor llave del árbol.
        keylow = om.minKey(catalog[year_iterator])
        keyhigh = om.get(catalog[year_iterator],up_limit_date)['key']
        Year_Dates = om.keys(catalog[year_iterator],keylow,keyhigh)

    elif criteria == 3:                 #Caso en el que dada una fecha límite inferior, se busca la mayor llave del árbol.
        keyhigh = om.maxKey(catalog[year_iterator])
        keylow = om.get(catalog[year_iterator],down_limit_date)['key']      
        Year_Dates = om.keys(catalog[year_iterator],keylow,keyhigh)
    return Year_Dates
def RankingServicios(analyzer, topN):

    # print(taxisPorCompania)
    RankingFinal = lt.newList(datastructure='SINGLE_LINKED', cmpfunction=None)
    rangoRanking = 0

    serviciosPorCompania = ServiciosPorCompania(analyzer)
    while rangoRanking < topN:
        if serviciosPorCompania is not None:
            MayorValor = om.maxKey(serviciosPorCompania)
            nombre_compania = om.get(serviciosPorCompania, MayorValor)
            lt.addLast(RankingFinal, nombre_compania)
            if om.contains(serviciosPorCompania, MayorValor):
                om.remove(serviciosPorCompania, MayorValor)
                rangoRanking += 1

    return RankingFinal
예제 #20
0
def llavesEnRango(cont, initialDate, finalDate, anio):
    llaves = {}
    if anio['type'] == 0:
        llaves[anio['anio']] = om.keys(cont[anio['anio']][0]['dateIndex'],
                                       initialDate, finalDate)
    else:
        for i in range(int(str(initialDate)[:4]), int(str(finalDate)[:4]) + 1):
            if str(i) in str(initialDate):
                mayor = om.maxKey(cont[str(i)][0]['dateIndex'])
                llaves[str(i)] = om.keys(cont[str(i)][0]['dateIndex'],
                                         initialDate, mayor)
            elif str(i) in str(finalDate):
                menor = om.minKey(cont[str(i)][0]['dateIndex'])
                llaves[str(i)] = om.keys(cont[str(i)][0]['dateIndex'], menor,
                                         finalDate)
            else:
                llaves[str(i)] = om.keySet(cont[str(i)][0]['dateIndex'])
    return llaves
예제 #21
0
def cargarporanio(cont, anio):
    if cont[anio][0] != None:
        accidentfile = cont[anio][1]
        print("\nCargando información de accidentes .....")
        controller.loadData(cont[anio][0], accidentfile)
        print('Accidentes cargados: ' +
              str(controller.accidentsSize(cont[anio][0])))
        print('Altura del arbol: ' +
              str(controller.indexHeight(cont[anio][0])[0]))
        print('Elementos en el arbol: ' +
              str(controller.indexSize(cont[anio][0])[0]))
        print('Menor Llave: ' + str(controller.minKey(cont[anio][0])))
        print('Mayor Llave: ' + str(controller.maxKey(cont[anio][0])))

        print('Accidentes cargados: ' +
              str(controller.accidentsSize(cont[anio][0])))
        print('Altura del arbol: ' +
              str(controller.indexHeight(cont[anio][0])[1]))
        print('Elementos en el arbol: ' +
              str(controller.indexSize(cont[anio][0])[1]))
        print('Menor Llave: ' + str(om.minKey(cont[anio][0]['timeIndex'])))
        print('Mayor Llave: ' + str(om.maxKey(cont[anio][0]['timeIndex'])))
def getAccidentsByGeographicZone(analyzer, longitud, latitud, radio):
    cant_accidentes = om.size(analyzer['dateIndex'])
    llaves = om.keys(analyzer['dateIndex'], om.minKey(analyzer['dateIndex']),
                     om.maxKey(analyzer['dateIndex']))
    accidentes = m.newMap(numelements=17,
                          prime=109345121,
                          maptype='CHAINING',
                          loadfactor=0.5,
                          comparefunction=compararDias)
    accidentes_reportados = 0
    i = 1
    while i <= cant_accidentes:
        fecha = om.get(analyzer['dateIndex'], lt.getElement(llaves, i))
        lista_accidentes = fecha['value']['lstaccidents']
        j = 1
        while j <= lt.size(lista_accidentes):
            accidente = lt.getElement(lista_accidentes, j)
            long = float(accidente['Start_Lng'])
            lat = float(accidente['Start_Lat'])
            distancia = haversine(longitud, latitud, long, lat)
            if distancia <= radio:
                fecha = accidente['Start_Time']
                anio = fecha[:4]
                mes = fecha[5:7]
                dia = fecha[8:10]
                dia_semana = calcular_dia(int(dia), int(mes), int(anio))
                esta_dia = m.contains(accidentes, dia_semana)
                if not esta_dia:
                    lista = lt.newList(datastructure='SINGLE_LINKED',
                                       cmpfunction=None)
                    m.put(accidentes, dia_semana, lista)
                lis = m.get(accidentes, dia_semana)
                lis = lis['value']
                lt.addLast(lis, accidente)
                m.put(accidentes, dia_semana, lis)
                accidentes_reportados += 1
            j += 1
        i += 1
    return accidentes_reportados, accidentes
def test_remove(tree):
    tree = om.put(tree, 21, 'book21')
    tree = om.put(tree, 7, 'book7')
    tree = om.put(tree, 30, 'book30')
    tree = om.put(tree, 5, 'book5')
    tree = om.put(tree, 4, 'book4')
    tree = om.put(tree, 3, 'book3')
    tree = om.put(tree, 20, 'book20')
    tree = om.put(tree, 25, 'book25')
    tree = om.put(tree, 35, 'book35')
    tree = om.put(tree, 29, 'book29')
    tree = om.put(tree, 11, 'book11')
    tree = om.put(tree, 15, 'book15')
    tree = om.remove(tree, 21)
    tree = om.put(tree, 10, 'book10')
    tree = om.put(tree, 10, 'book10A')
    assert om.contains(tree, 29) is True
    assert om.contains(tree, 28) is False
    assert om.minKey(tree) == 3
    assert om.maxKey(tree) == 35
    om.deleteMin(tree)
    assert om.contains(tree, 3) is False
예제 #24
0
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
예제 #25
0
def Accidentes_en_radio(catalog, latitud, longitud, radio, medida_r):
    if medida_r == "M":
        radio = float(radio) * 1.609
    else:
        radio = float(radio)
    Latitud = float(latitud) / 57.29577951
    Longitud = float(longitud) / 57.29577951
    total = 0
    maximo = om.maxKey(catalog['Indice_fechas'])
    minimo = om.minKey(catalog['Indice_fechas'])
    Valores = om.values(catalog['Indice_fechas'], minimo, maximo)
    iterador = it.newIterator(Valores)
    Diccionario = {}
    while it.hasNext(iterador):
        valor = it.next(iterador)
        lista = valor["Accidentes"]
        iterador2 = it.newIterator(lista)
        while it.hasNext(iterador2):
            accidente = it.next(iterador2)
            latitud2 = float(accidente["Start_Lat"]) / 57.29577951
            longitud2 = float(accidente["Start_Lng"]) / 57.29577951
            distancia = 3963.0 * math.acos(
                math.sin(Latitud) * math.sin(latitud2) + math.cos(Latitud) *
                math.cos(latitud2) * math.cos(longitud2 - Longitud))
            distancia *= 1.609344
            if distancia <= radio:
                total += 1
                Fecha = accidente['Start_Time']
                Fecha_accidente = datetime.datetime.strptime(
                    Fecha, '%Y-%m-%d %H:%M:%S')
                if Fecha_accidente.date() not in Diccionario:
                    Diccionario[Fecha_accidente.date()] = 0
                    Diccionario[Fecha_accidente.date()] += 1
                else:
                    Diccionario[Fecha_accidente.date()] += 1
    return Diccionario, total
def maxKey(analyzer):

    return om.maxKey(analyzer['dateIndex'])
예제 #27
0
def maxKey(analyzer):
    """
    Llave mas grande
    """
    return om.maxKey(analyzer['dateIndex'])
def DistanceMaxKey(analyzer):
    return om.maxKey(analyzer['DistanceIndex'])
def TimeMaxKey(analyzer):
    return om.maxKey(analyzer['TimeIndex'])
예제 #30
0
def maxKey(analyzer):
    """Numero de autores leido
    """
    return om.maxKey(analyzer['dates'])