public void Setup() { hazmatDriver = new Driver { AvailableDrivingHours = 10, AvailableDutyHours = 14, DisplayName = "Hazmat Driver", EarliestStartTime = new TimeSpan(0, 0, 0).Ticks, Id = 1, IsFlatbed = false, IsHazmat = true, StartingLocation = new Domain.Geography.Location() }; nonHazmatDriver = new Driver { AvailableDrivingHours = 10, AvailableDutyHours = 14, DisplayName = "Hazmat Driver", EarliestStartTime = new TimeSpan(0, 0, 0).Ticks, Id = 1, IsFlatbed = false, IsHazmat = false, StartingLocation = new Domain.Geography.Location() }; job = new Job(); job.IsHazmat = true; }
public void SetShift(Job jobWithRoutes, IList <JobGroup> jobGroups) { if (jobWithRoutes == null || jobGroups == null || !jobGroups.Any() || jobWithRoutes.RouteStops == null) { return; } var stops = jobWithRoutes.RouteStops.OrderBy(p => p.SortOrder).ThenBy(p => p.Id).ToList(); if (stops.Count > 2) { var stop = stops[stops.Count - 2]; var ts = new TimeSpan(stop.WindowEnd); while (ts.TotalDays > 1.000) { ts = ts.Subtract(TimeSpan.FromDays(1)); } JobGroup jg = null; jg = ts >= CompareMax || ts <= CompareMin ? jobGroups[1] : jobGroups[0]; if (jobWithRoutes.JobGroup == null || jobWithRoutes.JobGroup.Id != jg.Id) { jobWithRoutes.JobGroup = jg; jobWithRoutes.JobGroupId = jg.Id; } } }
public void Can_add_sample_job_orders() { var subscriber = _subscriberService.Select().FirstOrDefault(); var location = _locationService.Select().FirstOrDefault(p => p.SubscriberId == subscriber.Id); var sa = _stopActionService.GetByShortName("NA"); var job = new Job() { Subscriber = subscriber, OrderNumber = "TESTORDER", BillOfLading = "BILLOFLADING", BookingNumber = "BOOKING", }; _jobService.Insert(job); var routeStops = new List <RouteStop>() { new RouteStop() { Job = job, Subscriber = subscriber, SortOrder = 0, Location = location, StopAction = sa, }, new RouteStop() { Job = job, Subscriber = subscriber, SortOrder = 1, Location = location, StopAction = sa, }, }; _routeStopService.Insert(routeStops[0], false); _routeStopService.Insert(routeStops[1], false); _routeStopService.SaveChanges(); }
private List <int> GetLiveIndexes(Job job) { var result = new List <int>(); if (job != null && job.RouteStops != null) { for (int i = 0; i < job.RouteStops.Count; i++) { var rs = job.RouteStops[i]; if (rs.StopAction != null && (rs.StopAction.ShortName == "LU" || rs.StopAction.ShortName == "LL")) { result.Add(i); } } } return(result); }
private Job FixJob(Job j, IList <JobGroup> jobGroups) { for (int r = 0; r < j.RouteStops.Count; r++) { // set ordering j.RouteStops[r].SortOrder = r + 1; // set live duration var liveIndexes = GetLiveIndexes(j); if (liveIndexes.Count > 1) { for (int l = 0; l < liveIndexes.Count; l++) { j.RouteStops[liveIndexes[l]].StopDelay = 0; if (l + 1 == liveIndexes.Count) { j.RouteStops[liveIndexes[l]].StopDelay = 90; } } } // make C/O FEC Miami Ramp stops invalid if (!j.RouteStops.Any(x => invalidStreetAddresses.Contains(x.Location.Street.ToLower()))) { continue; } foreach (var routeStop in j.RouteStops) { routeStop.StopAction = new StopAction { Id = StopActions.NoAction.Id, Name = StopActions.NoAction.Name, ShortName = StopActions.NoAction.ShortName }; } j.IsValid = false; j.IsValidNullable = false; } SetShift(j, jobGroups); return(j); }
/// <summary> /// Validates Job based on RouteStops /// </summary> /// <param name="job"></param> /// <returns></returns> public ValidationResult ValidateJob(PAI.FRATIS.SFL.Domain.Orders.Job job, bool validateLocations, IDistanceService distanceService) { var optimizationJob = new Drayage.Optimization.Model.Orders.Job(); try { job.RouteStops = job.RouteStops.OrderBy(p => p.SortOrder).ToList(); _mapDomainService.MapDomainToModel(job, optimizationJob, null); } catch (Exception ex) { return(new ValidationResult() { Successful = false, Errors = new List <string>() { "Invalid Route Stop" } }); } var result = _validationService.ValidateJob(optimizationJob, validateLocations, distanceService); try { return(new ValidationResult() { Successful = result.Successful, Errors = result.Errors }); } catch (Exception ex) { throw new Exception("Could not map ValidationResult using Automapper - verify AutoMapper profile loaded and configured correctly", ex); } }
public IList <Job> GetJobs(Dictionary <string, Location> locationsByCustomerNumber, IList <StopAction> stopActions, int subscriberId) { var jobGroups = _jobGroupService.GetGroups(subscriberId).Where(p => p.Name != "Unspecified").ToList(); var result = new List <Job>(); foreach (var kvp in Dictionary) { if (!kvp.Value.FilteredLegs.Any()) { continue; } var job = new Job() { SubscriberId = subscriberId, ContainerNumber = kvp.Value.FilteredLegs.First().Trailer, ShipperName = kvp.Value.FilteredLegs.First().ShipperName, ConsigneeName = kvp.Value.FilteredLegs.First().ConsigneeName, LegacyId = kvp.Key, OrderNumber = kvp.Value.FilteredLegs.First().ManifestNumber, BillOfLading = kvp.Value.FilteredLegs.First().BillOfLadingNumber, DueDate = null, RouteStops = new List <RouteStop>(), IsValid = true, IsHazmat = kvp.Value.FilteredLegs.First().IsHazmat, IsFlatbed = kvp.Value.IsFlatbed, }; var filteredLegsWithoutRails = kvp.Value.FilteredLegsWithoutRails; DateTime?dueDateLocal = null; switch (kvp.Value.JobType) { case ManifestJobType.CustomerToRamp: #region Customer To Ramp Logic job.RouteStops.Add( CreateRouteStop(stopActions.GetStopAction("PEWC"), "0", locationsByCustomerNumber, FecDefaultStopDelay, subscriberId)); for (int i = 0; i < filteredLegsWithoutRails.Count; i++) { var leg = filteredLegsWithoutRails[i]; if (!job.DueDate.HasValue) { dueDateLocal = leg.ScheduledDateTime.Date; job.DueDate = this.DateTimeHelper.ConvertLocalToUtcTime(dueDateLocal.Value); } // CBS 190914 - Removing 30 minute padding var tsStart = leg.ScheduledDateTime; //.AddMinutes(-30); var appointmentTimeTicks = dueDateLocal.HasValue ? tsStart.Subtract(dueDateLocal.Value).Ticks : 0; var windowStart = appointmentTimeTicks; var windowEnd = appointmentTimeTicks; job.RouteStops.Add(GetRouteStopFromLeg(subscriberId, leg, stopActions.GetStopAction("LL"), locationsByCustomerNumber, new TimeSpan(windowStart), new TimeSpan(windowEnd), 60)); } var finalStop = kvp.Value.GetMiamiRailLegAfterCustomers(); if (finalStop != null) { var windowEnd = new TimeSpan(finalStop.ScheduledDateTime.Hour, finalStop.ScheduledDateTime.Minute, 0); job.RouteStops.Add(GetRouteStopFromLeg(subscriberId, finalStop, stopActions.GetStopAction("DLWC"), locationsByCustomerNumber, new TimeSpan(0, 0, 0), windowEnd, FecDefaultStopDelay)); } else { job.RouteStops.Add( CreateRouteStop(stopActions.GetStopAction("DLWC"), "0", locationsByCustomerNumber, FecDefaultStopDelay, subscriberId, new TimeSpan(job.RouteStops.Last().WindowStart), new TimeSpan(job.RouteStops.Last().WindowStart + new TimeSpan(23, 59, 0).Ticks))); } #endregion break; case ManifestJobType.RampToCustomer: #region Ramp to Customer Logic var firstStop = kvp.Value.GetMiamiRailLegBeforeCustomers(); if (firstStop != null) { var windowStart = new TimeSpan(firstStop.ScheduledDateTime.Hour, firstStop.ScheduledDateTime.Minute, 0); job.RouteStops.Add(GetRouteStopFromLeg(subscriberId, firstStop, stopActions.GetStopAction("PLWC"), locationsByCustomerNumber, windowStart, new TimeSpan(23, 59, 0), FecDefaultStopDelay)); } else { job.RouteStops.Add( CreateRouteStop(stopActions.GetStopAction("PLWC"), "0", locationsByCustomerNumber, FecDefaultStopDelay, subscriberId)); } for (int i = 0; i < filteredLegsWithoutRails.Count; i++) { var leg = filteredLegsWithoutRails[i]; if (!job.DueDate.HasValue) { dueDateLocal = leg.ScheduledDateTime.Date; job.DueDate = this.DateTimeHelper.ConvertLocalToUtcTime(dueDateLocal.Value); } // CBS 190914 - Removing 30 minute padding var tsStart = leg.ScheduledDateTime; //.AddMinutes(-30); var appointmentTimeTicks = dueDateLocal.HasValue ? tsStart.Subtract(dueDateLocal.Value).Ticks : 0; var sa = stopActions.GetStopAction("LU"); job.RouteStops.Add(GetRouteStopFromLeg(subscriberId, leg, sa, locationsByCustomerNumber, new TimeSpan(appointmentTimeTicks), new TimeSpan(appointmentTimeTicks), 120)); } if (job.RouteStops.Last().StopAction.ShortName == "DL") { job.RouteStops.Add( CreateRouteStop(stopActions.GetStopAction("DC"), "0", locationsByCustomerNumber, FecDefaultStopDelay, subscriberId, new TimeSpan(job.RouteStops.Last().WindowStart), new TimeSpan(job.RouteStops.Last().WindowStart + new TimeSpan(23, 59, 0).Ticks))); } else { job.RouteStops.Add( CreateRouteStop(stopActions.GetStopAction("DEWC"), "0", locationsByCustomerNumber, FecDefaultStopDelay, subscriberId, new TimeSpan(job.RouteStops.Last().WindowStart), new TimeSpan(job.RouteStops.Last().WindowStart + new TimeSpan(23, 59, 0).Ticks))); } #endregion break; case ManifestJobType.IncompleteOrderType1: case ManifestJobType.IncompleteOrderType2: #region Incomplete Order // add all customers, no actions job.IsValid = false; for (int i = 0; i < filteredLegsWithoutRails.Count; i++) { var leg = filteredLegsWithoutRails[i]; if (!job.DueDate.HasValue) { dueDateLocal = leg.ScheduledDateTime.Date; job.DueDate = this.DateTimeHelper.ConvertLocalToUtcTime(dueDateLocal.Value); } // CBS 190914 - Removing 30 minute padding var tsStart = leg.ScheduledDateTime; //.AddMinutes(-30); var appointmentTimeTicks = dueDateLocal.HasValue ? tsStart.Subtract(dueDateLocal.Value).Ticks : 0; job.RouteStops.Add(GetRouteStopFromLeg(subscriberId, leg, stopActions.GetStopAction("NA"), locationsByCustomerNumber, new TimeSpan(appointmentTimeTicks), new TimeSpan(appointmentTimeTicks), 120)); } #endregion break; default: continue; // invalid j } if (job.RouteStops.Any(f => f.Location.DisplayName.ToLower().Contains("gibson"))) { job.IsFlatbed = true; } // fix intermediate routestop durations, and set JobGroup/shift Console.WriteLine(job.OrderNumber); job = FixJob(job, jobGroups); result.Add(job); } return(result); }