public Driver(string name, PartnerFleet PartnerFleet = null, Location location = null)
     : base(name)
 {
     if (PartnerFleet != null)
         PartnerFleet.AddDriver(this);
     this.PartnerFleet = PartnerFleet;
     this.location = location;
     lastUpdate = DateTime.UtcNow;
 }
        static public PartnerConfiguration LoadPartnerConfigurationFromJsonFile(string filename)
        {
            string partnerConfiguration = File.ReadAllText(filename);
            var configuration = JsonSerializer.DeserializeFromString<PartnerConfiguration>(partnerConfiguration);

            configuration.partnerFleets = new List<PartnerFleet>();

            foreach (var partnerFleet in configuration.Fleets)
            {
                var vehicleTypes = partnerFleet.VehicleTypes;

                var trips = new List<Pair<Location, Location>>();
                foreach (var trip in partnerFleet.PossibleTrips)
                {
                    trips.Add(new Pair<Location, Location>(new Location(trip.Start.Lat, trip.Start.Lng), new Location(trip.End.Lat, trip.End.Lng)));
                }

                var location = partnerFleet.Location;
                var coverage = partnerFleet.Coverage;
                var drivers = partnerFleet.Drivers != null ? partnerFleet.Drivers.Select(driver => new Driver(driver)).ToList() : new List<Driver>();
                var passengers = partnerFleet.Passengers.Select(passenger => new Passenger(passenger)).ToList();
                if (coverage == null)
                    coverage = new List<Zone>();
                if (vehicleTypes == null)
                    vehicleTypes = new List<VehicleType>();

                var fleet = new PartnerFleet(
                    name: partnerFleet.Name,
                    location: location,
                    coverage: coverage,
                    drivers: drivers,
                    vehicleTypes: vehicleTypes,
                    possibleTrips: trips,
                    baseCost: partnerFleet.BaseCost,
                    costPerMile: partnerFleet.CostPerMile,
                    tripsPerHour: partnerFleet.TripsPerHour,
                    passengers: passengers);

                configuration.partnerFleets.Add(fleet);
            }
            return configuration;

        }
 public void AddPartnerFleet(PartnerFleet f)
 {
     f.partner = this;
     PartnerFleets.Add(f.ID, f);
 }
 public Passenger(string name, PartnerFleet PartnerFleet = null)
     : base(name)
 {
     this.PartnerFleet = PartnerFleet;
 }
 public PartnerTrip(Partner partner, string ID, Origination origination, Location pickupLocation, DateTime pickupTime, PaymentMethod? paymentMethod = null, string passengerID = null, string passengerName = null, Location dropoffLocation = null,
    DateTime? dropoffTime = null, List<Location> waypoints = null, VehicleType? vehicleType = null, double? maxPrice = null, int? minRating = null, PartnerFleet fleet = null, Driver driver = null, TimeSpan? duration = null, TimeSpan? driverRouteDuration = null, double? price = null)
 {
     this.ID = ID;
     this.origination = origination;
     this.service = Origination.Local;
     this.partner = partner;
     this.passengerID = passengerID;
     this.passengerName = passengerName;
     this.pickupLocation = pickupLocation;
     this.pickupTime = pickupTime;
     this.duration = duration;
     this.dropoffLocation = dropoffLocation;
     this.dropoffTime = dropoffTime;
     this.waypoints = waypoints;
     this.paymentMethod = paymentMethod;
     this.vehicleType = vehicleType;
     this.maxPrice = maxPrice;
     this.minRating = minRating;
     this.PartnerFleet = fleet;
     this.driver = driver;
     this.price = price;
     this.UpdateTripStatus(notifyPartner: false, status: Status.New);
 }
 public PartnerTrip(PartnerTrip t)
 {
     this.ID = t.ID;
     this.passengerID = t.passengerID;
     this.passengerName = t.passengerName;
     this.origination = t.origination;
     this.service = t.service;
     this.luggage = t.luggage;
     this.persons = t.persons;
     this.pickupLocation = t.pickupLocation;
     this.pickupTime = t.pickupTime;
     this.duration = t.duration;
     this.dropoffLocation = t.dropoffLocation;
     this.dropoffTime = t.dropoffTime;
     this.waypoints = t.waypoints;
     this.paymentMethod = t.paymentMethod;
     this.vehicleType = t.vehicleType;
     this.price = t.price;
     this.maxPrice = t.maxPrice;
     this.minRating = t.minRating;
     this.PartnerFleet = t.PartnerFleet;
     this.driver = t.driver;
     this.lastUpdate = t.lastUpdate;
     this._status = t._status;
     this.partner = t.partner;
     this.lastDispatchAttempt = DateTime.MinValue;
 }
Esempio n. 7
0
 public UnitTest_SingleTripLifecycleAndReturningDriver(Test_TripLifeCycle_Base parent, PartnerFleet fleet, Pair<Location, Location> tripSpec)
 {
     if (parent == null)
         throw new Exception("parent must be defined");
     this.parent = parent;
     this.fleet = fleet;
     this.tripSpec = tripSpec;
 }
