From 3573ecae94aa328591d4b3a6e2d05e4fc9e261fc Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sat, 28 Feb 2026 23:32:50 +0100 Subject: Deduplicate and collapse routes with excessive short-name variants on stop arrivals (#137) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: arielcostas <94913521+arielcostas@users.noreply.github.com> --- .../Controllers/ArrivalsController.cs | 69 ++++++++++++++-------- 1 file changed, 43 insertions(+), 26 deletions(-) (limited to 'src/Enmarcha.Backend/Controllers') diff --git a/src/Enmarcha.Backend/Controllers/ArrivalsController.cs b/src/Enmarcha.Backend/Controllers/ArrivalsController.cs index a887c89..50d4012 100644 --- a/src/Enmarcha.Backend/Controllers/ArrivalsController.cs +++ b/src/Enmarcha.Backend/Controllers/ArrivalsController.cs @@ -158,17 +158,18 @@ public partial class ArrivalsController : ControllerBase Latitude = stop.Lat, Longitude = stop.Lon }, - Routes = [.. stop.Routes - .OrderBy(r => SortingHelper.GetRouteSortKey(r.ShortName, r.GtfsId)) - .Select(r => new RouteInfo - { - GtfsId = r.GtfsId, - ShortName = _feedService.NormalizeRouteShortName(feedId, r.ShortName ?? ""), - Colour = r.Color ?? fallbackColor, - TextColour = r.TextColor is null or "000000" ? - ContrastHelper.GetBestTextColour(r.Color ?? fallbackColor) : - r.TextColor - })], + Routes = [.. _feedService.ConsolidateRoutes(feedId, + stop.Routes + .OrderBy(r => SortingHelper.GetRouteSortKey(r.ShortName, r.GtfsId)) + .Select(r => new RouteInfo + { + GtfsId = r.GtfsId, + ShortName = _feedService.NormalizeRouteShortName(feedId, r.ShortName ?? ""), + Colour = r.Color ?? fallbackColor, + TextColour = r.TextColor is null or "000000" ? + ContrastHelper.GetBestTextColour(r.Color ?? fallbackColor) : + r.TextColor + }))], Arrivals = [.. arrivals.Where(a => a.Estimate.Minutes >= timeThreshold)], Usage = context.Usage }); @@ -224,15 +225,23 @@ public partial class ArrivalsController : ControllerBase id = s.GtfsId, code = _feedService.NormalizeStopCode(feedId, s.Code ?? ""), name = s.Name, - routes = s.Routes - .OrderBy(r => r.ShortName, Comparer.Create(SortingHelper.SortRouteShortNames)) + routes = _feedService.ConsolidateRoutes(feedId, + s.Routes + .OrderBy(r => r.ShortName, Comparer.Create(SortingHelper.SortRouteShortNames)) + .Select(r => new RouteInfo + { + GtfsId = r.GtfsId, + ShortName = _feedService.NormalizeRouteShortName(feedId, r.ShortName ?? ""), + Colour = r.Color ?? fallbackColor, + TextColour = r.TextColor is null or "000000" ? + ContrastHelper.GetBestTextColour(r.Color ?? fallbackColor) : + r.TextColor + })) .Select(r => new { - shortName = _feedService.NormalizeRouteShortName(feedId, r.ShortName ?? ""), - colour = r.Color ?? fallbackColor, - textColour = r.TextColor is null or "000000" ? - ContrastHelper.GetBestTextColour(r.Color ?? fallbackColor) : - r.TextColor + shortName = r.ShortName, + colour = r.Colour, + textColour = r.TextColour }) .ToList() }; @@ -269,17 +278,25 @@ public partial class ArrivalsController : ControllerBase name = name, latitude = s.Lat, longitude = s.Lon, - lines = s.Routes? - .OrderBy(r => r.ShortName, Comparer.Create(SortingHelper.SortRouteShortNames)) + lines = _feedService.ConsolidateRoutes(feedId, + (s.Routes ?? []) + .OrderBy(r => r.ShortName, Comparer.Create(SortingHelper.SortRouteShortNames)) + .Select(r => new RouteInfo + { + GtfsId = r.GtfsId, + ShortName = _feedService.NormalizeRouteShortName(feedId, r.ShortName ?? ""), + Colour = r.Color ?? fallbackColor, + TextColour = r.TextColor is null or "000000" ? + ContrastHelper.GetBestTextColour(r.Color ?? fallbackColor) : + r.TextColor + })) .Select(r => new { - line = _feedService.NormalizeRouteShortName(feedId, r.ShortName ?? ""), - colour = r.Color ?? fallbackColor, - textColour = r.TextColor is null or "000000" ? - ContrastHelper.GetBestTextColour(r.Color ?? fallbackColor) : - r.TextColor + line = r.ShortName, + colour = r.Colour, + textColour = r.TextColour }) - .ToList() ?? [], + .ToList(), label = string.IsNullOrWhiteSpace(code) ? name : $"{name} ({code})" }; }).ToList(); -- cgit v1.3