summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2026-03-15 23:01:32 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2026-03-15 23:01:32 +0100
commit99005bce74288a415ac748414e0f8b522e207c93 (patch)
tree2aacb51f1ebbd58a687b176ed81dc240970db878
parentc0e758b1e793159fc86c85916130f8959360c64e (diff)
feat: enhance arrival processing with shift badge retrieval and deletion flag
-rw-r--r--src/Enmarcha.Backend/Services/ArrivalsPipeline.cs2
-rw-r--r--src/Enmarcha.Backend/Services/FeedService.cs39
-rw-r--r--src/Enmarcha.Backend/Services/Processors/FeedConfigProcessor.cs3
-rw-r--r--src/Enmarcha.Backend/Services/Processors/RenfeRealTimeProcessor.cs5
-rw-r--r--src/Enmarcha.Backend/Types/Arrivals/Arrival.cs6
5 files changed, 50 insertions, 5 deletions
diff --git a/src/Enmarcha.Backend/Services/ArrivalsPipeline.cs b/src/Enmarcha.Backend/Services/ArrivalsPipeline.cs
index 9e44535..4837051 100644
--- a/src/Enmarcha.Backend/Services/ArrivalsPipeline.cs
+++ b/src/Enmarcha.Backend/Services/ArrivalsPipeline.cs
@@ -66,5 +66,7 @@ public class ArrivalsPipeline
using var processorActivity = Telemetry.Source.StartActivity($"Processor:{processor.GetType().Name}");
await processor.ProcessAsync(context);
}
+
+ context.Arrivals = context.Arrivals.Where(a => !a.Delete).ToList();
}
}
diff --git a/src/Enmarcha.Backend/Services/FeedService.cs b/src/Enmarcha.Backend/Services/FeedService.cs
index dc016b4..c3e33fd 100644
--- a/src/Enmarcha.Backend/Services/FeedService.cs
+++ b/src/Enmarcha.Backend/Services/FeedService.cs
@@ -217,10 +217,45 @@ public class FeedService
return HiddenStops.Contains(stopId);
}
- public ShiftBadge? GetShiftBadge(string feedId, string tripId)
+ public static ShiftBadge? GetShiftBadge(string feedId, string tripId)
{
- if (feedId != "vitrasa") return null;
+ return feedId switch
+ {
+ "vitrasa" => GetVitrasaShiftBadge(tripId.Split(':', 2)[1]),
+ "tranvias" => GetTranviasShiftBadge(tripId.Split(':', 2)[1]),
+ _ => null
+ };
+ }
+
+ private static ShiftBadge? GetTranviasShiftBadge(string tripId)
+ {
+ // Example: 200032223 || 2301032230
+ var padded = tripId.PadLeft(10);
+
+ Console.WriteLine(padded[4..6]);
+
+ var dayOfWeek = padded[4..6] switch
+ {
+ "01" => "Lab",
+ "02" => "Sab",
+ "03" => "Dom",
+ "04" => "Fes",
+ "05" or "06" or "07" => "NoLec",
+ "08" => "Ex.UDC",
+ "09" => "Desc",
+ "10" => "Navid",
+ _ => ""
+ };
+
+ return new ShiftBadge
+ {
+ ShiftName = padded[..4].Trim(),
+ ShiftTrip = $"{dayOfWeek} {padded[6..]}",
+ };
+ }
+ private static ShiftBadge? GetVitrasaShiftBadge(string tripId)
+ {
// Example: C1 04LN 02_001004_4
var parts = tripId.Split('_');
if (parts.Length < 2) return null;
diff --git a/src/Enmarcha.Backend/Services/Processors/FeedConfigProcessor.cs b/src/Enmarcha.Backend/Services/Processors/FeedConfigProcessor.cs
index 7e5a745..196091a 100644
--- a/src/Enmarcha.Backend/Services/Processors/FeedConfigProcessor.cs
+++ b/src/Enmarcha.Backend/Services/Processors/FeedConfigProcessor.cs
@@ -26,9 +26,10 @@ public class FeedConfigProcessor : IArrivalsProcessor
if (feedId == "vitrasa")
{
FormatVitrasaLine(arrival);
- arrival.Shift = _feedService.GetShiftBadge(feedId, arrival.TripId);
}
+ arrival.Shift = FeedService.GetShiftBadge(feedId, arrival.TripId);
+
if (string.IsNullOrEmpty(arrival.Route.Colour) || arrival.Route.Colour == "FFFFFF")
{
arrival.Route.Colour = fallbackColor;
diff --git a/src/Enmarcha.Backend/Services/Processors/RenfeRealTimeProcessor.cs b/src/Enmarcha.Backend/Services/Processors/RenfeRealTimeProcessor.cs
index dcddd5d..750cb2d 100644
--- a/src/Enmarcha.Backend/Services/Processors/RenfeRealTimeProcessor.cs
+++ b/src/Enmarcha.Backend/Services/Processors/RenfeRealTimeProcessor.cs
@@ -51,6 +51,11 @@ public class RenfeRealTimeProcessor : AbstractRealTimeProcessor
contextArrival.Estimate.Minutes += delayMinutes;
contextArrival.Estimate.Precision = ArrivalPrecision.Confident;
+
+ if (contextArrival.Estimate.Minutes < 0)
+ {
+ contextArrival.Delete = true;
+ }
}
if (positions.TryGetValue(trainNumber, out var position))
diff --git a/src/Enmarcha.Backend/Types/Arrivals/Arrival.cs b/src/Enmarcha.Backend/Types/Arrivals/Arrival.cs
index 9789d43..a07c988 100644
--- a/src/Enmarcha.Backend/Types/Arrivals/Arrival.cs
+++ b/src/Enmarcha.Backend/Types/Arrivals/Arrival.cs
@@ -26,11 +26,13 @@ public class Arrival
[JsonPropertyName("patternId")] public string? PatternId { get; set; }
- [System.Text.Json.Serialization.JsonIgnore]
+ [JsonIgnore]
public List<string> NextStops { get; set; } = [];
- [System.Text.Json.Serialization.JsonIgnore]
+ [JsonIgnore]
public object? RawOtpTrip { get; set; }
+
+ [JsonIgnore] public bool Delete { get; set; }
}
public class RouteInfo