aboutsummaryrefslogtreecommitdiff
path: root/src/Enmarcha.Backend/Services
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2026-04-20 16:23:00 +0200
committerAriel Costas Guerrero <ariel@costas.dev>2026-04-20 16:23:00 +0200
commit32574981f659a6c59faf968c8dbfe6eda3c632d6 (patch)
tree455f7c2de0253c933309d3dc4757411857e389a4 /src/Enmarcha.Backend/Services
parent594b106010c0a5f9de38f6f0f3bda9b5f92f6699 (diff)
Mostrar procedencia en rutas interurbanascopilot/update-coruna-realtime-processor
Closes #154
Diffstat (limited to 'src/Enmarcha.Backend/Services')
-rw-r--r--src/Enmarcha.Backend/Services/Processors/NextStopsProcessor.cs51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/Enmarcha.Backend/Services/Processors/NextStopsProcessor.cs b/src/Enmarcha.Backend/Services/Processors/NextStopsProcessor.cs
index 4c0b8ac..0f86be5 100644
--- a/src/Enmarcha.Backend/Services/Processors/NextStopsProcessor.cs
+++ b/src/Enmarcha.Backend/Services/Processors/NextStopsProcessor.cs
@@ -43,7 +43,31 @@ public class NextStopsProcessor : IArrivalsProcessor
.ToList();
}
+ // Remove last stop since it doesn't make sense to show "via" for the terminus
+ arrival.NextStops = arrival.NextStops.Take(arrival.NextStops.Count - 1).ToList();
+
+ if (feedId == "xunta")
+ {
+ arrival.OriginStops = otpArrival.Trip.Stoptimes
+ .Where(s => s.ScheduledDeparture < currentStopDeparture)
+ .OrderBy(s => s.ScheduledDeparture)
+ .Take(1)
+ .Select(s => $"{s.Stop.Name} -- {s.Stop.Description}")
+ .Distinct()
+ .ToList();
+ }
+ else if (feedId == "renfe")
+ {
+ arrival.OriginStops = otpArrival.Trip.Stoptimes
+ .Where(s => s.ScheduledDeparture < currentStopDeparture)
+ .OrderBy(s => s.ScheduledDeparture)
+ .Take(1)
+ .Select(s => FeedService.NormalizeStopName(feedId, s.Stop.Name))
+ .ToList();
+ }
+
arrival.Headsign.Marquee = GenerateMarquee(feedId, arrival.NextStops);
+ arrival.Headsign.Origin = GenerateOrigin(feedId, arrival.OriginStops);
}
return Task.CompletedTask;
@@ -122,6 +146,33 @@ public class NextStopsProcessor : IArrivalsProcessor
};
}
+ private static string? GenerateOrigin(string feedId, List<string> originStops)
+ {
+ if (originStops.Count == 0) return null;
+
+ if (feedId == "xunta")
+ {
+ var points = originStops.Select(SplitXuntaStopDescription).ToList();
+ var concellos = points
+ .Select(p => p.concello)
+ .Where(c => !string.IsNullOrWhiteSpace(c))
+ .Distinct(StringComparer.OrdinalIgnoreCase)
+ .ToList();
+
+ return concellos.Count > 0 ? string.Join(" > ", concellos) : null;
+ }
+
+ if (feedId == "renfe")
+ {
+ // For trains just show the origin terminus
+ return originStops.First();
+ }
+
+ // For local bus feeds, origin is generally not very informative,
+ // but return the first stop for completeness
+ return originStops.First();
+ }
+
private static (string nombre, string parroquia, string concello) SplitXuntaStopDescription(string stopName)
{
var parts = stopName.Split(" -- ", 3);