Esempio n. 8
0
 private void WaitUntilStatusReachedOrTimeout(PartnerFleet fleet, PartnerTrip trip, DateTime timeoutAt)
 {
     Status startingStatus = trip.status;
     do
     {
         // There's a reason we're calling ProcessTrip instead of ProcessQueue, as when there are multiple trips in a queue, a call to ProcessQueue
         // may end up processing more than one queue.  Then it may seem like trips jump a state (status).
         fleet.ProcessTrip(trip);
         Thread.Sleep(simInterval);
     } while (trip.status == startingStatus && DateTime.UtcNow < timeoutAt);
 }
Esempio n. 9
0
 public void ValidateReturningDriverRouteIfServiceLocal(PartnerFleet fleet, PartnerTrip trip)
 {
     if (trip.service == PartnerTrip.Origination.Foreign)
         return;
     Status currentStatus = trip.status;
     Assert.AreNotEqual(trip.ETA, null, "The trip ETA is null. Trip ID");
     DateTime timeoutAt = (DateTime) trip.ETA + maxLateness;
     while (!trip.driver.location.Equals(fleet.location, tolerance: locationVerificationTolerance))
     {
         fleet.UpdateReturningDriverLocations();
         //Assert.IsFalse(DateTime.UtcNow > timeoutAt, "The timeoutAt is less than UtcNow. Trip ID: " + trip.ID);
         System.Threading.Thread.Sleep(simInterval);
     }
 }
Esempio n. 10
0
        public void ValidateNextTripStatus(PartnerFleet fleet, PartnerTrip trip, Status nextStatus)
        {
            ValidateOriginationAndService(trip);
            if (trip.status == nextStatus)
                ValidateTripThruStatus(trip);
            WaitUntilStatusReachedOrTimeout(fleet, trip, GetTimeWhenStatusShouldBeReached(trip));

            Assert.AreEqual(nextStatus, trip.status, "The 'trip' not advance to the next status. Trip ID: " + trip.ID);
            switch (trip.status)
            {
                case Status.Enroute:
                    Assert.IsNotNull(trip.driverLocation, "The trip is route but the driverLocation is null. Trip ID: " + trip.ID);
                    break;
                case Status.PickedUp:
                    Assert.IsNotNull(trip.driverLocation, "The trip is PickedUp but the driverLocation is null. Trip ID: " + trip.ID);
                    Assert.IsTrue(trip.driverLocation.Equals(trip.pickupLocation, tolerance: locationVerificationTolerance), "The trip is PickedUp but the driverLocation is out to the tolerance area. Trip ID: " + trip.ID);
                    break;
                case Status.Complete:
                    Assert.IsNotNull(trip.driverLocation, "The trip is Complete but the driverLocation is null. Trip ID: " + trip.ID);
                    Assert.IsTrue(trip.driverLocation.Equals(trip.dropoffLocation, tolerance: locationVerificationTolerance), "The trip is Complete but the driverLocation is out to the tolerance area. Trip ID: " + trip.ID);
                    break;
            }
        }
Esempio n. 11
0
        public void TestTripLifecycle_FromNewToComplete(PartnerFleet fleet, PartnerTrip trip)
        {
            int activeTrips, response;
            Assert.AreEqual(Status.New, trip.status,"The trip: " + trip.ID + " no is a new trip.");

            lock (fleet)
            {
                fleet.QueueTrip(trip);
                response = partner.tripsByID.Count(t => t.Value.origination == PartnerTrip.Origination.Local && t.Value.status != Status.Complete);
                activeTrips = ++_activeTrips;
            }

            Assert.AreEqual(Status.Queued, trip.status, "The trip: " + trip.ID + " no is a Queued trip.");
            Assert.AreEqual(activeTrips, response, "The activeTrips");
            ValidateNextTripStatus(fleet, trip, Status.Dispatched);
            ValidateNextTripStatus(fleet, trip, Status.Enroute);
            ValidateNextTripStatus(fleet, trip, Status.PickedUp);
            ValidateNextTripStatus(fleet, trip, Status.Complete);

            lock (fleet)
            {
                var trips = partner.tripsByID.Where(
                    t => t.Value.origination == PartnerTrip.Origination.Local && t.Value.status == Status.Complete);

                foreach (var tripp in trips)
                {
                    try
                    {
                        if (tripsList.Contains(tripp.Key)) continue;
                        tripsList.Add(tripp.Key);
                        --_activeTrips;
                    }catch
                    {}
                }
            }
        }
Esempio n. 12
0
 public void TestTripLifecycleAndReturningDriver(PartnerFleet fleet, Pair<Location, Location> tripSpec)
 {
     PartnerTrip trip = fleet.GenerateTrip(fleet.passengers[0], DateTime.UtcNow, tripSpec);
     TestTripLifecycle_FromNewToComplete(fleet, trip);
     ValidateReturningDriverRouteIfServiceLocal(fleet, trip);
 }