* Initial plan * Initial project setup - update to .NET 8.0 for compatibility Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com> * Complete SBB transport integration implementation Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com> * Revert to .NET 9 and separate transport info into ShiftTransport class Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com> * Make safety buffer minutes configurable via appsettings Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com> * Migrade pdf export service * Update gitignore * Implement new approach: real-time transport data per shift selection with ShiftWithTransport view model Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com> * Refactor export methods to directly use ShiftWithTransport instead of converting to separate parameters Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com> * Move ShiftWithTransport class to its own file Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com> * Code cleanup * Fix transport timing logic to respect safety buffer and find best available connections Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: clayschaad <11883505+clayschaad@users.noreply.github.com> Co-authored-by: clayschaad <c.schaad@pog.ch> Co-authored-by: Claudio Schaad <clayschaad@users.noreply.github.com>
77 lines
No EOL
2.7 KiB
C#
77 lines
No EOL
2.7 KiB
C#
using ShiftScheduler.Shared.Models;
|
|
|
|
namespace ShiftScheduler.Services
|
|
{
|
|
public class ShiftEnrichmentService
|
|
{
|
|
private readonly TransportService _transportService;
|
|
|
|
public ShiftEnrichmentService(TransportService transportService)
|
|
{
|
|
_transportService = transportService;
|
|
}
|
|
|
|
public async Task<List<ShiftTransport>> EnrichShiftsWithTransportAsync(List<Shift> shifts, Dictionary<DateTime, string> schedule)
|
|
{
|
|
var shiftTransports = new List<ShiftTransport>();
|
|
|
|
foreach (var shift in shifts)
|
|
{
|
|
var shiftTransport = new ShiftTransport
|
|
{
|
|
ShiftName = shift.Name
|
|
};
|
|
|
|
// Find dates where this shift is scheduled
|
|
var scheduledDates = schedule.Where(kvp => kvp.Value == shift.Name).Select(kvp => kvp.Key).ToList();
|
|
|
|
if (scheduledDates.Count > 0)
|
|
{
|
|
// Use the first scheduled date to calculate transport times
|
|
var sampleDate = scheduledDates.First();
|
|
|
|
// Get transport for morning shift
|
|
if (!string.IsNullOrEmpty(shift.MorningTime))
|
|
{
|
|
var morningStartTime = ParseShiftTime(sampleDate, shift.MorningTime);
|
|
if (morningStartTime.HasValue)
|
|
{
|
|
shiftTransport.MorningTransport = await _transportService.GetConnectionAsync(morningStartTime.Value);
|
|
}
|
|
}
|
|
|
|
// Get transport for afternoon shift
|
|
if (!string.IsNullOrEmpty(shift.AfternoonTime))
|
|
{
|
|
var afternoonStartTime = ParseShiftTime(sampleDate, shift.AfternoonTime);
|
|
if (afternoonStartTime.HasValue)
|
|
{
|
|
shiftTransport.AfternoonTransport = await _transportService.GetConnectionAsync(afternoonStartTime.Value);
|
|
}
|
|
}
|
|
}
|
|
|
|
shiftTransports.Add(shiftTransport);
|
|
}
|
|
|
|
return shiftTransports;
|
|
}
|
|
|
|
private DateTime? ParseShiftTime(DateTime date, string timeRange)
|
|
{
|
|
try
|
|
{
|
|
var times = timeRange.Split('-');
|
|
if (times.Length > 0 && TimeSpan.TryParse(times[0], out var startTime))
|
|
{
|
|
return date.Add(startTime);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// Ignore parsing errors
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
} |