コード例 #1
0
def ObtenerAccidentesPorHora(lst):
    lista=[]
    dik={"Severidad1":0,"Severidad2":0,"Severidad3":0,"Severidad4":0}
    m=0
    iterator = it.newIterator(lst)
    while it.hasNext(iterator):
        itet=it.next(iterator)
        tamanor=lt.size(itet["listaccidentes"])
        i=0
        while i!=tamanor:
            iterator3=it.newIterator(itet["listaccidentes"])
            while it.hasNext(iterator3):
                itat=it.next(iterator3)
                if int(itat["Severity"])==1:
                    dik["Severidad1"]=dik["Severidad1"]+1
                elif int(itat["Severity"])==2:
                    dik["Severidad2"]=dik["Severidad2"]+1
                elif int(itat["Severity"])==3:
                    dik["Severidad3"]=dik["Severidad3"]+1
                elif int(itat["Severity"])==4:
                    dik["Severidad4"]=dik["Severidad4"]+1
            i+=1
        m=m+i
    lista.append(m)
    if m!=0:
        porcentajesev1=round(((dik["Severidad1"]/m)*100),2)
        porcentajesev2=round(((dik["Severidad2"]/m)*100),2)
        porcentajesev3=round(((dik["Severidad3"]/m)*100),2)
        porcentajesev4=round(((dik["Severidad4"]/m)*100),2)
    lista.append(porcentajesev1)
    lista.append(porcentajesev2)
    lista.append(porcentajesev3)
    lista.append(porcentajesev4)
    return (lista,dik)
コード例 #2
0
def Clusters(analyzer,l1,l2):
    estructura=scc.KosarajuSCC(analyzer['connections'])
    idscc=estructura['idscc']
    #print(idscc)
    numero=scc.connectedComponents(estructura)
    land1=lt.newList()
    land2=lt.newList()
    vertices=gr.vertices(analyzer['connections'])
    a=lit.newIterator(vertices)
    answer=False
    while lit.hasNext(a):
        c=lit.next(a)
        h=c.split("-")
                #print(h)
                #if h[0] not in Lista:
        if h[0]==l1:
            lt.addLast(land1, c)
        if h[0]==l2:
            lt.addLast(land2, c)
    la1=lit.newIterator(land1)
    while lit.hasNext(la1):
        b=lit.next(la1)
        entry=mp.get(idscc,b)
        cluster=me.getValue(entry)
        #print(cluster)
        la2=lit.newIterator(land2)
        while lit.hasNext(la2):
            c=lit.next(la2)
            entry=mp.get(idscc,c)
            cluster1=me.getValue(entry)
            if cluster1==cluster:
                #print(cluster1)
                answer=True
                return (answer,numero)
    return (answer,numero)
コード例 #3
0
 def __init__(self, catalog):
     super_list = mp.valueSet(catalog.videos)
     self.super_iter = lliterator.newIterator(super_list)
     country_map = lliterator.next(self.super_iter)
     country_list = mp.valueSet(country_map)
     self.country_iter = lliterator.newIterator(country_list)
     self.category_iter = aliterator.newIterator(
         lliterator.next(self.country_iter))
コード例 #4
0
def distPaises (analyzer,paisA,paisB):
    pA=me.getValue(mp.get(analyzer['countries'],paisA))
    minin=1000000
    listi=lt.newList()
    loc1=(float(pA['CapitalLatitude']),float(pA['CapitalLongitude']))
    for landingp in (analyzer['landingpoints']['table']['elements']):
        if landingp['key']!=None:
            land=me.getValue(mp.get(analyzer['landingpoints'], landingp['key']))
            loc2=(float(land['latitude']),float(land['longitude']))
            dist=hs.haversine(loc1,loc2)
            if dist<minin:
                minin=dist
                landeA=land['landing_point_id']
    pB=me.getValue(mp.get(analyzer['countries'],paisB))
    Lista=lt.newList()
    dist=0
    mini=10000000
    loc1=(float(pB['CapitalLatitude']),float(pB['CapitalLongitude']))
    for landingp in (analyzer['landingpoints']['table']['elements']):
         if landingp['key']!=None:
            land=me.getValue(mp.get(analyzer['landingpoints'], landingp['key']))
            loc2=(float(land['latitude']),float(land['longitude']))
            dist=hs.haversine(loc1,loc2)
            if dist<mini:
                mini=dist
                landes=land['landing_point_id']
    vertices=gr.vertices(analyzer['connections'])
    a=lit.newIterator(vertices)
    while lit.hasNext(a):
        c=lit.next(a)
        h=c.split("-")
        if h[0]==landes:
            lt.addLast(Lista, c)
        if h[0]==landeA:
            x=c 
            lt.addLast(listi, c)
    dist=-1
    path="No"
    disti=1000000000000000
    pathh="No"
    t=lit.newIterator(listi)
    while lit.hasNext(t):
        y=lit.next(t)
        route=dij.Dijkstra(analyzer['connections'],y)
        a=lit.newIterator(Lista)
        while lit.hasNext(a):
            e=lit.next(a)
            path=dij.hasPathTo(route, e)
            if path==True:
                dist=dij.distTo(route, e)
                path=dij.pathTo(route, e)
                if path !=None and dist<disti: 
                    disti=dist
    return(path,disti)
