def addDate_city_trips(catalog, row): ''' Función que construye el árbol RBT de fechas. Cada nodo del árbol es a su vez un mapa de hash con cantidad de viajes indexados por ciudad ''' # Añadimos las fechas al RBT con un value igual a un map con ciudad y values = cantidad de viajes d = row['start_date'] # row del archivo trip.csv t = d.split(" ")[0] date = strToDate(t, '%m/%d/%Y') #print(date) id_station = row['start_station_id'] city_trip = tree.get(catalog['date_city_trips'], date, greater) #print(city_trip) city = station_id_city(catalog, id_station) if city_trip: if map.contains(city_trip, city): u = map.get(city_trip, city)['value'] u += 1 map.put(city_trip, city, u) catalog['date_city_trips'] = tree.put(catalog['date_city_trips'], date, city_trip, greater) else: map.put(city_trip, city, 1) catalog['date_city_trips'] = tree.put(catalog['date_city_trips'], date, city_trip, greater) else: city_trip = map.newMap(capacity=5, prime=3, maptype='CHAINING', comparefunction=compareByKey) map.put(city_trip, city, 1) catalog['date_city_trips'] = tree.put(catalog['date_city_trips'], date, city_trip, greater)
def addToTree (catalog, row): tree=catalog['dateTree'] #Árbol RBT ordenado por fecha date_raw= row['start_date'].split(" ")[0] date=strToDate(date_raw, '%m/%d/%Y') #Convertir fecha a str StationInf = map.get(catalog['stationMap'], row['start_station_id'])['value'][1] #Ciudad de la estación if oms.contains(tree, date, greater): dateValue = oms.get(tree, date, greater) if map.contains(dateValue, StationInf): value = map.get(dateValue, StationInf)['value'] map.put(dateValue, StationInf, value+1) else: map.put(dateValue, StationInf, 1) totalValue = map.get(dateValue, 'total')['value'] totalValue += 1 map.put(dateValue, 'total', totalValue) tree = oms.put(tree, date, dateValue, greater) else: DateValueMap = map.newMap(maptype='PROBING', comparefunction= compareByKey) map.put(DateValueMap, StationInf, 1) map.put(DateValueMap, 'total', 1) tree = oms.put(tree, date, DateValueMap, greater)
def put(map, key, value, comparefunction): """ Ingresa una pareja llave,valor a la tabla. Si la llave ya existe, se reemplaza el valor. Es necesario proveer una función de comparación para las llaves. """ return om.put(map, key, value, comparefunction)