blob: 5bdb5bb969c7c4460fe718147d732837eb2aed17 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
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)
{
if (context.IsNano) return Task.CompletedTask;
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;
}
}
|