コード例 #5
0
 def __next__(self):
     while not aliterator.hasNext(self.category_iter):
         while not lliterator.hasNext(self.country_iter):
             if not lliterator.hasNext(self.super_iter):
                 raise StopIteration
             else:
                 country_list = mp.valueSet(lliterator.next(
                     self.super_iter))
                 self.country_iter = lliterator.newIterator(country_list)
         self.category_iter = aliterator.newIterator(
             lliterator.next(self.country_iter))
     current = aliterator.next(self.category_iter)
     return current
コード例 #6
0
def addConnection(analyzer):
    vertices=gr.vertices(analyzer['connections'])
    a=lit.newIterator(vertices)
    while lit.hasNext(a):
        c=lit.next(a)
        b=lit.newIterator(vertices)
        while lit.hasNext(b):
            d=lit.next(b)
            if c!=d: 
                h=c.split("-")
                j=d.split("-")
                if h[0]==j[0]:
                    addLine(analyzer,100,c,d)
コード例 #7
0
def count_artists_2(rango, reproducciones) -> int:
    artists_ids = mp.newMap(numelements=reproducciones)
    rango_it = ll_it.newIterator(rango)
    while ll_it.hasNext(rango_it):
        mp.put(artists_ids, ll_it.next(rango_it), 1)
    artist_list = lt.newList()
    artist_full_list = mp.keySet(artists_ids)
    iterator = ll_it.newIterator(artist_full_list)
    for i in range(0, 10):
        if not ll_it.hasNext(iterator):
            break
        lt.addLast(artist_list, ll_it.next(iterator))
    return mp.size(artists_ids), artist_list
コード例 #8
0
 def req_2(self, country: str):
     repeticiones = mp.newMap(numelements=20000)
     for video in country_iterator(self, country):
         video_id = lt.getElement(video[0], 1)
         video_pair = mp.get(repeticiones, video_id)
         if video_pair:
             mp.put(repeticiones, video_id,
                    (video, video_pair['value'][1] + 1))
         else:
             mp.put(repeticiones, video_id, (video, 1))
     videos_ids = mp.keySet(repeticiones)
     id_iter = lliterator.newIterator(videos_ids)
     maximo = 0
     max_id = 0
     while lliterator.hasNext(id_iter):
         video_id = lliterator.next(id_iter)
         video = mp.get(repeticiones, video_id)['value']
         video_rep = video[1]
         if video_rep > maximo:
             maximo = video_rep
             max_id = video_id
     res = lt.newList()
     res_vid = mp.get(repeticiones, video_id)['value']
     lt.addFirst(res, res_vid[0])
     return (res, res_vid[1])
コード例 #9
0
 def all_points_cluster(self, cluster):
     vertex_it = ll_it.newIterator(mp.keySet(self.data.clusters['idscc']))
     while ll_it.hasNext(vertex_it):
         vertex = ll_it.next(vertex_it)
         if mp.get(self.data.clusters['idscc'], vertex)['value'] == cluster:
             self.graph_point(vertex)
     self.m.save('Data/map.html')
