From a304c24b32c0327436bbd8c2853e60668e161b42 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Mon, 29 Dec 2025 00:41:52 +0100 Subject: Rename a lot of stuff, add Santiago real time --- .../Services/Processors/NextStopsProcessor.cs | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/Enmarcha.Backend/Services/Processors/NextStopsProcessor.cs (limited to 'src/Enmarcha.Backend/Services/Processors/NextStopsProcessor.cs') diff --git a/src/Enmarcha.Backend/Services/Processors/NextStopsProcessor.cs b/src/Enmarcha.Backend/Services/Processors/NextStopsProcessor.cs new file mode 100644 index 0000000..5d02066 --- /dev/null +++ b/src/Enmarcha.Backend/Services/Processors/NextStopsProcessor.cs @@ -0,0 +1,34 @@ +using Enmarcha.Sources.OpenTripPlannerGql.Queries; + +namespace Enmarcha.Backend.Services.Processors; + +public class NextStopsProcessor : IArrivalsProcessor +{ + private readonly FeedService _feedService; + + public NextStopsProcessor(FeedService feedService) + { + _feedService = feedService; + } + + public Task ProcessAsync(ArrivalsContext context) + { + var feedId = context.StopId.Split(':')[0]; + + foreach (var arrival in context.Arrivals) + { + if (arrival.RawOtpTrip is not ArrivalsAtStopResponse.Arrival otpArrival) continue; + + // Filter stoptimes that are after the current stop's departure + var currentStopDeparture = otpArrival.ScheduledDepartureSeconds; + + arrival.NextStops = otpArrival.Trip.Stoptimes + .Where(s => s.ScheduledDeparture > currentStopDeparture) + .OrderBy(s => s.ScheduledDeparture) + .Select(s => _feedService.NormalizeStopName(feedId, s.Stop.Name)) + .ToList(); + } + + return Task.CompletedTask; + } +} -- cgit v1.3