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_ids: set = {r.event_ref.id for rid, r in ride_requests.items()} assert len(event_ids) == 1 event_ref = EventDao().get_ref(event_ids.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 = LocationGenericDao().get(location_ref) 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
def remove_match_tmp(ride_request_id): ride_request_ref = RideRequestGenericDao( ).rideRequestCollectionRef.document(ride_request_id) ride_request = RideRequestGenericDao().get(ride_request_ref) orbit_ref = ride_request.orbit_ref orbit = OrbitDao().get(orbit_ref) group_actions.remove_from_orbit(ride_request, orbit)
def testCreateOrbit(self): newOrbit = Orbit.from_dict(orbitDict) orbitRef = OrbitDao().create(newOrbit) self.to_delete.append(orbitRef) self.assertIsNotNone(orbitRef)
def generate_orbit(event_ref) -> Orbit: orbit_dict = store.get_orbit_dict_empty(event_ref) orbit = Orbit.from_dict(orbit_dict) OrbitDao().create(orbit) return orbit
def execute(self) -> set: """ This method puts rideRequests into orbit and update participants eventSchedule in atomic operations. Note that ids of ride requests not dropped from the orbit is not returned. :return: a list of rideRequests that are not joined """ transaction = self.transaction orbit = self.orbit # Create a transaction so that an exception is thrown when updating an object that is # changed since last read from database existing_ids = {rid for rid, r in self.ride_requests_existing.items()} joined_ids, not_joined_ids = OrbitGroup._add( to_add=self.ride_requests_to_add, orbit=orbit) dropped_ids, not_dropped_ids = OrbitGroup._drop( to_drop=self.ride_requests_to_drop, orbit=orbit) # Update database copy of rideRequests that was just joined # TODO: Implement update_all method to refresh all ride requests dropped, added, and etc. # (no need for now since ride request is independent from orbit) # TODO: test that all ride requests are covered # Update database copy of orbit OrbitDao.set_with_transaction(transaction, orbit, orbit.get_firestore_ref()) # refresh event schedule for each user in_orbit: dict = OrbitGroup._get_in_orbit( existing_ids=id_set_from_dict(self.ride_requests_existing), just_joined_ids=joined_ids, just_exited_ids=dropped_ids, existing_r=self.ride_requests_existing, to_add_r=self.ride_requests_to_add, to_drop_r=self.ride_requests_to_drop) not_in_orbit: dict = OrbitGroup._get_not_in_orbit( not_joined_ids=not_joined_ids, dropped_ids=dropped_ids, existing_r=self.ride_requests_existing, to_drop_r=self.ride_requests_to_drop) _refresh_ride_requests_all(transaction=transaction, in_orbit=in_orbit, not_in_orbit=not_in_orbit, orbit=orbit, event=self.event, location=self.location) _refresh_event_schedules_all(transaction=transaction, in_orbit=in_orbit, not_in_orbit=not_in_orbit, orbit=orbit, event=self.event, location=self.location) print( "About to commit: just joined ids {}; not joined ids {}; just dropped ids: {}; not_dropped_ids: {}; all " "ids in orbit after operation: {} ".format(joined_ids, not_joined_ids, dropped_ids, not_dropped_ids, in_orbit.keys())) return not_joined_ids
def _get_orbit(transaction: Transaction = None, orbit_id: str = None) -> Orbit: orbit_ref = OrbitDao().ref_from_id(orbit_id) return OrbitDao.get_with_transaction(transaction, orbit_ref)