diff options
Diffstat (limited to 'src/Enmarcha.Backend')
7 files changed, 74 insertions, 5 deletions
diff --git a/src/Enmarcha.Backend/Controllers/ArrivalsController.cs b/src/Enmarcha.Backend/Controllers/ArrivalsController.cs index f922ca9..9216004 100644 --- a/src/Enmarcha.Backend/Controllers/ArrivalsController.cs +++ b/src/Enmarcha.Backend/Controllers/ArrivalsController.cs @@ -219,11 +219,16 @@ public partial class ArrivalsController : ControllerBase { string feedId = id.Split(':', 2)[0]; - if (feedId is "vitrasa" or "tranvias" or "tussa") + if (feedId is "vitrasa" or "tranvias") { return 0; } + if (feedId is "tussa" or "ourense" or "lugo") + { + return -5; + } + return -30; } diff --git a/src/Enmarcha.Backend/Controllers/TileController.cs b/src/Enmarcha.Backend/Controllers/TileController.cs index 63e8a9a..5ef8dd6 100644 --- a/src/Enmarcha.Backend/Controllers/TileController.cs +++ b/src/Enmarcha.Backend/Controllers/TileController.cs @@ -164,6 +164,7 @@ public class TileController : ControllerBase "tussa" => "stop-tussa", "tranvias" => "stop-tranvias", "ourense" => "stop-ourense", + "lugo" => "stop-lugo", "xunta" => "stop-xunta", "renfe" => "stop-renfe", "feve" => "stop-feve", diff --git a/src/Enmarcha.Backend/Controllers/TransitController.cs b/src/Enmarcha.Backend/Controllers/TransitController.cs index 9b13972..bda7152 100644 --- a/src/Enmarcha.Backend/Controllers/TransitController.cs +++ b/src/Enmarcha.Backend/Controllers/TransitController.cs @@ -42,7 +42,7 @@ public class TransitController : ControllerBase using var activity = Telemetry.Source.StartActivity("GetRoutes"); if (feeds.Length == 0) { - feeds = ["tussa", "vitrasa", "tranvias", "ourense", "feve", "shuttle"]; + feeds = ["tussa", "vitrasa", "tranvias", "ourense", "lugo", "feve", "shuttle"]; } activity?.SetTag("feeds", string.Join(",", feeds)); diff --git a/src/Enmarcha.Backend/Helpers/SortingHelper.cs b/src/Enmarcha.Backend/Helpers/SortingHelper.cs index fe39521..7fd4e37 100644 --- a/src/Enmarcha.Backend/Helpers/SortingHelper.cs +++ b/src/Enmarcha.Backend/Helpers/SortingHelper.cs @@ -49,12 +49,13 @@ public class SortingHelper var feed = routeId?.Split(':')[0]; - if (feed is "vitrasa" or "tussa") + if (feed is "vitrasa" or "tussa" or "lugo") { int group = feed switch { "vitrasa" => GetVitrasaRouteGroup(shortName), "tussa" => GetTussaRouteGroup(shortName), + "lugo" => GetLugoRouteGroup(shortName), _ => throw new ArgumentOutOfRangeException() }; @@ -90,27 +91,39 @@ public class SortingHelper { // Circular: "C" followed by a digit if (shortName.Length > 1 && shortName[0] == 'C' && char.IsDigit(shortName[1])) + { return 0; + } // Hospital: starts with "H" if (shortName[0] == 'H') + { return 2; + } // Night: "N" followed by a digit if (shortName[0] == 'N' && shortName.Length > 1 && char.IsDigit(shortName[1])) + { return 3; + } // PSA shuttle lines if (shortName.StartsWith("PSA", StringComparison.OrdinalIgnoreCase)) + { return 3; + } // University: "U" followed by a digit if (shortName[0] == 'U' && shortName.Length > 1 && char.IsDigit(shortName[1])) + { return 3; + } // Multi-letter codes with no digits (LZD, PTL) if (shortName.Length >= 2 && shortName.All(char.IsLetter)) + { return 3; + } // Everything else is regular (numbered routes like 4A, 6, 10, single letters like A) return 1; @@ -126,6 +139,45 @@ public class SortingHelper return 0; } + private static int GetLugoRouteGroup(string shortName) + { + if (char.IsLetter(shortName[0])) + { + return 50000; + } + + // Sort something like 2,6,1.1,1.2,1.4,3.1,5.1,PAZO1,PAZO2,CDL + // 1.1, 1.2, 1.4, 2, 3.1, 5.1, 6, then PAZO1, PAZO2, then CDL + if (shortName.Contains('.')) + { + var parts = shortName.Split('.', 2); + if (int.TryParse(parts[0], out int main) && int.TryParse(parts[1], out int sub)) + { + return main * 100 + sub; // 1.1 -> 101, 1.2 -> 102, etc. + } + } + + string numericPart = string.Empty; + foreach (char c in shortName) + { + if (char.IsDigit(c)) + { + numericPart += c; + } + else + { + break; + } + } + + if (int.TryParse(numericPart, out int leadingNumber)) + { + return leadingNumber * 100 + 50; // Sort by leading number if present, with a large multiplier to come after pure numbers + } + + return 0; + } + private static int ExtractNumber(string name) { var digits = new string(name.Where(char.IsDigit).ToArray()); diff --git a/src/Enmarcha.Backend/Services/FareService.cs b/src/Enmarcha.Backend/Services/FareService.cs index fda5eb5..294166d 100644 --- a/src/Enmarcha.Backend/Services/FareService.cs +++ b/src/Enmarcha.Backend/Services/FareService.cs @@ -25,6 +25,9 @@ public class FareService private const decimal OurenseCashFare = 0.85M; private const decimal OurenseCardFare = 0.49M; + private const decimal LugoCashFare = 0.64M; + private const decimal LugoCardFare = 0.45M; + public FareService( IOptions<AppConfiguration> config, XuntaFareProvider xuntaFareProvider, @@ -77,6 +80,9 @@ public class FareService case "ourense": total += OurenseCashFare; break; + case "lugo": + total += LugoCashFare; + break; case "xunta": // TODO: Handle potentiall blow-ups if (leg.From is not { ZoneId: not null }) @@ -137,6 +143,12 @@ public class FareService maxUsages = 2; initialFare = OurenseCardFare; break; + case "lugo": + // IDK About card rules, so we set it to zero + maxMinutes = 0; + maxUsages = 0; + initialFare = LugoCardFare; + break; case "xunta": if (leg.From?.ZoneId == null || leg.To?.ZoneId == null) { diff --git a/src/Enmarcha.Backend/Services/FeedService.cs b/src/Enmarcha.Backend/Services/FeedService.cs index 4ea3752..4e0547b 100644 --- a/src/Enmarcha.Backend/Services/FeedService.cs +++ b/src/Enmarcha.Backend/Services/FeedService.cs @@ -30,7 +30,6 @@ public class FeedService { "Riós", "Ríos" }, { "Avda. Beiramar Porto Pesqueiro Berbés", "Berbés" }, { "Conde de Torrecedeira", "Torrecedeira" }, - }; public (string Color, string TextColor) GetFallbackColourForFeed(string feed) @@ -41,6 +40,7 @@ public class FeedService "tussa" => ("#508096", "#FFFFFF"), "tranvias" => ("#E61C29", "#FFFFFF"), "ourense" => ("#ffb319", "#000000"), + "lugo" => ("#FDC609", "#000000"), "xunta" => ("#007BC4", "#FFFFFF"), "renfe" => ("#870164", "#FFFFFF"), "feve" => ("#EE3D32", "#FFFFFF"), diff --git a/src/Enmarcha.Backend/Types/ConsolidatedCirculation.cs b/src/Enmarcha.Backend/Types/ConsolidatedCirculation.cs index 298e2f4..3f5b61a 100644 --- a/src/Enmarcha.Backend/Types/ConsolidatedCirculation.cs +++ b/src/Enmarcha.Backend/Types/ConsolidatedCirculation.cs @@ -45,6 +45,5 @@ public class Epsg25829 public class Shape { - public string ShapeId { get; set; } public List<Epsg25829> Points { get; set; } = []; } |
