def addService(analyzer, service): company = service['company'] taxi_id = service['taxi_id'] service_id = service['trip_id'] if service['trip_total'] is not '': money = float(service['trip_total']) else: money = 0 if service['trip_miles'] is not '': distance = float(service['trip_miles']) else: distance = 0 date = getDate(service['trip_start_timestamp']) if company == '': company = 'Independent Owner' if not ipq.contains(analyzer['TaxiPQ']['PQ'], company): taxilist = lt.newList(datastructure='ARRAY_LIST', cmpfunction=compareCompanies2) if not lt.isPresent(taxilist, taxi_id): lt.addLast(taxilist, taxi_id) m.put(analyzer['TaxiPQ']['Map'], company, taxilist) ipq.insert(analyzer['TaxiPQ']['PQ'], company, 1) else: taxilist = me.getValue(m.get(analyzer['TaxiPQ']['Map'], company)) if not lt.isPresent(taxilist, company): if not lt.isPresent(taxilist, taxi_id): lt.addLast(taxilist, taxi_id) ipq.increaseKey(analyzer['TaxiPQ']['PQ'], company, lt.size(taxilist)) if not ipq.contains(analyzer['ServicePQ']['PQ'], company): servicelist = lt.newList(datastructure='ARRAY_LIST', cmpfunction=compareCompanies2) lt.addLast(servicelist, service_id) m.put(analyzer['ServicePQ']['Map'], company, servicelist) ipq.insert(analyzer['ServicePQ']['PQ'], company, 1) else: servicelist = me.getValue(m.get(analyzer['ServicePQ']['Map'], company)) if not lt.isPresent(servicelist, company): lt.addLast(servicelist, service_id) ipq.increaseKey(analyzer['ServicePQ']['PQ'], company, lt.size(servicelist)) if not m.contains(analyzer["TaxiNum"],company): m.put(analyzer["TaxiNum"],company,{"Taxi":0}) else: valor=me.getValue(m.get(analyzer["TaxiNum"],company)) valor["Taxi"]+=1 if money > 0 and distance > 0: uptadePointsTree(analyzer, date, taxi_id, money, distance) addServiceToGraph(analyzer, service) return analyzer
def test_insert(iminpq): iminpq = pq.decreaseKey(iminpq, 'A', 1) key = pq.min(iminpq) assert key == 'A' iminpq = pq.increaseKey(iminpq, 'A', 12) key = pq.min(iminpq) assert key == 'D'
def addConnection(bikes, origin, destination, duration): edge = gr.getEdge(bikes["grafo"], origin, destination) if edge is None: gr.addEdge(bikes["grafo"], origin, destination, duration) else: initial = edge["weight"] edge["weight"] = ((int(initial) + int(duration)) / 2) llegada = gr.indegree(bikes["grafo"], destination) salida = gr.outdegree(bikes["grafo"], origin) llegadad = gr.indegree(bikes["grafo"], destination) salidad = salida = gr.outdegree(bikes["grafo"], origin) oruse = salida + llegadad desuse = llegada + salidad llegadainv = 1 / llegada salidainv = 1 / salida iminpq.increaseKey(bikes["topuso"], destination, desuse) iminpq.increaseKey(bikes["topuso"], origin, oruse) iminpq.decreaseKey(bikes["topllegada"], destination, llegadainv) iminpq.decreaseKey(bikes["topsalida"], origin, salidainv) return bikes