Пример #1
0
 public Test_TripLifeCycle_Base(
     string filename,
     Gateway tripthru,
     TimeSpan? maxLateness = null,
     PartnerTrip.Origination? origination = null,
     PartnerTrip.Origination? service = null,
     double? locationVerificationTolerance = null)
 {
     this.filename = filename;
     this.tripthru = tripthru;
     if (maxLateness != null)
         this.maxLateness = (TimeSpan)maxLateness;
     if (origination != null)
         this.origination = origination;
     if (service != null)
         this.service = service;
     if (locationVerificationTolerance != null)
         this.locationVerificationTolerance = (double)locationVerificationTolerance;
     PartnerConfiguration configuration = Partner.LoadPartnerConfigurationFromJsonFile(filename);
     partner = new Partner(configuration.Partner.ClientId, configuration.Partner.Name, new GatewayClientMock(tripthru), configuration.partnerFleets);
     partner.tripthru.RegisterPartner(partner);
 }
Пример #2
0
 // TODO: make these more real
 public double GetPrice(PartnerTrip trip)
 {
     return baseCost + (GetDistance(trip) * costPerMile); // once we have the distance it won't be too hard to come up with some prices.
 }
Пример #3
0
 private void ProcessStatusEnroute(PartnerTrip t)
 {
     if (TripServicedByForeignProvider(t))
         return; // partner.GetTripStatusFromForeignServiceProvider(t, true);
     else
     {
         UpdateTripDriverLocation(t);
         if (DriverHasReachedThePickupLocation(t))
             MakeTripPickedUp(t);
         else if (TripStatusUpdateIntervalReached(t))
             LogTheNewDriverLocation(t);
     }
 }
Пример #4
0
 private bool MissedPeriodReached(PartnerTrip t)
 {
     return DateTime.UtcNow > t.pickupTime + missedPeriod;
 }
Пример #5
0
 private void MakeTripEnroute(PartnerTrip trip)
 {
     Logger.Log("Driver is now enroute: " + trip);
     Logger.Tab();
     DateTime eta = UpdateDriverRouteAndGetETA(trip.driver, trip.pickupLocation);
     trip.UpdateTripStatus(notifyPartner: true, status: Status.Enroute, driverLocation: trip.driver.location, eta: eta);
     Logger.Untab();
 }
Пример #6
0
        void DispatchTrip(PartnerTrip t)
        {
            if (TripOriginatedLocally(t))
            {
                if (MissedPeriodReached(t))
                {
                    CancelTrip(t);
                    return;
                }
                if (TripServicedByForeignProvider(t)) // means serviced through partner
                    return;
            }
            // If origination is foreign, then it means we're servicing the trip so we have to process it.
            if (CriticalPeriodNotYetReached(t))
                return;
            Logger.Log("Ready for dispatch: " + t);
            Logger.Tab();

            if (!TryDispatchTripLocally(t) && TripOriginatedLocally(t))
                TryToDispatchToForeignProvider(t);
            Logger.Untab();
        }
Пример #7
0
 private bool DispatchRetryIntervalReached(PartnerTrip t)
 {
     return DateTime.UtcNow > t.lastDispatchAttempt + retryInterval;
 }
Пример #8
0
 private static void UpdateTripDriverLocation(PartnerTrip t)
 {
     t.driver.location = t.driver.route.GetCurrentWaypoint(t.driver.routeStartTime, DateTime.UtcNow);
 }
Пример #9
0
 private static void CancelTrip(PartnerTrip t)
 {
     Logger.Log("Missed period reached: -- so cancel " + t);
     Logger.Tab();
     t.UpdateTripStatus(notifyPartner: true, status: Status.Cancelled);
     Logger.Untab();
 }
Пример #10
0
 private static bool AgeSinceCompletedClock_HasNotBeenSet(PartnerTrip t)
 {
     return t.dropoffTime == null;
 }
Пример #11
0
 public bool TryDispatchTripLocally(PartnerTrip t)
 {
     Logger.Log("DispatchTripLocally");
     if (!FleetServesLocation(t.pickupLocation))
     {
         Logger.Log("Pickup location " + t.pickupLocation + " is outside of coverage area");
         return false;
     }
     if (t.status != Status.Queued)
         throw new Exception("Invalid 'Dispatch' status");
     if (ThereAreAvailableDrivers())
     {
         DispatchToFirstAvailableDriver(t);
         t.UpdateTripStatus(notifyPartner: true, status: Status.Dispatched, driverLocation: t.driver.location, eta: t.pickupTime);
         return true;
     }
     Logger.Log("No drivers are currently available");
     return false;
 }
Пример #12
0
 public bool TripStatusUpdateIntervalReached(PartnerTrip t)
 {
     return DateTime.UtcNow > t.lastUpdate + updateInterval;
 }
Пример #13
0
 public void RemoveTrip(PartnerTrip t)
 {
     queue.Remove(queue.Find(t));
 }
