diff --git a/Services/TransportApiService.cs b/Services/TransportApiService.cs index c06e959..83ae225 100644 --- a/Services/TransportApiService.cs +++ b/Services/TransportApiService.cs @@ -25,12 +25,8 @@ 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}"); - } + var allConnections = apiResponse.Connections.Select(MapToTransportConnection).ToList(); + allConnections.ForEach(tc => logger.LogDebug($"Found connection {tc}")); var bestConnection = TransportConnectionCalculator.FindBestConnection( allConnections, new ConnectionPickArgument(shiftStartTime, config.SafetyBufferMinutes, config.MaxEarlyArrivalMinutes, config.MaxLateArrivalMinutes), logger); diff --git a/Services/TransportConnectionCalculator.cs b/Services/TransportConnectionCalculator.cs index 500b875..738eba8 100644 --- a/Services/TransportConnectionCalculator.cs +++ b/Services/TransportConnectionCalculator.cs @@ -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(); var lateValidConnections = new List(); @@ -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(); } } \ No newline at end of file