Example #1
0
def newAnalyzer():
    try:
        citibike = {
            'graph': None,
            'lsttrips': None,
            'divide': None,
            'grafo': None,
            'StationI': None,
            'StationF': None
        }

        citibike['graph'] = gr.newGraph(datastructure='ADJ_LIST',
                                        directed=True,
                                        size=1000,
                                        comparefunction=compareStations)
        citibike['lsttrips'] = lt.newList('SINGLE_LINKED', compareStations)
        citibike['divide'] = {}
        citibike['grafo'] = gr.newGraph(datastructure='ADJ_LIST',
                                        directed=True,
                                        size=1000,
                                        comparefunction=compareStations)
        citibike['StationI'] = mp.newMap(numelements=300317,
                                         prime=109345121,
                                         maptype='CHAINING',
                                         loadfactor=1.0,
                                         comparefunction=comparer)
        citibike['StationF'] = mp.newMap(numelements=300317,
                                         prime=109345121,
                                         maptype='CHAINING',
                                         loadfactor=1.0,
                                         comparefunction=comparer)
        citibike['namesI'] = mp.newMap(numelements=300317,
                                       prime=109345121,
                                       maptype='CHAINING',
                                       loadfactor=1.0,
                                       comparefunction=comparer)
        citibike['namesF'] = mp.newMap(numelements=300317,
                                       prime=109345121,
                                       maptype='CHAINING',
                                       loadfactor=1.0,
                                       comparefunction=comparer)
        citibike['suscripcion'] = mp.newMap(numelements=300317,
                                            prime=109345121,
                                            maptype='CHAINING',
                                            loadfactor=1.0,
                                            comparefunction=comparer)
        return citibike
    except Exception as exp:
        error.reraise(exp, 'model:newAnalyzer')
Example #2
0
def newCatalog(map_type="CHAINING", loadfactor=None):
    """ Inicializa el catálogo de libros

    Crea una lista vacia para guardar todos los libros

    Se crean indices (Maps) por los siguientes criterios:
    Autores
    ID libros
    Tags
    Año de publicacion

    Retorna el catalogo inicializado.
    """
    if loadfactor is None:
        if map_type == "PROBING":
            loadfactor = 0.4
        elif map_type == "CHAINING":
            loadfactor = 0.9
        else:
            return None

    catalog = dict()

    catalog['producers'] = mp.newMap(100,
                                     maptype=map_type,
                                     loadfactor=loadfactor,
                                     comparefunction=compareMapProductora)

    catalog['actors'] = mp.newMap(400,
                                  maptype=map_type,
                                  loadfactor=loadfactor,
                                  comparefunction=compareMapProductora)

    catalog['genres'] = mp.newMap(400,
                                  maptype=map_type,
                                  loadfactor=loadfactor,
                                  comparefunction=compareMapProductora)

    catalog['directores'] = mp.newMap(500,
                                      maptype='CHAINING',
                                      loadfactor=0.7,
                                      comparefunction=compareMapProductora)
    catalog["paises"] = mp.newMap(500,
                                  maptype='CHAINING',
                                  loadfactor=0.7,
                                  comparefunction=compareMapProductora)

    return catalog
Example #3
0
def secondReq(catalog, country):
    """
    Completa el requerimiento #2
    """

    new_map = mp.newMap(50000, 50007, 'PROBING', 0.80, None)
    for videos in catalog["videos"]["table"]["elements"]:
        if videos["key"] != None:
            for video in lt.iterator(videos["value"]["videos"]):
                if str(video["country"]).lower() == str(country).lower():
                    value = {
                        "title": video["title"],
                        "channel": video["channel_title"],
                        "count": "1"
                    }
                    key = video["title"]
                    exists = mp.contains(new_map, key)
                    if not exists:
                        mp.put(new_map, key, value)
                    else:
                        new_value = mp.get(new_map, key)
                        new_value["value"]["count"] = str(
                            int(new_value["value"]["count"]) + 1)
                        mp.put(new_map, key, new_value["value"])

    new_list = lt.newList('ARRAY_LIST', cmpfunction=cmpVideosByTrendingdays)
    for element in new_map["table"]["elements"]:
        if element["key"] != None:
            lt.addLast(new_list, element["value"])

    sorted_list = quick.sort(new_list, cmpVideosByTrendingdays)
    result = lt.firstElement(sorted_list)
    result["country"] = country

    return result
Example #4
0
def newMap(numelements=17,
           prime=109345121,
           maptype='CHAINING',
           loadfactor=0.5,
           comparefunction=None):
    """Crea una tabla de simbolos (map) sin orden

    Args:
        numelements: Tamaño inicial de la tabla
        prime: Número primo utilizado en la función MAD
        maptype: separate chaining ('CHAINING' ) o linear probing('PROBING')
        loadfactor: Factor de carga inicial de la tabla
        comparefunction: Funcion de comparación entre llaves
    Returns:
        Un nuevo map
    Raises:
        Exception
    """
    return ht.newMap(numelements, prime, maptype, loadfactor, comparefunction)
Example #5
0
def thirdReq(catalog, category):
    """
    Completa el requerimiento #3
    """
    for cate in catalog["categories"]["table"]["elements"]:
        try:
            if int(cate["key"]) == int(category):
                info = cate["value"]["videos"]
                break
        except:
            pass
    new_map = mp.newMap(50000, 50007, 'PROBING', 0.80, None)
    i = 1
    t = lt.size(info)
    x = 0
    while i <= t:
        elem = lt.getElement(info, i)
        value = {
            "title": elem["title"],
            "channel": elem["channel_title"],
            "count": 1
        }
        key = elem["title"]
        exists = mp.contains(new_map, key)
        if not exists:
            mp.put(new_map, key, value)
        else:
            new_value = mp.get(new_map, key)
            key = elem["title"]
            new_value["value"]["count"] += 1
            mp.put(new_map, key, new_value["value"])
        i += 1
    new_list = lt.newList()
    for element in new_map["table"]["elements"]:
        if element["key"] != None:
            lt.addLast(new_list, element["value"])
    sorted_list = quick.sort(new_list, cmpVideosByTrendingdays)
    result = lt.firstElement(sorted_list)
    result["cat"] = category

    return result
Example #6
0
def newCatalog():
    catalog = {"videos": None, "categories": None, "info": None}
    catalog["videos"] = mp.newMap(400000, 400007, 'PROBING', 0.80, None)
    catalog["categories"] = mp.newMap(36, 37, 'PROBING', 0.80, None)
    return catalog
Example #7
0
def MakeMapFormat(els, Type='PROBING', ints=False):
    return mp.newMap(els, maptype=Type, comparefunction=compareMp, ints=ints)