コード例 #1
0
 def from_location(self, value):
     if value != '' and value is not None:
         if "/" in value:
             self.ride_host.from_location = Location.get(
                 doc_ref_str=value)
         else:
             self.ride_host.from_location = Location.get(doc_id=value)
コード例 #2
0
 def to_location(self, value):
     if value != '' and value is not None:
         if "/" in value:
             self.rider_booking.to_location = Location.get(
                 doc_ref_str=value)
         else:
             self.rider_booking.to_location = Location.get(doc_id=value)
コード例 #3
0
def _create_airport_ride_request(args, user_id):
    """ Creates an airport ride request with arguments received by REST API endpoint

    :param args: argument dict returned by .parse_args() from a reqparse object
    :param user_id: user id
    :return: RideRequest object
    """
    builder = AirportRideRequestBuilder()
    ride_request: AirportRideRequest = builder \
        .set_with_form_and_user_id(args, user_id) \
        .build_airport_ride_request() \
        .export_as_class(AirportRideRequest)
    location = Location.get(
        doc_id=any_to_doc_id(ride_request.airport_location)
    )
    if ride_request.target.to_event:
        # TODO: fix
        user_location = Location.get(
            doc_id=any_to_doc_id(ride_request.origin_ref)
        )
    else:
        raise ValueError("to_event is False ")
    # Do Validation Tasks before saving rideRequest
    # 1. Check that rideRequest is not submitted by the same user
    #       for the flight on the same day already
    # TODO: move to transactional logic for better atomicity
    if utils.check_duplicate(ride_request.user_id, ride_request.event_ref):
        raise service_errors.RequestAlreadyExistsError
    # Starts database operations to (save rideRequest and update user's eventSchedule)
    transaction = db.transaction()
    # Transactional business logic for adding rideRequest
    utils.add_ride_request(transaction, ride_request, location, user_id)
    # Save write result
    transaction.commit()
    return ride_request
コード例 #4
0
    def to_tuple_point(self, to_event = True):
        """ Returns a tuple (actually a list) representation of the ride request
            as a point for grouping algorithm.

        :return:
        """

        assert to_event is True

        # Time-related
        to_event_target: ToEventTarget = self.target
        earliest = to_event_target.arrive_at_event_time['earliest']
        latest = to_event_target.arrive_at_event_time['latest']

        # Tag to identify ride request
        ref = self.get_firestore_ref()

        # Location-related
        pickup_location_ref = None
        if self.target.to_event:
            pickup_location_ref = self.origin_ref
        else:
            raise ValueError("Pickup address of to_event=False is not supported. ")
        location = Location.get(doc_id=any_to_doc_id(pickup_location_ref.id))
        coordinates = location.coordinates
        latitude = coordinates["latitude"]
        longitude = coordinates["longitude"]

        # Form tuple ()
        t = [earliest, latest, latitude, longitude, ref]
        return t
コード例 #5
0
ファイル: actions.py プロジェクト: billyrrr/gravitate-backend
def run_orbit_group(ride_requests: dict):
    """ Create an orbit and group ride requests into the orbit.

    :param ride_requests: ride requests to place in the same orbit.
    :return: ride requests that could not be joined
    """
    assert len(ride_requests) != 0
    event_refs: set = {r.event_ref for rid, r in ride_requests.items()}
    assert len(event_refs) == 1
    event_ref = event_refs.pop()

    orbit = Orbit.from_dict({
        "orbitCategory": "airportRide",
        "eventRef": event_ref,
        "userTicketPairs": {
        },
        "chatroomRef": None,
        "costEstimate": 987654321,
        "status": 1
    })
    orbit_ref = OrbitDao().create(orbit)
    orbit.set_firestore_ref(orbit_ref)
    event = EventDao().get(event_ref)
    location_ref: DocumentReference = event.location_ref
    location = Location.get(doc_id=location_ref.id)
    ride_request_refs = [r.get_firestore_ref() for rid, r in ride_requests.items()]

    transaction = db.transaction()
    # TODO: implement and call validate_entities_not_changed
    not_joined = _add_to_group(transaction, orbit_ref, ride_request_refs, event_ref, location_ref)
    return not_joined
コード例 #6
0
 def _get_dropoff_address(self):
     dropoff_location_ref = None
     if not self.target.to_event:
         dropoff_location_ref = self.destination_ref
     else:
         raise ValueError("Pickup address of to_event=True is not supported. ")
     location = Location.get(dropoff_location_ref)
     return location.address
コード例 #7
0
 def location(self):
     """
         Note that this method is non-transactional. We are assuming that
                 Location objects are immutable and ready before the transaction.
         :return:
     """
     location_ref = self.location_ref
     location = Location.get(doc_id=location_ref.id)
     return location
コード例 #8
0
    def testGet(self):

        l = model.getLocation()
        l.save()
        doc_id = l.doc_id
        self.to_delete.append(l.doc_ref)

        location = Location.get(doc_id=doc_id)
        self.assertIsNotNone(location)
        print(location.to_dict())
コード例 #9
0
 def testGetUserLocation(self):
     location = LocationFactory.from_pickup_address("Tenaya Hall, San Diego, CA 92161")
     location.save()
     ref = location.doc_ref
     self.to_delete.append(ref)
     location = Location.get(doc_id=location.doc_id)
     d = location.to_dict()
     self.assertDictContainsSubset({
         'obj_type': "UserLocation",
         'coordinates': {'latitude': 32.8794203, 'longitude': -117.2428555},
         'address': 'Tenaya Hall, San Diego, CA 92161',
     }, d)
コード例 #10
0
    def _get_pickup_address(self):
        """
        Note that this method is non-transactional. We are assuming that
            Location objects are immutable and ready before the transaction.
        :return:
        """
        pickup_location_ref = None
        if self.target.to_event:
            pickup_location_ref = self.origin_ref
        else:
            raise ValueError("Pickup address of to_event=False is not supported. ")
        # if self._transaction is not None:
        #     location = LocationGenericDao().get_with_transaction(self._transaction, pickup_location_ref)
        #     return location.address
        # else:

        location = Location.get(doc_id=any_to_doc_id(pickup_location_ref))
        return location.address
コード例 #11
0
 def _get_location(transaction: Transaction = None,
                   location_id: str = None) -> Type[Location]:
     return Location.get(doc_id=location_id, transaction=transaction)