Пример #1
0
def ajax_quick_search():
    origin = request.form.get('origin')
    destination = request.form.get('destination')
    max_travel_duration = int(request.form.get('max-travel-duration'))*3600
    budget = int(request.form.get('budget'))
    max_hotel_price = settings.HOTEL_THRESHOLDS.get(budget)
    directions = Directions.generate_from_google(origin, destination)
    corridors = directions.get_corridors(max_travel_duration, settings.DEFAULT_CORRIDOR_DURATION)
    for corridor in corridors:
        corridor.generate_hotels(Hotel, max_hotel_price, settings.DEFAULT_EARLY_WEIGHT, settings.DEFAULT_DETOUR_WEIGHT)
        if len(corridor.hotels) >= settings.NUMBER_OF_HOTELS_RETURNED:
            corridor.hotels = corridor.hotels[:settings.NUMBER_OF_HOTELS_RETURNED]
    return render_template("quick_search_results.html", directions=directions, corridors=corridors)
Пример #2
0
def generate_test():
    origin = 'Boston'
    destination = 'Boulder'
    max_travel_duration = 10*3600
    budget = 3
    max_hotel_price = settings.HOTEL_THRESHOLDS.get(budget)
    directions = Directions.generate_from_google(origin, destination)
    corridors = directions.get_corridors(max_travel_duration, settings.DEFAULT_CORRIDOR_DURATION)
    for corridor in corridors:
        corridor.generate_hotels(Hotel, max_hotel_price, settings.DEFAULT_EARLY_WEIGHT, settings.DEFAULT_DETOUR_WEIGHT)
        if len(corridor.hotels) >= settings.NUMBER_OF_HOTELS_RETURNED:
            corridor.hotels = corridor.hotels[:settings.NUMBER_OF_HOTELS_RETURNED]
    with open('data/test.pk', 'wb') as output:
        pickle.dump(directions, output, pickle.HIGHEST_PROTOCOL)
        pickle.dump(corridors, output, pickle.HIGHEST_PROTOCOL)
    return "Success."