コード例 #1
0
ファイル: model.py プロジェクト: JeOs714/Lab3_202010
def addDirectorId(catalog, row):
    """
    Adiciona un autor al map y sus libros
    """
    directors = catalog['directorsId']
    director = newDirector(row)
    map.put(directors, row["id"], director, compareByKey)
コード例 #2
0
ファイル: model.py プロジェクト: andresR0410/Lab3_202010
def addMovieMap(catalog, row):
    """
    Adiciona película al map con key=title
    """
    movies = catalog['moviesMap']
    movie = newMovie(row)
    map.put(movies, movie['title'], movie, compareByKey)
コード例 #3
0
def newDijkstra(graph, s):
    """
    Crea una busqueda Dijkstra para un digrafo y un vertice origen
    """
    prime = nextPrime (g.numVertex(graph) * 2)
    search = {'graph':graph, 's':s, 'visitedMap':None, 'minpq':None}
    search['visitedMap'] = map.newMap(numelements=prime, maptype='PROBING', comparefunction=graph['comparefunction'])
    vertices = g.vertices (graph)
    itvertices = it.newIterator (vertices)
    while (it.hasNext (itvertices)):
        vert =  it.next (itvertices)
        map.put (search['visitedMap'], vert, {'marked':False,'edgeTo':None,'distTo':math.inf})
    map.put(search['visitedMap'], s, {'marked':True,'edgeTo':None,'distTo':0})
    pq = minpq.newIndexMinPQ(g.numVertex(graph), comparenames)
    search['minpq'] = pq
    minpq.insert(search['minpq'], s, 0)
    while not minpq.isEmpty(search['minpq']):
        v = minpq.delMin(pq)
        if not g.containsVertex(graph,v):
            raise Exception("Vertex ["+v+"] is not in the graph")
        else:
            adjs = g.adjacentEdges(search['graph'],v)
            adjs_iter = it.newIterator (adjs) 
            while (it.hasNext(adjs_iter)):
                w = it.next (adjs_iter)
                relax(search, w)


        # obtener los enlaces adjacentes de v
        # Iterar sobre la lista de enlaces
        # Relajar (relax) cada enlace
    return search
コード例 #4
0
def addMovieMap(catalog, row):
    """
    Adicion la pelicula al map con key=id
    """
    movies = catalog['moviesMap']
    movie = newMovie(row)
    map.put(movies, movie['id'], movie, compareByKey)
コード例 #5
0
ファイル: model.py プロジェクト: susme2020/Lab3_202010
def addBookMap(catalog, row):
    """
    Adiciona libro al map con key=title
    """
    books = catalog['booksMap']
    book = newBook(row)
    map.put(books, book['title'], book, compareByKey)
コード例 #6
0
def exch(minPQ, i, j):
    element_i = minPQ['pq'][i]
    element_j = minPQ['pq'][j]
    minPQ['pq'][i] = element_j
    map.put(minPQ['qpMap'], element_i['index'], j)
    minPQ['pq'][j] = element_i
    map.put(minPQ['qpMap'], element_j['index'], i)
コード例 #7
0
ファイル: adjlist.py プロジェクト: danielhmahecha/Genificador
def addEdge(graph, vertexa, vertexb, weight=0):
    """
    Agrega un arco entre los vertices vertexa ---- vertexb, con peso weight.
    Si el grafo es no dirigido se adiciona dos veces el mismo arco, en el mismo orden
    Si el grafo es dirigido se adiciona solo el arco vertexa --> vertexb
    """
    try:
        # Se crea el arco
        edge = e.newEdge(vertexa, vertexb, weight)

        #Se obtienen las listas de adyacencias de cada vertice
        #Se anexa a cada lista el arco correspondiente
        entrya = map.get(graph['vertices'], vertexa)
        lt.addLast(entrya['value'], edge)

        if (not graph['directed']):
            entryb = map.get(graph['vertices'], vertexb)
            lt.addLast(entryb['value'], edge)
        else:
            degree = map.get(graph['indegree'], vertexb)
            map.put(graph['indegree'], vertexb, degree['value'] + 1)

        graph['edges'] += 1

        return graph
    except:
        return None
コード例 #8
0
ファイル: adjlist.py プロジェクト: dlmanrique/Lab7_202010
def insertVertex(graph, vertex):
    """
    Inserta el vertice vertex en el grafo graph
    """
    edges = lt.newList()
    map.put(graph['vertices'], vertex, edges)
    return graph
