diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2026-03-08 23:42:39 +0100 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2026-03-08 23:42:39 +0100 |
| commit | 5288cfbed34f94c4321b8d9dc497cfd0da3ffd26 (patch) | |
| tree | fc4038fa829a07e58944d32b4b34f626b935e686 /src/Enmarcha.Backend | |
| parent | 4056bc1b66db722bfcffaa960f8ff89150971a4d (diff) | |
Refactor VigoUsageProcessor to remove CSV whitelist loading; add StopUsageChart component for usage visualization in Stops page
Diffstat (limited to 'src/Enmarcha.Backend')
| -rw-r--r-- | src/Enmarcha.Backend/Data/vitrasa_stops_p95.csv | 60 | ||||
| -rw-r--r-- | src/Enmarcha.Backend/Services/Processors/VigoUsageProcessor.cs | 54 |
2 files changed, 0 insertions, 114 deletions
diff --git a/src/Enmarcha.Backend/Data/vitrasa_stops_p95.csv b/src/Enmarcha.Backend/Data/vitrasa_stops_p95.csv deleted file mode 100644 index 8091fd9..0000000 --- a/src/Enmarcha.Backend/Data/vitrasa_stops_p95.csv +++ /dev/null @@ -1,60 +0,0 @@ -codigo -14264 -8630 -6940 -14206 -14333 -8750 -5610 -6930 -8610 -8840 -5800 -1310 -5820 -5630 -6300 -2780 -8820 -8460 -8520 -8540 -8470 -14892 -8040 -8480 -6570 -8450 -6960 -5300 -6860 -5790 -5540 -20102 -6620 -14337 -5650 -1360 -20193 -8500 -1920 -20111 -20075 -5560 -5570 -7000 -5530 -2820 -5620 -5680 -5520 -6550 -1260 -1280 -8770 -2830 -14123 -14163 -14168 -2020 -8060 diff --git a/src/Enmarcha.Backend/Services/Processors/VigoUsageProcessor.cs b/src/Enmarcha.Backend/Services/Processors/VigoUsageProcessor.cs index 7f98fff..282f08a 100644 --- a/src/Enmarcha.Backend/Services/Processors/VigoUsageProcessor.cs +++ b/src/Enmarcha.Backend/Services/Processors/VigoUsageProcessor.cs @@ -1,8 +1,6 @@ using System.Text.Json; -using CsvHelper; using Enmarcha.Backend.Types.Arrivals; using Microsoft.Extensions.Caching.Memory; -using System.Globalization; namespace Enmarcha.Backend.Services.Processors; @@ -11,69 +9,18 @@ public class VigoUsageProcessor : IArrivalsProcessor private readonly HttpClient _httpClient; private readonly IMemoryCache _cache; private readonly ILogger<VigoUsageProcessor> _logger; - private readonly IHostEnvironment _environment; private readonly FeedService _feedService; - private static readonly HashSet<string> _vigoStopsWhitelist = []; - private static bool _whitelistLoaded = false; - private static readonly object _lock = new(); public VigoUsageProcessor( HttpClient httpClient, IMemoryCache cache, ILogger<VigoUsageProcessor> logger, - IHostEnvironment environment, FeedService feedService) { _httpClient = httpClient; _cache = cache; _logger = logger; - _environment = environment; _feedService = feedService; - - LoadWhitelist(); - } - - private void LoadWhitelist() - { - if (_whitelistLoaded) return; - - lock (_lock) - { - if (_whitelistLoaded) return; - - try - { - var path = Path.Combine(_environment.ContentRootPath, "Data", "vitrasa_stops_p95.csv"); - if (File.Exists(path)) - { - using var reader = new StreamReader(path); - using var csv = new CsvReader(reader, CultureInfo.InvariantCulture); - csv.Read(); - csv.ReadHeader(); - while (csv.Read()) - { - var code = csv.GetField("codigo"); - if (!string.IsNullOrWhiteSpace(code)) - { - _vigoStopsWhitelist.Add(code.Trim()); - } - } - _logger.LogInformation("Loaded {Count} Vigo stops for usage data whitelist", _vigoStopsWhitelist.Count); - } - else - { - _logger.LogWarning("Vigo stops whitelist CSV not found at {Path}", path); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Error loading Vigo stops whitelist"); - } - finally - { - _whitelistLoaded = true; - } - } } public async Task ProcessAsync(ArrivalsContext context) @@ -81,7 +28,6 @@ public class VigoUsageProcessor : IArrivalsProcessor if (!context.StopId.StartsWith("vitrasa:")) return; var normalizedCode = _feedService.NormalizeStopCode("vitrasa", context.StopCode); - if (!_vigoStopsWhitelist.Contains(normalizedCode)) return; var cacheKey = $"vigo_usage_{normalizedCode}"; if (_cache.TryGetValue(cacheKey, out List<BusStopUsagePoint>? cachedUsage)) |
