Esempio n. 1
0
def getAccidentsByDateRange (catalog, dates):
    
    startDate = strToDate(dates.split(" ")[0],'%Y-%m-%d')
    endDate = strToDate(dates.split(" ")[1],'%Y-%m-%d')
    dateList = tree.valueRange(catalog['dateTree'], startDate, endDate, greater)
   # print(dateList)
    #hol= lt.getElement(dateList,13)
    #print(hol)
    iteraDates = it.newIterator(dateList)
    cities = {}
    count = 0
    while it.hasNext(iteraDates):
        dateElement = it.next(iteraDates)
        if dateElement:
            citiesList = map.keySet(dateElement['cityMap'])
            iteraCities = it.newIterator(citiesList)
            while it.hasNext(iteraCities):
                cityKey = it.next(iteraCities)
                new = map.get(dateElement['cityMap'],cityKey,compareByKey)
                count += new
                if cityKey in cities.keys():
                    cities[cityKey] += new
                else:
                    cities[cityKey]=new
                #response += ''+str(cityKey) + ':' + str(map.get(dateElement['cityMap'],cityKey,compareByKey)) + '\n'
    response = 'Total de accidentes en el rango: '+str(count)+'\n'
    for i in cities:
        response += str(i)+": "+str(cities[i])+"\n"
            #print (i, cities[i])
            #response += str(i[0])+": "+str(i[1])+"\n"
        
    return response
Esempio n. 2
0
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
Esempio n. 3
0
def req2(catalogo, rango):
    dat = rango.split(' ')
    respuesta = {}
    fecha_1 = strToDate(dat[0], '%m/%d/%Y')
    fecha_2 = strToDate(dat[1], '%m/%d/%Y')
    ciudades = map.keySet(catalogo['map_city_req2'])
    for i in range(1, lt.size(ciudades)):
        arbol = lt.getElement(ciudades, i)
        rango_set = tree.valueRange(arbol, fecha_1, fecha_2, compareByKey)
        for z in range(1, lt.size(rango_set)):
            dic = lt.getElement(rango_set, z)
            respuesta[str(i)] += dic['viajes']
    return respuesta
Esempio n. 4
0
 def test_valueRange(self):
     tree = omap.newMap()
     tree = omap.put(tree, 'A', 'Title 50', self.comparekeys)
     tree = omap.put(tree, 'C', 'Title 70', self.comparekeys)
     tree = omap.put(tree, 'E', 'Title 30', self.comparekeys)
     tree = omap.put(tree, 'H', 'Title 80', self.comparekeys)
     tree = omap.put(tree, 'L', 'Title 90', self.comparekeys)
     tree = omap.put(tree, 'M', 'Title 20', self.comparekeys)
     tree = omap.put(tree, 'P', 'Title 50', self.comparekeys)
     tree = omap.put(tree, 'R', 'Title 60', self.comparekeys)
     tree = omap.put(tree, 'S', 'Title 10', self.comparekeys)
     tree = omap.put(tree, 'X', 'Title 40', self.comparekeys)
     kList = (omap.valueRange(tree, "A", "R", self.greater))
     print("\nRBT keys between R and X")
     print(kList)
Esempio n. 5
0
def test_valueRange(self):
    """
        """
    tree = omap.newMap()

    tree = omap.put(tree, 'A', 'Title 50', self.comparestrkeys)
    tree = omap.put(tree, 'C', 'Title 70', self.comparestrkeys)
    tree = omap.put(tree, 'E', 'Title 30', self.comparestrkeys)
    tree = omap.put(tree, 'H', 'Title 80', self.comparestrkeys)
    tree = omap.put(tree, 'L', 'Title 90', self.comparestrkeys)
    tree = omap.put(tree, 'M', 'Title 20', self.comparestrkeys)
    tree = omap.put(tree, 'P', 'Title 50', self.comparestrkeys)
    tree = omap.put(tree, 'R', 'Title 60', self.comparestrkeys)
    tree = omap.put(tree, 'S', 'Title 10', self.comparestrkeys)
    tree = omap.put(tree, 'X', 'Title 40', self.comparestrkeys)
    kList = omap.valueRange(tree, 'R', 'X', self.comparestrkeys)
    print("\nRBT values between R and X")
    print(kList)
Esempio n. 6
0
def getBooksCountByYearRange(catalog, years):
    """
    Retorna la cantidad de libros por rating para un rango de años
    """

    startYear = strToDate(years.split(" ")[0], '%Y')
    endYear = strToDate(years.split(" ")[1], '%Y')
    yearList = tree.valueRange(catalog['yearsTree'], startYear, endYear,
                               greater)
    counter = 0
    if yearList:
        iteraYear = it.newIterator(yearList)
        while it.hasNext(iteraYear):
            yearElement = it.next(iteraYear)
            #print(yearElement['year'],yearElement['count'])
            counter += yearElement['count']
        return counter
    return None
Esempio n. 7
0
 def test_valueRange(self):
     """
     """
     tree = omap.newMap()
     tree = omap.put(tree, 'A', 'Title 50', self.comparekeys)
     tree = omap.put(tree, 'C', 'Title 70', self.comparekeys)
     tree = omap.put(tree, 'E', 'Title 30', self.comparekeys)
     tree = omap.put(tree, 'H', 'Title 80', self.comparekeys)
     tree = omap.put(tree, 'L', 'Title 90', self.comparekeys)
     tree = omap.put(tree, 'M', 'Title 20', self.comparekeys)
     tree = omap.put(tree, 'P', 'Title 50', self.comparekeys)
     tree = omap.put(tree, 'R', 'Title 60', self.comparekeys)
     tree = omap.put(tree, 'S', 'Title 10', self.comparekeys)
     tree = omap.put(tree, 'X', 'Title 40', self.comparekeys)
     vList = omap.valueRange(tree, 'M', 'W', self.comparekeys)
     size = lt.size(vList)
     self.assertEqual((size), 4)
     print("\nValores entre M y W")
     print(vList)