コード例 #9
0
ファイル: model.py プロジェクト: nCaicedo789/Lab6_202010
def getBooksCountByYearRange(catalog, years):
    """
    Retorna la cantidad de libros por rating para un rango de años
    """

    startYear = strToDate(years.split(" ")[0], '%Y-%m-%d')
    endYear = strToDate(years.split(" ")[1], '%Y-%m-%d')
    yearList = tree.valueRange(catalog['yearsTree'], startYear, endYear,
                               greater)
    counter = 0
    cities = map.newMap(40009, maptype='PROBING')
    if yearList:
        iteraYear = it.newIterator(yearList)
        while it.hasNext(iteraYear):
            yearElement = it.next(iteraYear)
            #print(yearElement['year'],yearElement['count'])
            counter += yearElement['count']
            keys = map.keySet(yearElement['ratingMap'])
            for i in range(1, lt.size(keys)):
                city_key = lt.getElement(keys, i)
                city = map.get(cities, city_key, compareByKey)
                if city:
                    city['Accidentes'] += 1
                else:
                    ciudad = {'ciudad': city_key, 'Accidentes': 1}
                    map.put(cities, ciudad['ciudad'], ciudad, compareByKey)
        total = {'total_Accidentes': counter}
        map.put(cities, 'total', total, compareByKey)

        return cities
    return None
コード例 #10
0
ファイル: model.py プロジェクト: nCaicedo789/Lab6_202010
def addYearTree(catalog, row):
    """
    Adiciona el libro al arbol anual key=original_publication_year
    """
    yearText = row['Start_Time']
    if row['Start_Time']:
        yearText = row['Start_Time'][0:row['Start_Time'].index(' ')]
    year = strToDate(yearText, '%Y-%m-%d')
    yearNode = tree.get(catalog['yearsTree'], year, greater)
    if yearNode:
        yearNode['count'] += 1
        sev = int(row['Severity'])
        yearNode['severity'][sev] += 1
        city = row['City']
        ratingCount = map.get(yearNode['ratingMap'], city, compareByKey)
        if ratingCount:
            ratingCount['Accidentes'] += 1
        else:
            ciudad = {'Ciudad': row['City'], 'Accidentes': 1}
            map.put(yearNode['ratingMap'], ciudad['Ciudad'], ciudad,
                    compareByKey)

        state = row['State']
        state_count = tree.get(yearNode['state'], state, greater)
        if state_count:
            state_count['Accidentes'] += 1
        else:
            estado = {'Estado': row['State'], 'Accidentes': 1}
            tree.put(yearNode['state'], estado['Estado'], estado, greater)
    else:
        yearNode = newYear(year, row)
        catalog['yearsTree'] = tree.put(catalog['yearsTree'], year, yearNode,
                                        greater)
コード例 #11
0
    def test_LoadTable(self):
        table_capacity = 171
        book_map = ht.newMap(capacity=table_capacity,
                             maptype='CHAINING',
                             comparefunction=self.compare_book_id)
        booksfile = cf.data_dir + 'GoodReads/books-small.csv'

        self.assertEqual(ht.size(book_map), 0)
        self.assertTrue(ht.isEmpty(book_map))

        input_file = csv.DictReader(open(booksfile))
        for book in input_file:
            ht.put(book_map, book['book_id'], book)

        self.assertEqual(ht.size(book_map), 149)
        self.assertTrue(ht.contains(book_map, '100'))

        entry = ht.get(book_map, '100')
        self.assertIsNotNone(entry)
        self.assertEqual(entry['value']['book_id'], '100')

        ht.remove(book_map, '100')
        self.assertEqual(ht.size(book_map), 148)
        self.assertFalse(ht.contains(book_map, '100'))

        lst_keys = ht.keySet(book_map)
        self.assertFalse(lt.isEmpty(lst_keys))
        self.assertEqual(lt.size(lst_keys), 148)

        lst_values = ht.valueSet(book_map)
        self.assertFalse(lt.isEmpty(lst_values))
        self.assertEqual(lt.size(lst_values), 148)
コード例 #12
0
    def test_LoadTable(self):
        self.assertEqual(ht.size(self.book_map), 0)
        self.assertTrue(ht.isEmpty(self.book_map))

        input_file = csv.DictReader(open(self.booksfile))
        for book in input_file:
            ht.put(self.book_map, book['book_id'], book, self.compare_book_id)

        self.assertEqual(ht.size(self.book_map), 149)
        self.assertTrue(ht.contains(self.book_map, '100',
                                    self.compare_book_id))

        entry = ht.get(self.book_map, '100', self.compare_book_id)
        self.assertIsNotNone(entry)
        self.assertEqual(entry['value']['book_id'], '100')

        ht.remove(self.book_map, '100', self.compare_book_id)
        self.assertEqual(ht.size(self.book_map), 148)
        self.assertFalse(
            ht.contains(self.book_map, '100', self.compare_book_id))

        lst_keys = ht.keySet(self.book_map)
        self.assertFalse(lt.isEmpty(lst_keys))
        self.assertEqual(lt.size(lst_keys), 148)

        lst_values = ht.valueSet(self.book_map)
        self.assertFalse(lt.isEmpty(lst_values))
        self.assertEqual(lt.size(lst_values), 148)
