Fix finding best connection (#49)
* Log and fix connection * Update Services/TransportConnectionCalculator.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Services/TransportConnectionCalculator.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Services/TransportConnectionCalculator.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * better logging --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
5103aecacf
commit
28429d78d0
2 changed files with 14 additions and 18 deletions
|
|
@ -26,11 +26,7 @@ namespace ShiftScheduler.Services
|
|||
if (apiResponse?.Connections.Count > 0)
|
||||
{
|
||||
var allConnections = apiResponse.Connections.Select(MapToTransportConnection).ToList();
|
||||
|
||||
foreach (var connection in allConnections)
|
||||
{
|
||||
logger.LogDebug($"Found connection {connection}");
|
||||
}
|
||||
allConnections.ForEach(tc => logger.LogDebug($"Found connection {tc}"));
|
||||
|
||||
var bestConnection = TransportConnectionCalculator.FindBestConnection(
|
||||
allConnections, new ConnectionPickArgument(shiftStartTime, config.SafetyBufferMinutes, config.MaxEarlyArrivalMinutes, config.MaxLateArrivalMinutes), logger);
|
||||
|
|
|
|||
|
|
@ -7,13 +7,7 @@ public record ConnectionPickArgument(
|
|||
DateTimeOffset ShiftStartTime,
|
||||
int SafetyBufferMinutes,
|
||||
int MaxEarlyArrivalMinutes,
|
||||
int MaxLateArrivalMinutes)
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
return $"ShiftStartTime: {ShiftStartTime}, SafetyBufferMinutes: {SafetyBufferMinutes}, MaxEarlyArrivalMinutes{MaxEarlyArrivalMinutes}, MaxLateArrivalMinutes:{MaxLateArrivalMinutes}";
|
||||
}
|
||||
}
|
||||
int MaxLateArrivalMinutes);
|
||||
|
||||
public static class TransportConnectionCalculator
|
||||
{
|
||||
|
|
@ -24,10 +18,13 @@ public static class TransportConnectionCalculator
|
|||
var earliestAcceptableTime = args.ShiftStartTime.AddMinutes(-args.MaxEarlyArrivalMinutes);
|
||||
var latestAcceptableTime = args.ShiftStartTime.AddMinutes(args.MaxLateArrivalMinutes);
|
||||
|
||||
logger.LogDebug(args.ToString());
|
||||
logger.LogDebug($"latestArrivalTime: {latestArrivalTime}");
|
||||
logger.LogDebug($"earliestAcceptableTime: {earliestAcceptableTime}");
|
||||
logger.LogDebug($"latestAcceptableTime: {latestAcceptableTime}");
|
||||
logger.LogDebug("ShiftStartTime: {ShiftStartTime}", args.ShiftStartTime);
|
||||
logger.LogDebug("SafetyBufferMinutes: {SafetyBufferMinutes}", args.SafetyBufferMinutes);
|
||||
logger.LogDebug("MaxEarlyArrivalMinutes: {MaxEarlyArrivalMinutes}", args.MaxEarlyArrivalMinutes);
|
||||
logger.LogDebug("MaxLateArrivalMinutes: {MaxLateArrivalMinutes}", args.MaxLateArrivalMinutes);
|
||||
logger.LogDebug("latestArrivalTime: {LatestArrivalTime}", latestArrivalTime);
|
||||
logger.LogDebug("earliestAcceptableTime: {EarliestAcceptableTime}", earliestAcceptableTime);
|
||||
logger.LogDebug("latestAcceptableTime: {LatestAcceptableTime}", latestAcceptableTime);
|
||||
|
||||
var validConnections = new List<TransportConnection>();
|
||||
var lateValidConnections = new List<TransportConnection>();
|
||||
|
|
@ -50,6 +47,7 @@ public static class TransportConnectionCalculator
|
|||
var bestValidConnection = validConnections.Last();
|
||||
if (bestValidConnection.ArrivalTime > earliestAcceptableTime)
|
||||
{
|
||||
logger.LogDebug("Found bestValidConnection {BestValidConnection}", bestValidConnection);
|
||||
return bestValidConnection;
|
||||
}
|
||||
}
|
||||
|
|
@ -57,9 +55,11 @@ public static class TransportConnectionCalculator
|
|||
// If no connections arrive before latest arrival time, check if any arrive within acceptable late range
|
||||
if (lateValidConnections.Count > 0)
|
||||
{
|
||||
logger.LogDebug("Found lateValidConnection {LateValidConnection}", lateValidConnections.First());
|
||||
return lateValidConnections.First();
|
||||
}
|
||||
|
||||
return validConnections.FirstOrDefault();
|
||||
logger.LogDebug("Use last valid connection {LastValidConnection}", validConnections.LastOrDefault());
|
||||
return validConnections.LastOrDefault();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue