Add radar test page with auto-play and connection monitoring

- Add MVC test page at /radar/{suburb}/{state} demonstrating API usage
- Implement auto-play on page load with cookie-based settings
- Add connection monitoring with automatic retry on API downtime
- Show update status, cache state, and next check times
- Fix NextUpdateTime calculation to account for background service intervals
- Add graceful error handling and visual status indicators
This commit is contained in:
2025-12-07 15:23:18 +10:00
parent 27dd44aaa1
commit 151ea1c6ac
7 changed files with 1003 additions and 10 deletions
+33 -2
View File
@@ -7,6 +7,7 @@ public static class ResponseBuilder
/// <summary>
/// Creates a RadarResponse from a cache folder path, frames, and metadata
/// </summary>
/// <param name="cacheManagementCheckIntervalMinutes">The interval in minutes that the background cache management service checks for updates. Used to calculate NextUpdateTime when cache is invalid.</param>
public static RadarResponse CreateRadarResponse(
string cacheFolderPath,
List<RadarFrame> frames,
@@ -15,7 +16,8 @@ public static class ResponseBuilder
string? state = null,
bool? cacheIsValid = null,
DateTime? cacheExpiresAt = null,
bool isUpdating = false)
bool isUpdating = false,
int cacheManagementCheckIntervalMinutes = 5)
{
var folderInfo = new DirectoryInfo(cacheFolderPath);
var lastWriteTime = folderInfo.Exists
@@ -33,6 +35,35 @@ public static class ResponseBuilder
}
}
// Calculate NextUpdateTime based on cache status:
// - If cache is valid: NextUpdateTime = max(CacheExpiresAt, next background service check)
// (Background service checks every N minutes, so update might happen at next check after expiry)
// - If cache is invalid and updating: NextUpdateTime = estimated completion time (~2 minutes)
// - If cache is invalid and NOT updating: NextUpdateTime = next background service check (based on check interval)
DateTime? nextUpdateTime = null;
// Calculate next background service check time (rounds up to next check interval)
var now = DateTime.UtcNow;
var minutesUntilNextCheck = cacheManagementCheckIntervalMinutes - (now.Minute % cacheManagementCheckIntervalMinutes);
var nextServiceCheck = now.AddMinutes(minutesUntilNextCheck);
if (isUpdating)
{
// Update in progress - estimate completion in ~2 minutes
nextUpdateTime = now.AddMinutes(2);
}
else if (cacheIsValid == true && cacheExpiresAt.HasValue)
{
// Cache is valid - next update will be when cache expires OR next service check, whichever is later
// This accounts for the fact that the background service only checks every N minutes
nextUpdateTime = cacheExpiresAt.Value > nextServiceCheck ? cacheExpiresAt.Value : nextServiceCheck;
}
else if (cacheIsValid == false)
{
// Cache is invalid and not updating - next update will be at next background service check
nextUpdateTime = nextServiceCheck;
}
var response = new RadarResponse
{
Frames = frames,
@@ -44,7 +75,7 @@ public static class ResponseBuilder
CacheIsValid = cacheIsValid ?? false,
CacheExpiresAt = cacheExpiresAt,
IsUpdating = isUpdating,
NextUpdateTime = cacheExpiresAt ?? (isUpdating ? DateTime.UtcNow.AddMinutes(2) : null) // Estimate 2 min for update if in progress
NextUpdateTime = nextUpdateTime
};
return response;