Пример #14
0
 public bool QueueTrip(PartnerTrip t)
 {
     lock (locker)
     {
         if (availableDrivers.Count == 0 && t.origination == PartnerTrip.Origination.Foreign)
             return false; // don't except from parters if no available drivers
         Logger.Log("Queueing " + t);
         queue.AddLast(t);
         partner.tripsByID.Add(t.ID, t);
         partner.activeTrips.Add(t.ID, new Trip
         {
             FleetId = t.PartnerFleet != null ? t.PartnerFleet.ID : null,
             FleetName = t.PartnerFleet != null ? t.PartnerFleet.name : null,
             DriverId = t.driver != null ? t.driver.ID : null,
             DriverLocation = t.driver != null ? t.driver.location : null,
             DriverName = t.driver != null ? t.driver.name : null,
             DropoffLocation = t.dropoffLocation,
             DriverInitiaLocation = null,
             DropoffTime = t.dropoffTime,
             Id = t.ID,
             OriginatingPartnerId = this.ID,
             OriginatingPartnerName = this.name,
             PassengerName = t.passengerName,
             PickupLocation = t.pickupLocation,
             PickupTime = t.pickupTime,
             Price = t.price,
             Status = t.status,
             VehicleType = t.vehicleType,
         });
         t.UpdateTripStatus(notifyPartner: false, status: Status.Queued);
         return true;
     }
 }
Пример #15
0
 public void ProcessTrip(PartnerTrip t)
 {
     //Logger.LogDebug("Processing " + t);
     lock (locker)
     {
         switch (t.status)
         {
             case Status.New:
                 {
                     Logger.Log("Unexpected status (New): Something wrong with " + t);
                     break;
                 }
             case Status.Queued:
                 {
                     ProcessStatusQueued(t);
                     break;
                 }
             case Status.Dispatched:
                 {
                     ProcessStatusDispatched(t);
                     break;
                 }
             case Status.Enroute:
                 {
                     ProcessStatusEnroute(t);
                     break;
                 }
             case Status.PickedUp:
                 {
                     ProcessStatusPickedUp(t);
                     break;
                 }
         }
     }
 }
Пример #16
0
 private static bool TripOriginatedLocally(PartnerTrip t)
 {
     return t.origination == PartnerTrip.Origination.Local;
 }
Пример #17
0
 private static bool TripServicedByForeignProvider(PartnerTrip t)
 {
     return t.service == PartnerTrip.Origination.Foreign;
 }
Пример #18
0
 private static bool DestinationReached(PartnerTrip t)
 {
     return t.driver.location.Equals(t.driver.route.end);
 }
Пример #19
0
 private bool CriticalPeriodNotYetReached(PartnerTrip t)
 {
     return DateTime.UtcNow < t.pickupTime - criticalPeriod;
 }
Пример #20
0
 private static bool DriverHasReachedThePickupLocation(PartnerTrip t)
 {
     return t.driver.location.Equals(t.pickupLocation);
 }
Пример #21
0
 private void DispatchToFirstAvailableDriver(PartnerTrip t)
 {
     if (availableDrivers.Count == 0)
         throw new Exception("Invalid condition: no available drivers");
     t.driver = availableDrivers.First();
     t.PartnerFleet = this;
     availableDrivers.RemoveFirst();
     //throw new Exception("driver = " + t.driver + ", name = " + t.driver.name);
     if (t.driver == null)
         throw new Exception("Invalid condition: driver object null");
     Logger.Log("Dispatched to " + t.driver.name);
 }
Пример #22
0
 private static bool DriverWillBeLateIfHeDoesntLeaveNow(PartnerTrip t)
 {
     return DateTime.UtcNow >= t.pickupTime - MapTools.GetRoute(t.driver.location, t.pickupLocation).duration;
 }
Пример #23
0
 private void MakeTripComplete(PartnerTrip t)
 {
     Logger.Log("The destination has been reached for: " + t);
     Logger.Tab();
     t.dropoffTime = DateTime.UtcNow;
     CompleteTrip(t);
     t.UpdateTripStatus(notifyPartner: true, status: Status.Complete);
     Logger.Untab();
 }
Пример #24
0
 private static TimeSpan GetAgeSinceCancelledOrRejected(PartnerTrip t)
 {
     return DateTime.UtcNow - (DateTime)t.pickupTime;
 }
Пример #25
0
 private void MakeTripPickedUp(PartnerTrip trip)
 {
     Logger.Log("Picking up: " + trip);
     Logger.Tab();
     DateTime eta = UpdateDriverRouteAndGetETA(trip.driver, trip.dropoffLocation);
     trip.UpdateTripStatus(notifyPartner: true, status: Status.PickedUp, driverLocation: trip.driver.location, eta: eta);
     Logger.Untab();
 }
Пример #26
0
 private static TimeSpan GetAgeSinceCompleted(PartnerTrip t)
 {
     return DateTime.UtcNow - (DateTime)t.dropoffTime;
 }
Пример #27
0
 private void ProcessStatusDispatched(PartnerTrip t)
 {
     if (TripServicedByForeignProvider(t))
         return; // partner.GetTripStatusFromForeignServiceProvider(t, true);
     else if (DriverWillBeLateIfHeDoesntLeaveNow(t))
         MakeTripEnroute(t);
     else if (TripStatusUpdateIntervalReached(t))
         LogTheNewDriverLocation(t);
 }
Пример #28
0
 private static void LogTheNewDriverLocation(PartnerTrip t)
 {
     Logger.Log("Getting status of: " + t);
     t.lastUpdate = DateTime.UtcNow;
 }
Пример #29
0
 private void ProcessStatusPickedUp(PartnerTrip t)
 {
     if (TripServicedByForeignProvider(t))
         return; // partner.GetTripStatusFromForeignServiceProvider(t, true);
     else
     {
         UpdateTripDriverLocation(t);
         if (DestinationReached(t))
             MakeTripComplete(t);
         else if (TripStatusUpdateIntervalReached(t))
             LogTheNewDriverLocation(t);
     }
 }
Пример #30
0
 private static void StartTheAgeSinceCompletedClock_FromNow(PartnerTrip t)
 {
     t.dropoffTime = DateTime.UtcNow;
 }