コード例 #13
0
def insert(minPQ, index, priority):
    if contains(minPQ, index):
        raise Exception('index is already in the priority queue')
    n = minPQ['size'] + 1
    minPQ['size'] = n
    map.put(minPQ['qpMap'], index, n)
    minPQ['pq'][n] = {'index': index, 'priority': priority}
    swim(minPQ, n)
コード例 #14
0
ファイル: model.py プロジェクト: nCaicedo789/Lab3_202010
def addMovieMap(catalog, row):
    """
    Adiciona libro al map con key=title
    """
    books = catalog['MovieMap_title']
    books_id = catalog['MovieMap_id']
    book = newMovie(row)
    map.put(books, book['title'], book, compareByKey)
    map.put(books_id, book['id'], book, compareByKey)
コード例 #15
0
ファイル: model.py プロジェクト: nCaicedo789/Lab3_202010
def add_gen(catalog, row):
    generos = catalog['generos']
    split_gen = row['genres'].split('|')
    for i in split_gen:
        if map.contains(generos, i, compareByKey):
            map.get(generos, i, compareByKey)['peliculas'] += 1
        else:
            x = new_gen(row['genres'])
            map.put(generos, i, x, compareByKey)
コード例 #16
0
ファイル: model.py プロジェクト: dlmanrique/Lab5_202010
def newDate (date, row):
    """
    Crea una nueva estructura para almacenar los accidentes por fecha 
    """
    dateNode = {"date": date, "severityMap":None}
    dateNode ['severityMap'] = map.newMap(7,maptype='CHAINING')
    intSeverity = int(row['Severity'])
    map.put(dateNode['severityMap'],intSeverity,1, compareByKey)
    return dateNode
コード例 #17
0
ファイル: dfs.py プロジェクト: danielhmahecha/Lab9_202010
def dfs (search, v):
    adjs = g.adjacents(search['graph'],v)
    adjs_iter = it.newIterator (adjs)
    while (it.hasNext(adjs_iter)):
        w = it.next (adjs_iter)
        visited_w = map.get(search['visitedMap'], w)
        if visited_w == None:
            map.put(search['visitedMap'], w, {'marked':True, 'edgeTo':v})
            dfs(search, w)
コード例 #18
0
def newDate (date, row):
    """
    Crea una nueva estructura para almacenar los accidentes por fecha 
    """
    dateNode = {"date": date, "cityMap":None}
    dateNode ['cityMap'] = map.newMap(2999,maptype='CHAINING') #5966 ciudades
    city = row['City']
    map.put(dateNode['cityMap'],city,1, compareByKey)
    return dateNode
コード例 #19
0
ファイル: dfs.py プロジェクト: danielhmahecha/Lab8_202010
def dfs_2(grafo, v, revisados):
    adjs = g.adjacents(grafo, v)
    adjs_iter = it.newIterator(adjs)
    while (it.hasNext(adjs_iter)):
        w = it.next(adjs_iter)
        visited_w = map.contains(revisados, w)
        if visited_w == False:
            map.put(revisados, w, {'marked': True, 'edgeTo': v})
            dfs_2(grafo, w, revisados)
コード例 #20
0
def newYear (year, row):
    """
    Crea una nueva estructura para almacenar los libros por año 
    """
    yearNode = {"year": year, "ratingMap":None,}
    yearNode ['ratingMap'] = map.newMap(11,maptype='CHAINING')
    intRating = round(float(row['average_rating']))
    map.put(yearNode['ratingMap'],intRating, 1, compareByKey)
    return yearNode
コード例 #21
0
def depth_first_search(catalog,node):
    valor={'nodo':node, 'stado':True, 'predecesor':None}
    map.put(catalog['visitedMap'],valor['nodo'],valor)
    list_ad=g.adjacents(catalog['delayGraph'],node)
    for i in range (1,lt.size(list_ad)+1):
        li_node=lt.getElement(list_ad,i)
        if not map.contains(catalog['visitedMap'],li_node):
            record={'nodo':li_node, 'stado':True, 'predecesor':node}
            map.put(catalog['visitedMap'],record['nodo'],record)
            depth_first_search(catalog,li_node)