コード例 #10
0
 def __init__(self, catalog, category):
     self.category = category
     super_list = mp.valueSet(catalog.videos)
     self.super_iter = lliterator.newIterator(super_list)
     country_map = lliterator.next(self.super_iter)
     category_list = mp.get(country_map, category)['value']
     self.category_iter = aliterator.newIterator(category_list)
コード例 #11
0
def Requirement2(analyzer):

    tracemalloc.start()

    delta_time = -1.0
    delta_memory = -1.0

    start_time = getTime()
    start_memory = getMemory()

    vertices = gr.vertices(analyzer["connections_origin_destination"])

    size_max = 0

    iterator1 = it.newIterator(vertices)
    while it.hasNext(iterator1):
        element = it.next(iterator1)

        adjacents = gr.adjacents(analyzer["connections_origin_destination"],
                                 element)
        size = lt.size(adjacents)

        if size >= size_max:
            size_max = size
            result = greaterLandingPoint(analyzer, element)

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

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

    return size_max, result, delta_time, delta_memory
コード例 #12
0
def createTempoList(tempoMap, loTempo, hiTempo):
    listOfLists = om.values(tempoMap, loTempo, hiTempo)
    tempoList = lt.newList(datastructure='SINGLE_LINKED')

    iteratorLists = slit.newIterator(listOfLists)

    while slit.hasNext(iteratorLists):
        list = slit.next(iteratorLists)

        iteratorSongs = slit.newIterator(list)

        while slit.hasNext(iteratorSongs):
            song = slit.next(iteratorSongs)
            lt.addLast(tempoList, song)

    return tempoList
コード例 #13
0
def createCharList(charMap, loValue, hiValue):
    listOfLists = om.values(charMap, loValue, hiValue)
    charList = lt.newList(datastructure='SINGLE_LINKED')

    iteratorLists = slit.newIterator(listOfLists)

    while slit.hasNext(iteratorLists):
        list = slit.next(iteratorLists)

        iteratorSongs = slit.newIterator(list)

        while slit.hasNext(iteratorSongs):
            song = slit.next(iteratorSongs)
            lt.addLast(charList, song)

    return charList
コード例 #14
0
def addCapital(analyzer):
    #print("Capital")
    Lista=lt.newList()
    for capital in (analyzer['countries']['table']['elements']):
        if capital['key']!=None:
            cap=me.getValue(mp.get(analyzer['countries'], capital['key']))
            mini=100000000000
            dist=0
            landes=" "
            loc1=(float(cap['CapitalLatitude']),float(cap['CapitalLongitude']))
            for landingp in (analyzer['landingpoints']['table']['elements']):
                if landingp['key']!=None and landingp['key'] not in Lista:
                    land=me.getValue(mp.get(analyzer['landingpoints'], landingp['key']))
                    loc2=(float(land['latitude']),float(land['longitude']))
                    dist=hs.haversine(loc1,loc2)
                    if dist<mini:
                        mini=dist
                        landes=land['landing_point_id']
            vertices=gr.vertices(analyzer['connections'])
            a=lit.newIterator(vertices)
            while lit.hasNext(a):
                c=lit.next(a)
                h=c.split("-")
                #print(h)
                #if h[0] not in Lista:
                if h[0]==landes:
                    #print(h[0],c)
                    #print(h[0])
                    addLine(analyzer,mini,cap['CapitalName'],c)
                    #
                    #print(cap['CapitalName'],c)
            lt.addLast(Lista, landes)
コード例 #15
0
def getStateInRange(lst):
    lista=[]
    iterator = it.newIterator(lst)
    while it.hasNext(iterator):
        itet=it.next(iterator)
        iterator2 = it.newIterator(itet["lstaccidents"])
        while it.hasNext(iterator2):
            itet2=it.next(iterator2)
            lista.append(itet2["State"])
    maxi = 0
    ret=None
    for estado in lista:
        cant=lista.count(estado)
        if cant > maxi:
            maxi = cant
            ret=estado
    return (ret,maxi)
コード例 #16
0
def hallar_categoria(lst):
    lista=[]
    iterator = it.newIterator(lst)
    while it.hasNext(iterator):
        itet=it.next(iterator)
        iterator2 = it.newIterator(itet["lstaccidents"])
        while it.hasNext(iterator2):
            itet2=it.next(iterator2)
            lista.append(itet2["Severity"])
    maxi = 0
    ret=None
    for severidad in lista:
        cant=lista.count(severidad)
        if cant > maxi:
            maxi = cant
            ret=severidad
    return (ret,maxi)
