aboutsummaryrefslogtreecommitdiff
path: root/src/Enmarcha.Backend/Services
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2026-03-08 23:42:39 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2026-03-08 23:42:39 +0100
commit5288cfbed34f94c4321b8d9dc497cfd0da3ffd26 (patch)
treefc4038fa829a07e58944d32b4b34f626b935e686 /src/Enmarcha.Backend/Services
parent4056bc1b66db722bfcffaa960f8ff89150971a4d (diff)
Refactor VigoUsageProcessor to remove CSV whitelist loading; add StopUsageChart component for usage visualization in Stops page
Diffstat (limited to 'src/Enmarcha.Backend/Services')
-rw-r--r--src/Enmarcha.Backend/Services/Processors/VigoUsageProcessor.cs54
1 files changed, 0 insertions, 54 deletions
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))