From 6e2d9ffe812eb1ca8fe5d04d3df2aa322e9e5760 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Thu, 5 Mar 2026 01:54:35 +0100 Subject: Refactor deployment process to use rsync for frontend and backend, update project paths, and add CtagShuttleRealtimeEstimatesProvider and CtagShuttleStatus classes --- src/Enmarcha.Backend/Enmarcha.Backend.csproj | 2 +- .../Processors/CtagShuttleRealTimeProcessor.cs | 2 +- .../Services/Processors/VigoUsageProcessor.cs | 1 - .../CtagShuttleRealtimeEstimatesProvider.cs | 30 ++++++++++++++ .../Enmarcha.Sources.CtagShuttle.csproj | 9 +++++ src/Enmarcha.Sources.CtagShuttle/Status.cs | 46 ++++++++++++++++++++++ src/frontend/app/i18n/locales/en-GB.json | 2 +- src/frontend/app/i18n/locales/es-ES.json | 2 +- src/frontend/app/i18n/locales/gl-ES.json | 2 +- 9 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 src/Enmarcha.Sources.CtagShuttle/CtagShuttleRealtimeEstimatesProvider.cs create mode 100644 src/Enmarcha.Sources.CtagShuttle/Enmarcha.Sources.CtagShuttle.csproj create mode 100644 src/Enmarcha.Sources.CtagShuttle/Status.cs (limited to 'src') diff --git a/src/Enmarcha.Backend/Enmarcha.Backend.csproj b/src/Enmarcha.Backend/Enmarcha.Backend.csproj index a353b4d..3ce20ad 100644 --- a/src/Enmarcha.Backend/Enmarcha.Backend.csproj +++ b/src/Enmarcha.Backend/Enmarcha.Backend.csproj @@ -29,7 +29,7 @@ - + diff --git a/src/Enmarcha.Backend/Services/Processors/CtagShuttleRealTimeProcessor.cs b/src/Enmarcha.Backend/Services/Processors/CtagShuttleRealTimeProcessor.cs index 593ac86..316591d 100644 --- a/src/Enmarcha.Backend/Services/Processors/CtagShuttleRealTimeProcessor.cs +++ b/src/Enmarcha.Backend/Services/Processors/CtagShuttleRealTimeProcessor.cs @@ -175,7 +175,7 @@ public class CtagShuttleRealTimeProcessor : AbstractRealTimeProcessor .Where(a => a.Estimate.Minutes >= 0) .OrderBy(a => a.Estimate.Minutes) .FirstOrDefault(); - + _logger.LogDebug("No matching arrival found, using next upcoming trip"); } diff --git a/src/Enmarcha.Backend/Services/Processors/VigoUsageProcessor.cs b/src/Enmarcha.Backend/Services/Processors/VigoUsageProcessor.cs index f5c7664..7f98fff 100644 --- a/src/Enmarcha.Backend/Services/Processors/VigoUsageProcessor.cs +++ b/src/Enmarcha.Backend/Services/Processors/VigoUsageProcessor.cs @@ -1,6 +1,5 @@ using System.Text.Json; using CsvHelper; -using CsvHelper.Configuration; using Enmarcha.Backend.Types.Arrivals; using Microsoft.Extensions.Caching.Memory; using System.Globalization; diff --git a/src/Enmarcha.Sources.CtagShuttle/CtagShuttleRealtimeEstimatesProvider.cs b/src/Enmarcha.Sources.CtagShuttle/CtagShuttleRealtimeEstimatesProvider.cs new file mode 100644 index 0000000..3ec0c6f --- /dev/null +++ b/src/Enmarcha.Sources.CtagShuttle/CtagShuttleRealtimeEstimatesProvider.cs @@ -0,0 +1,30 @@ +using System.Net.Http.Json; + +namespace Enmarcha.Sources.CtagShuttle; + +public class CtagShuttleRealtimeEstimatesProvider +{ + private HttpClient _http; + + public CtagShuttleRealtimeEstimatesProvider(HttpClient http) + { + _http = http; + } + + public async Task GetShuttleStatus() + { + const string url = "https://shuttle.brain4mobility.com/status"; + + var response = await _http.GetAsync(url); + var status = await response.Content.ReadFromJsonAsync(); + + if (status is null) + { + throw new InvalidOperationException("Failed to retrieve shuttle status"); + } + + return status; + } + +} + diff --git a/src/Enmarcha.Sources.CtagShuttle/Enmarcha.Sources.CtagShuttle.csproj b/src/Enmarcha.Sources.CtagShuttle/Enmarcha.Sources.CtagShuttle.csproj new file mode 100644 index 0000000..237d661 --- /dev/null +++ b/src/Enmarcha.Sources.CtagShuttle/Enmarcha.Sources.CtagShuttle.csproj @@ -0,0 +1,9 @@ + + + + net10.0 + enable + enable + + + diff --git a/src/Enmarcha.Sources.CtagShuttle/Status.cs b/src/Enmarcha.Sources.CtagShuttle/Status.cs new file mode 100644 index 0000000..ecf2da1 --- /dev/null +++ b/src/Enmarcha.Sources.CtagShuttle/Status.cs @@ -0,0 +1,46 @@ +using System.Text.Json.Serialization; + +namespace Enmarcha.Sources.CtagShuttle; + +public class CtagShuttleStatus +{ + [JsonPropertyName("status")] public required string StatusValue { get; set; } + [JsonPropertyName("lat")] public double Latitude { get; set; } + [JsonPropertyName("lng")] public double Longitude { get; set; } + [JsonPropertyName("last_position_at")] public required string LastPositionAtValue { get; set; } + [JsonPropertyName("free_seats")] public int FreeSeats { get; set; } + + [JsonPropertyName("last_occupancy_at")] + public required string LastOccupancyAtValue { get; set; } + + [JsonIgnore] + public Status Status => Status.Parse(StatusValue); + + [JsonIgnore] + public DateTime LastPositionAt => DateTime.Parse(LastPositionAtValue); + + [JsonIgnore] + public DateTime LastOccupancyAt => DateTime.Parse(LastOccupancyAtValue); +} + +public enum Status +{ + Idle, + Operating +} + +public static class StatusExtensions +{ + extension(Status) + { + public static Status Parse(string value) + { + return value switch + { + "idle" => Status.Idle, + "operating" => Status.Operating, + _ => throw new ArgumentException($"Invalid status value: {value}") + }; + } + } +} diff --git a/src/frontend/app/i18n/locales/en-GB.json b/src/frontend/app/i18n/locales/en-GB.json index 3d8b32f..aed0066 100644 --- a/src/frontend/app/i18n/locales/en-GB.json +++ b/src/frontend/app/i18n/locales/en-GB.json @@ -12,7 +12,7 @@ "data_traffic_source": "Municipal open data", "data_lines": "Line listings and schedules", "map_tiles": "Maps", - "map_themes": "(\"liberty\" and \"positron\" themes for light/dark mode)", + "map_themes": "(\"libery\" theme, modified by myself)", "thanks_council": "Special thanks to Vigo City Council for providing this data under an open license.", "credits": "Credits", "developed_by": "Developed by", diff --git a/src/frontend/app/i18n/locales/es-ES.json b/src/frontend/app/i18n/locales/es-ES.json index 2184cfc..1c805b3 100644 --- a/src/frontend/app/i18n/locales/es-ES.json +++ b/src/frontend/app/i18n/locales/es-ES.json @@ -12,7 +12,7 @@ "data_traffic_source": "Datos abiertos municipales", "data_lines": "Listado de líneas y horarios", "map_tiles": "Mapas", - "map_themes": "(temas \"liberty\" y \"positron\" para modo claro/oscuro)", + "map_themes": "(tema \"liberty\", modificado por mí)", "thanks_council": "Agradecemos especialmente al Concello de Vigo por facilitar estos datos bajo licencia abierta.", "credits": "Créditos", "developed_by": "Desarrollado por", diff --git a/src/frontend/app/i18n/locales/gl-ES.json b/src/frontend/app/i18n/locales/gl-ES.json index b951278..1af3b56 100644 --- a/src/frontend/app/i18n/locales/gl-ES.json +++ b/src/frontend/app/i18n/locales/gl-ES.json @@ -16,7 +16,7 @@ "data_traffic_source": "Datos abertos municipais", "data_lines": "Listaxe de liñas e horarios", "map_tiles": "Mapas", - "map_themes": "(temas \"liberty\" e \"positron\" para modo claro/escuro)", + "map_themes": "(tema \"liberty\", modificado por min)", "thanks_council": "Agradecemos especialmente ao Concello de Vigo por facilitar estes datos baixo licenza aberta.", "credits": "Créditos", "developed_by": "Desenvolvido por", -- cgit v1.3