コード例 #17
0
def print_req_4(resultado):
    iterator = ll_it.newIterator(resultado)
    while ll_it.hasNext(iterator):
        res = tuple(ll_it.next(iterator))
        print("{} tiene {} y {} artistas".format(*res[0:3]))
        print("Artistas de {}".format(res[0]))
        aux_print_4(res[3])
        print("\n\n")
コード例 #18
0
def max_rep(ans_list):
    iterator = ll_it.newIterator(ans_list)
    maximo = ('', 0)
    while ll_it.hasNext(iterator):
        valor = ll_it.next(iterator)
        if maximo[1] < valor[1]:
            maximo = valor
    return maximo
コード例 #19
0
def hallar_muyrepetido(lst):
    lista=[]
    iterator = it.newIterator(lst)
    while it.hasNext(iterator):
        itet=it.next(iterator)
        iterator2 = it.newIterator(itet["lstaccidents"])
        while it.hasNext(iterator2):
            itet2=it.next(iterator2)
            fechahora=datetime.datetime.strptime(itet2["Start_Time"], '%Y-%m-%d %H:%M:%S')
            lista.append(fechahora.date())      
    maxi = 0
    ret=None
    for cada_fecha in lista:
        cant=lista.count(cada_fecha)
        if cant > maxi:
            maxi = cant
            ret=cada_fecha
    return (ret,maxi)
コード例 #20
0
 def __next__(self):
     while not aliterator.hasNext(self.category_iter):
         if not lliterator.hasNext(self.country_iter):
             raise StopIteration
         else:
             self.category_iter = aliterator.newIterator(
                 lliterator.next(self.country_iter))
     current = aliterator.next(self.category_iter)
     return current
コード例 #21
0
def addCountryToMap(analyzer):

    iterator0 = it.newIterator(analyzer['countries'])
    while it.hasNext(iterator0):
        country = it.next(iterator0)

        mp.put(analyzer['countries_map'], country['CountryName'], country)

    return analyzer
def mostAccInDate (lista):
    iterator = iterlk.newIterator(lista)
    most = time.strftime('%Y-%m-%d',lt.firstElement(lista))
    lastcounter = 0
    counter = 0
    while iterlk.hasNext(iterator):
        element = iterlk.next(iterator)
        elementr = time.strftime('%Y-%m-%d', element)
        if elementr == time.strftime('%Y-%m-%d', iterlk.next(iterator)):
            counter +=1
            
        if elementr != time.strftime('%Y-%m-%d', iterlk.next(iterator)):
            lastcounter = counter
            counter = 0
            
        if counter > lastcounter:
            most = elementr
    return most
コード例 #23
0
 def req_4(self, genre_list):
     genre_it = ll_it.newIterator(genre_list)
     ans_list = lt.newList()
     while ll_it.hasNext(genre_it):
         genre = ll_it.next(genre_it)
         temp_min, temp_max = mp.get(self.genres, genre)['value']
         temp_min, temp_max = self.req_5_aux_2(temp_min, temp_max)
         lt.addLast(ans_list, (genre, *self.req_4_aux(temp_min, temp_max)))
     return ans_list
コード例 #24
0
def addLandingPointToIDMap(analyzer):

    iterator0 = it.newIterator(analyzer['landing_points'])
    while it.hasNext(iterator0):
        landingPoint = it.next(iterator0)

        mp.put(analyzer['landing_points_mapID'],
               landingPoint['landing_point_id'], landingPoint)

    return analyzer
コード例 #25
0
 def __next__(self):
     while not aliterator.hasNext(self.category_iter):
         if not lliterator.hasNext(self.super_iter):
             raise StopIteration
         else:
             country_map = lliterator.next(self.super_iter)
             category_list = mp.get(country_map, self.category)['value']
             self.category_iter = aliterator.newIterator(category_list)
     current = aliterator.next(self.category_iter)
     return current
