Exemplo n.º 1
0
    def test_area_bottom_right(self):
        # create booking
        booking = Booking()
        booking.client = self.client
        booking.passengers = 1
        booking.luggage_number = 2
        booking.flight = "18070-12324"
        booking.departure = Geoposition(49.010247, 2.547678)
        booking.destination = Geoposition(48.792502, 2.386336)
        booking.distance = math.hypot(48.792502 - 49.010247,
                                      2.386336 - 2.547678)
        # booking.destination = "Place de la Libération, 94400 Vitry-sur-Seine"

        self.assertFalse(booking is None)

        self.assertEqual(get_area(booking), self.bottom_right)
Exemplo n.º 2
0
    def test_area_high_right(self):
        # create booking
        booking = Booking()
        booking.client = self.client
        booking.passengers = 1
        booking.luggage_number = 2
        booking.flight = "18070-12324"
        # booking.departure = "Aéroport Charles de Gaulle (T3-Roissypole), Tremblay-en-France"
        # booking.destination = "23 Rue Madeleine Vionnet, 93300 Aubervilliers"
        booking.departure = Geoposition(49.010247, 2.547678)
        booking.destination = Geoposition(48.903194, 2.374365)
        booking.distance = math.hypot(48.903194 - 49.010247,
                                      2.374365 - 2.547678)

        self.assertFalse(booking is None)

        self.assertEqual(get_area(booking), self.high_right)
Exemplo n.º 3
0
    def test_area_high_left(self):
        # create booking
        booking = Booking()
        booking.client = self.client
        booking.passengers = 1
        booking.luggage_number = 2
        booking.flight = "18070-12324"
        # booking.departure = "Aéroport Charles de Gaulle (T3-Roissypole), Tremblay-en-France"
        # booking.destination = "Place Charles de Gaulle, 75008 Paris"
        booking.departure = Geoposition(49.010247, 2.547678)
        booking.destination = Geoposition(48.873959, 2.295825)
        booking.distance = math.hypot(48.873959 - 49.010247,
                                      2.295825 - 2.547678)

        self.assertFalse(booking is None)

        self.assertEqual(get_area(booking), self.high_left)
Exemplo n.º 4
0
    def test_area_bottom_left(self):
        # create booking
        booking = Booking()
        booking.client = self.client
        booking.passengers = 1
        booking.luggage_number = 2
        booking.flight = "18070-12324"
        # booking.departure = "Aéroport Charles de Gaulle (T3-Roissypole), Tremblay-en-France"
        # booking.destination = "Champ de Mars, 5 Avenue Anatole France, 75007 Paris""
        booking.departure = Geoposition(49.010247, 2.547678)
        booking.destination = Geoposition(48.858956, 2.294512)
        booking.distance = math.hypot(48.858956 - 49.010247,
                                      2.294512 - 2.547678)

        self.assertFalse(booking is None)

        self.assertEqual(get_area(booking), self.bottom_left)
Exemplo n.º 5
0
def create_travel(booking_to_test):
    area = get_area(booking_to_test)
    place_wanted = booking_to_test.passengers
    estimated_arrive = booking_to_test.arrive_time + datetime.timedelta(
        seconds=booking_to_test.time_estimated) * 2
    model_car = booking_to_test.model_choose

    if place_wanted == 0:
        travels = None
    else:
        travels = Travel.objects.filter(
            start=booking_to_test.arrive_time,
            free_place__gte=place_wanted,
            area=area,
            airport=booking_to_test.airport,
            free_luggage__gte=booking_to_test.luggage_number)

    # The case with no travel found
    if not travels:
        car = free_car(area, booking_to_test.arrive_time, estimated_arrive)
        travel = Travel.objects.create(start=booking_to_test.arrive_time,
                                       free_place=model_car.number_place -
                                       place_wanted,
                                       free_luggage=model_car.luggage_number -
                                       booking_to_test.luggage_number,
                                       area=area,
                                       airport=booking_to_test.airport,
                                       car=car,
                                       end=estimated_arrive)
    else:
        travel = travels[0]

        # Update the leave places
        travel.free_place -= place_wanted
        travel.free_luggage -= booking_to_test.luggage_number

    travel.bookings.add(booking_to_test)

    if travel.bookings.count() > 1:
        # Optimise travel with multiples destination
        compute_travel_multiples(booking_to_test.airport,
                                 booking_to_test.arrive_time, travel)

    # update the travel
    travel.save()