mirror of
https://github.com/alexhopeoconnor/bom-local-service.git
synced 2026-10-04 03:28:11 +10:00
- Fix scraping to wait for display label to change after step forward, preventing duplicate minutesAgo values within same folder - Add hashset-based deduplication by AbsoluteObservationTime across cache folders - Filter frames that are too close together (< 4 minutes apart) - Preserve original folder structure while pruning filtered frames - Sort folders by earliest frame time to maintain chronological order - Add validation to detect folder overlaps that could cause out-of-order frames
66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
using BomLocalService.Models;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace BomLocalService.Utilities;
|
|
|
|
/// <summary>
|
|
/// Utility methods for cache folder validation and operations.
|
|
/// </summary>
|
|
public static class CacheHelper
|
|
{
|
|
/// <summary>
|
|
/// Gets the configured frame count for a data type from configuration.
|
|
/// </summary>
|
|
public static int GetFrameCountForDataType(IConfiguration configuration, CachedDataType dataType)
|
|
{
|
|
var dataTypeName = dataType.ToString();
|
|
var frameCount = configuration.GetValue<int>($"CachedDataTypes:{dataTypeName}:FrameCount", 7);
|
|
return frameCount;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if a cache folder has complete data for a specific data type.
|
|
/// </summary>
|
|
public static bool IsCacheFolderCompleteForDataType(string cacheFolderPath, CachedDataType dataType, IConfiguration configuration)
|
|
{
|
|
if (string.IsNullOrEmpty(cacheFolderPath) || !Directory.Exists(cacheFolderPath))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var dataTypeFolder = FilePathHelper.GetDataTypeFolderPath(cacheFolderPath, dataType);
|
|
if (!Directory.Exists(dataTypeFolder))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var expectedFrameCount = GetFrameCountForDataType(configuration, dataType);
|
|
for (int i = 0; i < expectedFrameCount; i++)
|
|
{
|
|
var framePath = FilePathHelper.GetFrameFilePath(cacheFolderPath, dataType, i);
|
|
if (!File.Exists(framePath))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Check for frames.json in data type folder
|
|
var framesMetadataPath = FilePathHelper.GetFramesMetadataFilePath(cacheFolderPath, dataType);
|
|
if (!File.Exists(framesMetadataPath))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if a cache folder is complete (has radar data - for backward compatibility).
|
|
/// </summary>
|
|
public static bool IsCacheFolderComplete(string cacheFolderPath, IConfiguration configuration)
|
|
{
|
|
return IsCacheFolderCompleteForDataType(cacheFolderPath, CachedDataType.Radar, configuration);
|
|
}
|
|
}
|
|
|