コード例 #26
0
 def path_str(self, path):
     respuesta = []
     path_it = ll_it.newIterator(path)
     while ll_it.hasNext(path_it):
         edge = ll_it.next(path_it)
         dist = round(edge['weight'], 2)
         cityA = self.id_to_city(edge['vertexA'])
         cityB = self.id_to_city(edge['vertexB'])
         respuesta.append("{} - {}: {} km".format(cityA, cityB, dist))
     return "\n".join(respuesta)
コード例 #27
0
def fallas(analyzer,vertice):
    print(vertice)
    Lista=lt.newList()
    listi=lt.newList()
    
    #recorrer map con los landing points y decir que si vertice == [name:] entonces name=l[name]

    
    vertices=gr.vertices(analyzer['connections'])
    b=lit.newIterator(vertices)
    name=" "
    while lit.hasNext(b) and name== " ":
        c=lit.next(b)
        if "-" in c:
            h=c.split("-")
            if h[1]==vertice:
                name=c
                print("hola")
    
    edges=gr.adjacents(analyzer['connections'], name)

    b=lit.newIterator(edges)
    while lit.hasNext(b):
        c=lit.next(b)
        h=c.split("-")
        p=me.getValue(mp.get(analyzer['landingpoints'],h[0]))
        loc1=(float(p['latitude']),float(p['longitude']))
        minin=100000000
        landeA=0
        for country in (analyzer['countries']['table']['elements']):
           
            if country['key']!=None:
                land=me.getValue(mp.get(analyzer['countries'], country['key']))
                loc2=(float(land['CapitalLatitude']),float(land['CapitalLongitude']))
                dist=hs.haversine(loc1,loc2)
                if dist<minin:
                    minin=dist
                    print("si")
                    landeA=land['CountryName']
        if landeA !=0:
            lt.addLast(Lista, landeA)  
    return Lista
コード例 #28
0
def getAccidentsByState(analyzer, initialDate, finalDate):
    rango = om.values(analyzer, initialDate, finalDate)

    histograma_estado = {'Estado': None, 'accidents': None}

    histograma_fecha = {'Fecha': None, 'accidents': None}

    iter = lit.newIterator(histograma_estado)
    while lit.hasNext(iter):
        entry = lit.next(iter)
        if entry['State'] not in histograma_estado:
            histograma_estado['Estado'] = 1
        else:
            histograma_estado['Estado'] += 1

    iter = lit.newIterator(histograma_fecha)
    while lit.hasNext(iter):
        date = lit.next(iter)
        if date['dateIndex'] not in histograma_fecha:
            histograma_fecha['Fecha'] = 1
        else:
            histograma_fecha['Fecha'] += 1

    maximo_estado = max(histograma_estado.values)
    llaves_estado = list(histograma_estado.keys)
    iter = lit.newIterator(llaves_estado)
    while lit.hasNext(iter):
        state = lit.next(iter)
        if histograma_estado[state] == maximo_estado:
            respuesta_estado = llaves_estado.index(maximo_estado)

    maximo_fecha = max(histograma_fecha.values)
    llaves_fecha = list(histograma_fecha.keys)
    iter = lit.newIterator(llaves_estado)
    while lit.hasNext(iter):
        fecha = lit.next(iter)
        if histograma_fecha[fecha] == maximo_fecha:
            respuesta_fecha = llaves_fecha.index(maximo_fecha)

    return ("El estado con mayores accidentes en el rango dado es: " +
            str(respuesta_estado) + "\n"
            "La fecha con mayores accidentes es: " + str(respuesta_fecha))
コード例 #29
0
 def graph_path(self, path):
     first = True
     path_it = ll_it.newIterator(path)
     while ll_it.hasNext(path_it):
         edge = ll_it.next(path_it)
         if first:
             self.graph_point(edge['vertexA'])
             first = False
         self.graph_point(edge['vertexB'])
     folium.PolyLine(self.line['elements']).add_to(self.m)
     self.m.save('Data/map.html')
コード例 #30
0
def next(iterator):
    """
    Retorna el elemento en la posición siguiente a la indicada por el iterador
    Args:
        iterator: El iterador de la lista
    Returns:
        El siguiente elemento al último retornado por el iterador
    """
    if (iterator['type'] == 'ARRAY_ITERATOR'):
        return ait.next(iterator)
    else:
        return lit.next(iterator)