Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix history graph #256

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions OrcanodeMonitor/Pages/NodeEvents.cshtml
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255, 99, 132, 1)',
borderWidth: 1,
spanGaps: true,
stepped: 'before'
},
{
@@ -55,6 +56,7 @@
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderColor: 'rgba(0, 255, 0, 1)',
borderWidth: 1,
spanGaps: true,
stepped: 'before'
},
{
@@ -63,6 +65,7 @@
backgroundColor: 'rgba(54, 162, 235, 0.2)',
borderColor: 'rgba(54, 162, 235, 1)',
borderWidth: 1,
spanGaps: true,
stepped: 'before'
}
]
52 changes: 29 additions & 23 deletions OrcanodeMonitor/Pages/NodeEvents.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) Orcanode Monitor contributors
// SPDX-License-Identifier: MIT
using MathNet.Numerics.Statistics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using OrcanodeMonitor.Core;
using OrcanodeMonitor.Data;
@@ -89,7 +87,7 @@ private static int StatusStringToInt(string value)
public string JsonMezmoData { get; set; }
public string JsonHydrophoneStreamData { get; set; }

private void AddCurrentEvent(List<OrcanodeEvent> events, DateTime origin, DateTime now)
private void AddCurrentEvent(List<OrcanodeEvent> events, DateTime now)
{
if (!events.Any())
{
@@ -102,41 +100,49 @@ private void AddCurrentEvent(List<OrcanodeEvent> events, DateTime origin, DateTi
return;
}

if (last.DateTimeUtc == now)
{
return;
}

var current = new OrcanodeEvent(last.Orcanode, last.Type, last.Value, now, null);
events.Add(current);
}

private string CreateJsonDataset(string type, List<DateTime> allTimestamps, DateTime now)
{
List<OrcanodeEvent> dataset = _events.Where(e => e.Type == type).OrderBy(e => e.DateTimeUtc).ToList();
AddCurrentEvent(dataset, now);

OrcanodeEvent first = events.First();
if (first.DateTimeUtc == origin)
var alignedDataset = allTimestamps.Select(timestamp =>
{
return;
}
var original = new OrcanodeEvent(last.Orcanode, last.Type, Orcanode.GetStatusString(OrcanodeOnlineStatus.Absent), origin, null);
events.Insert(0, original);
var matchingEvent = dataset.FirstOrDefault(e => e.DateTimeUtc == timestamp);
return new
{
Timestamp = timestamp,
StateValue = matchingEvent != null ? StatusStringToInt(matchingEvent.Value) : (int?)null
};
}).ToList();

string json = JsonSerializer.Serialize(alignedDataset);
return json;
}

private void FetchEvents(ILogger logger)
{
_events = Fetcher.GetRecentEventsForNode(_databaseContext, Id, DateTime.MinValue, logger)
.ToList() ?? new List<OrcanodeEvent>();

DateTime now = DateTime.UtcNow;
if (!_events.Any())
{
return; // Nothing to do.
}
OrcanodeEvent firstEvent = _events.OrderBy(e => e.DateTimeUtc).First();
DateTime firstTimeUtc = firstEvent.DateTimeUtc;

List<OrcanodeEvent> dataplicityEvents = _events.Where(e => e.Type == OrcanodeEventTypes.DataplicityConnection).OrderBy(e => e.DateTimeUtc).ToList();
AddCurrentEvent(dataplicityEvents, firstTimeUtc, now);
List<OrcanodeEvent> hydrophoneStreamEvents = _events.Where(e => e.Type == OrcanodeEventTypes.HydrophoneStream).OrderBy(e => e.DateTimeUtc).ToList();
AddCurrentEvent(hydrophoneStreamEvents, firstTimeUtc, now);
List<OrcanodeEvent> mezmoEvents = _events.Where(e => e.Type == OrcanodeEventTypes.MezmoLogging).OrderBy(e => e.DateTimeUtc).ToList();
AddCurrentEvent(mezmoEvents, firstTimeUtc, now);

JsonDataplicityData = JsonSerializer.Serialize(dataplicityEvents.Select(e => new { Timestamp = e.DateTimeUtc, StateValue = StatusStringToInt(e.Value) }));
JsonMezmoData = JsonSerializer.Serialize(mezmoEvents.Select(e => new { Timestamp = e.DateTimeUtc, StateValue = StatusStringToInt(e.Value) }));
JsonHydrophoneStreamData = JsonSerializer.Serialize(hydrophoneStreamEvents.Select(e => new { Timestamp = e.DateTimeUtc, StateValue = StatusStringToInt(e.Value) }));

DateTime now = DateTime.UtcNow;
List<DateTime> allTimestamps = _events.Select(e => e.DateTimeUtc).Union(new List<DateTime> { now }).OrderBy(t => t).ToList();
JsonDataplicityData = CreateJsonDataset(OrcanodeEventTypes.DataplicityConnection, allTimestamps, now);
JsonMezmoData = CreateJsonDataset(OrcanodeEventTypes.MezmoLogging, allTimestamps, now);
JsonHydrophoneStreamData = CreateJsonDataset(OrcanodeEventTypes.HydrophoneStream, allTimestamps, now);
}

public void OnGet(string id)
2 changes: 1 addition & 1 deletion docs/Design.md
Original file line number Diff line number Diff line change
@@ -113,7 +113,7 @@ The following state will be stored per orcanode:

**MEZMO_LOG_SECONDS**: The number of seconds of Mezmo logs to check for activity. Default: 60

**ORCASOUND_MIN_INTELLIGIBLE_SIGNAL_PERCENT**: The minimum percentage of total magnitude across all frequencies outside the hum range vs magnitude in hum range (multiples of 60 Hz), needed to determine that an audio stream is intelligible. Default: 150
**ORCASOUND_MIN_INTELLIGIBLE_SIGNAL_PERCENT**: The minimum percentage of total magnitude across all frequencies outside the hum range vs magnitude in hum range (multiples of 60 Hz), needed to determine that an audio stream is intelligible. Default: 100

**ORCASOUND_MAX_SILENCE_MAGNITUDE**: The maximum magnitude at which a stream stream might still be considered unintelligible due to silence. Default: 20