def get_prices_cheaper_than_round_trip(results_from_db, flight_checker): cheap_airports = {} expensive_airports = {} for index, result in enumerate(results_from_db): final_prices = result["connections"] origin = result["key"][0:3] dest = result["key"][4:7] area = flight_checker.pricer.flights_provider.flights_resp_dal.get_area_code(origin, dest) result = get_cheapest_flight(final_prices) round_trip_price = result[0] if not round_trip_price: continue for options in final_prices: for price in options: airport = get_upper_word(price[0]) if airport: if price[1] < round_trip_price: if not cheap_airports.has_key(area): cheap_airports[area] = set() cheap_airports[area].add(airport) else: if not expensive_airports.has_key(area): expensive_airports[area] = {} if not expensive_airports[area].has_key(airport): expensive_airports[area][airport] = list() expensive_airports[area][airport].append((price[1]-round_trip_price)*100/round_trip_price) expensive_airports = clean_airports_which_are_cheaper(expensive_airports, cheap_airports) return cheap_airports, expensive_airports
def get_chepaset_prices(results): prices = [] for index, result in enumerate(results): final_prices = result["connections"] round_trip_price, cheapest_trip_price, cheapest_flight, cheapest_type = get_cheapest_flight(final_prices) #get_cheapest_flight only returns values if there was a round trip price if round_trip_price and cheapest_trip_price: prices.append((round_trip_price, cheapest_trip_price, cheapest_flight, cheapest_type, result["key"])) return prices
print "Finished loading %d tests" % i break # first time only for it to be entered to the DB, the second is for actual analyzing # tests_to_run = tests_to_run[0:300] for index, test in enumerate(tests_to_run): print test, index final_prices = new_single_check(*test, vayant_connector=vayant_connector) if not final_prices: tests_to_run.remove(test) with open("updated_tests.info", "w") as tests_file: for test in tests_to_run: pickle.dump(test, tests_file) for index, test in enumerate(tests_to_run): print test, index final_prices = new_single_check(*test, flight_checker=FlightChecker()) round_trip_price, cheapest_trip_price, flight, cheapest_type = get_cheapest_flight(final_prices) if round_trip_price and cheapest_trip_price: prices.append((round_trip_price, cheapest_trip_price)) total_precentage_saving = 0 for price in prices: percentage_saved = (price[0] - price[1]) / price[0] total_precentage_saving += percentage_saved saved_in_avergae = total_precentage_saving / len(prices) print saved_in_avergae, len(prices)