Esempio n. 1
0
	def cancel_trip(self):
		if not self.__is_trip_cancellable():
			return standard_response.get_standard_api_response(False, "Trip not requested, not dispatched or already started", ApplicationErrorCodes.REQUEST_NOT_FULFILLED)

		self.__trip_status = trip_status.TRIP_CANCELLED
		self.__cab_action.deallocate_cab()

		return standard_response.get_standard_api_response(True, "", ApplicationErrorCodes.SUCCESS, self.to_dict())
Esempio n. 2
0
	def start_trip(self):
		if self.__trip_status != trip_status.TRIP_DISPATCHED:
			return standard_response.get_standard_api_response(False, "Trip not requested / dispatched", ApplicationErrorCodes.REQUEST_NOT_FULFILLED)

		self.__trip_start_time = datetime.datetime.now()
		self.__trip_status = trip_status.TRIP_STARTED

		return standard_response.get_standard_api_response(True, "", ApplicationErrorCodes.SUCCESS, self.to_dict())
Esempio n. 3
0
	def end_trip(self):
		if self.__trip_status != trip_status.TRIP_STARTED:
			return standard_response.get_standard_api_response(False, "Trip not started", ApplicationErrorCodes.REQUEST_NOT_FULFILLED)

		self.__trip_status = trip_status.TRIP_COMPLETED		
		self.__cab_action.deallocate_cab()
		self.__cab_action.update_cab_location(self.__request.get_trip_end_location())
		self.__trip_distance = utils.get_trip_distance(self.__request.get_trip_start_location(), self.__request.get_trip_end_location())
		self.__trip_duration = utils.get_trip_timing(self.__trip_distance)  # self.__trip_end_time - self.__trip_start_time
		self.__trip_end_time = self.__trip_start_time + datetime.timedelta(minutes = int(self.__trip_duration)) # datetime.now()
		self.__order = Order(self.__trip_id, self.__request.get_trip_customer(), self.__trip_distance, self.__trip_duration, self.__request.get_trip_preference().get_cab_color())

		return standard_response.get_standard_api_response(True, "", ApplicationErrorCodes.SUCCESS, self.to_dict())
Esempio n. 4
0
	def start_trip(self, trip_id, *args, **kwargs):
		try:
			trip = self.__trip_registry.get_trip_info(trip_id)
		except Exception as e:
			return standard_response.get_standard_api_response(False, str(e), ApplicationErrorCodes.REQUEST_NOT_FULFILLED)
		
		trip_data = trip.start_trip()

		return trip_data
Esempio n. 5
0
	def process_trip_request(self, trip_request, *args, **kwargs):
		try:
			allocated_cab_action_obj = self.__cab_dispatcher.allocate_cab_if_available(trip_request.get_trip_start_location(), trip_request.get_trip_preference())
		except Exception as e:
			return standard_response.get_standard_api_response(False, str(e), ApplicationErrorCodes.REQUEST_NOT_FULFILLED)

		trip_data = Trip(trip_request, allocated_cab_action_obj, self.__trip_registry)

		return trip_data.get_standard_trip_response()
Esempio n. 6
0
	def get_standard_trip_response(self):
		return standard_response.get_standard_api_response(True, "", ApplicationErrorCodes.SUCCESS, self.to_dict())