コード例 #22
0
ファイル: dfs.py プロジェクト: danielhmahecha/Lab9_202010
def newDFS(graph, source):
    """
    Crea una busqueda DFS para un grafo y un vertice origen
    """
    prime = nextPrime (g.numVertex(graph) * 2)
    search={'graph':graph, 's':source, 'visitedMap':None}   
    search['visitedMap'] = map.newMap(numelements=prime, maptype='PROBING', comparefunction=graph['comparefunction'])
    map.put(search['visitedMap'],source, {'marked':True,'edgeTo':None})
    dfs(search, source)
    return search
コード例 #23
0
ファイル: comp_conec.py プロジェクト: nCaicedo789/Lab7_202010
def depth_first_search(Graph, Mapa_de_marcar, node):
    valor={'nodo':node, 'stado':True, 'predecesor':None}
    map.put(Mapa_de_marcar,valor['nodo'],valor)
    list_ad=g.adjacents(Graph,node)
    for i in range (1,lt.size(list_ad)+1):
        li_node=lt.getElement(list_ad,i)
        if not map.contains(Mapa_de_marcar,li_node):
            record={'nodo':li_node, 'stado':True, 'predecesor':node}
            map.put(Mapa_de_marcar,record['nodo'],record)
            depth_first_search(Graph, Mapa_de_marcar, li_node)
コード例 #24
0
def date_tally(catalog, row):
    mapa = catalog['fecha_tally_viajes']
    formato = '%m/%d/%Y'
    fecha = strToDate(row['start_date'], formato)

    date = map.get(mapa, fecha)
    if date:
        date['total'] += 1
    else:
        dic = {'fehca': fecha, 'total': 1}
        map.put(mapa, fecha, dic)
コード例 #25
0
 def dfs(self, graph, vert, marked, pre, post, reversepost):
     q.enqueue(pre, vert)
     m.put(marked, vert, True)
     lstadjacents = g.adjacents(graph, vert)
     adjiterator = it.newIterator(lstadjacents)
     while it.hasNext(adjiterator):
         adjvert = it.next(adjiterator)
         if not m.contains(marked, adjvert):
             self.dfs(graph, adjvert, marked, pre, post, reversepost)
     q.enqueue(post, vert)
     s.push(reversepost, vert)
コード例 #26
0
def addGenre (catalog, row):
    genres = catalog['genres']
    gen = ['Adventure','Crime','Animation','History','Action','TV Movie','War','Fantasy','Romance','Thriller','Music','Horror','Documentary','Science Fiction','Family','Comedy','Drama','Western','Mystery','Foreign']
    for g in gen:
        
        if g in row['genres']:
            genre = map.get(genres,g,compareByKey)
            if genre:
                lt.addLast(genre['genreMovies'],row['id'])
            else:
                newgenre = newGenre (g,row)
                map.put(genres,newgenre['genre'],newgenre,compareByKey)
コード例 #27
0
ファイル: model.py プロジェクト: andresR0410/Lab3_202010
def addIdMap(catalog, row):
    """
    Adiciona película al map con key=id
    """
    movies = catalog['idMap']
    movie = newMovie(row)
    pelicula = {
        'title': movie['title'],
        'vote_average': float(movie['vote_average']),
        'director': ''
    }
    map.put(movies, movie['movies_id'], pelicula, compareByKey)
コード例 #28
0
ファイル: model.py プロジェクト: susme2020/Lab3_202010
def addActor(catalog, name, row):
    """
    Adiciona un actor al map y sus películas
    """
    if name:
        actors = catalog['actors']
        actor = map.get(actors, name, compareByKey)
        if actor:
            lt.addLast(actor['movies_id'], row['id'])
        else:
            actor = newActor(name, row)
            map.put(actors, actor['name'], actor, compareByKey)
コード例 #29
0
def relax(search, edge):
    v = e.either(edge)
    w = e.other(edge, v)
    visited_v = map.get(search['visitedMap'], v)['value']
    visited_w = map.get(search['visitedMap'], w)['value']
    if visited_w['distTo'] > (visited_v['distTo'] + e.weight(edge)):
        distToW = visited_v['distTo'] + e.weight(edge)
        map.put(search['visitedMap'], w, {'marked':True,'edgeTo':edge,'distTo':distToW})
        if minpq.contains(search['minpq'], w): 
            minpq.decreasePriority(search['minpq'], w, distToW)
        else:
            minpq.insert(search['minpq'], w, distToW)
コード例 #30
0
ファイル: model.py プロジェクト: susme2020/Lab3_202010
def addDirector(catalog, name, row):
    """
    Adiciona un director al map y sus películas
    """
    if name:
        directors = catalog['directors']
        director = map.get(directors, name, compareByKey)
        if director:
            lt.addLast(director['movies_id'], row['id'])
        else:
            director = newDirector(name, row)
            map.put(directors, name, director, compareByKey)