Skip to content

Commit

Permalink
Add timestamp on spectral density page
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler committed Jan 8, 2025
1 parent b2735f4 commit 978d892
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions OrcanodeMonitor/Core/Fetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,14 @@ private static void AddHydrophoneStreamStatusEvent(OrcanodeMonitorContext contex
return await GetExactAudioSampleAsync(node, newUri, logger);
}

public async static Task<DateTime?> GetLastModifiedAsync(Uri uri)
{
using var headRequest = new HttpRequestMessage(HttpMethod.Head, uri);
using var headResponse = await _httpClient.SendAsync(headRequest);
DateTime? lastModified = headResponse.Content.Headers.LastModified?.UtcDateTime;
return lastModified;
}

public async static Task<FrequencyInfo?> GetExactAudioSampleAsync(Orcanode node, Uri uri, ILogger logger)
{
OrcanodeOnlineStatus oldStatus = node.S3StreamStatus;
Expand Down
3 changes: 2 additions & 1 deletion OrcanodeMonitor/Pages/SpectralDensity.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<script src="https://github.com/xqq/mpegts.js/releases/download/v1.8.0/mpegts.js"></script>
<div class="text-center">
<h1 class="display-4">Spectral Density of Audio From @Model.NodeName</h1>
As of: @Model.LastModified<br />

<!-- Include Chart.js from CDN -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
Expand All @@ -21,7 +22,7 @@
labels: @Html.Raw(Json.Serialize(Model.Labels)),
datasets: [
{
label: 'Last Sample',
label: 'Audio Sample',
data: @Html.Raw(Json.Serialize(Model.MaxBucketMagnitude)),
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderColor: 'rgba(75, 192, 192, 1)',
Expand Down
5 changes: 5 additions & 0 deletions OrcanodeMonitor/Pages/SpectralDensity.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class SpectralDensityModel : PageModel
public string Status { get; private set; }
public double MaxSilenceMagnitude => FrequencyInfo.MaxSilenceMagnitude;
public double MinNoiseMagnitude => FrequencyInfo.MinNoiseMagnitude;
public string LastModified { get; private set; }

public SpectralDensityModel(OrcanodeMonitorContext context, ILogger<SpectralDensityModel> logger)
{
Expand Down Expand Up @@ -113,6 +114,10 @@ private async Task UpdateEventFrequencyDataAsync()
_logger.LogWarning("URI not found with event ID: {EventID}", _id);
return;
}

DateTime? lastModified = await Fetcher.GetLastModifiedAsync(uri);
LastModified = lastModified?.ToLocalTime().ToString() ?? "Unknown";

FrequencyInfo? frequencyInfo = await Fetcher.GetExactAudioSampleAsync(_node, uri, _logger);
if (frequencyInfo != null)
{
Expand Down

0 comments on commit 978d892

Please sign in to comment.