Skip to content

Commit

Permalink
Add AudioStreamStatus field to cosmosdb
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler committed Sep 28, 2024
1 parent 41033c8 commit a4b5cc1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 2 additions & 2 deletions OrcanodeMonitor/Core/Fetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,8 @@ public async static Task UpdateManifestTimestampAsync(OrcanodeMonitorContext con
try
{
using Stream stream = await _httpClient.GetStreamAsync(newUri);
OrcanodeOnlineStatus status = await FfmpegCoreAnalyzer.AnalyzeAudioStreamAsync(stream);
node.AudioStandardDeviation = (status == OrcanodeOnlineStatus.Unintelligible) ? 0 : 10000;
node.AudioStreamStatus = await FfmpegCoreAnalyzer.AnalyzeAudioStreamAsync(stream);
node.AudioStandardDeviation = 0.0;
} catch (Exception ex)
{
// We couldn't fetch the stream audio so could not update the
Expand Down
5 changes: 5 additions & 0 deletions OrcanodeMonitor/Data/OrcanodeMonitorContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.ToContainer("Orcanode")
.Property(item => item.ID);

modelBuilder.Entity<Orcanode>()
.ToContainer("Orcanode")
.Property(item => item.AudioStreamStatus)
.HasDefaultValue(OrcanodeOnlineStatus.Absent);

modelBuilder.Entity<Orcanode>()
.ToContainer("Orcanode")
.HasPartitionKey(item => item.PartitionValue)
Expand Down
22 changes: 20 additions & 2 deletions OrcanodeMonitor/Models/Orcanode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Orcanode()
DataplicityName = string.Empty;
DataplicitySerial = string.Empty;
OrcaHelloId = string.Empty;
PartitionValue = 1;
PartitionValue = 1;
}

#region persisted
Expand Down Expand Up @@ -182,6 +182,11 @@ public Orcanode()
/// Partition key fixed value.
/// </summary>
public int PartitionValue { get; set; }

/// <summary>
/// Audio stream status of most recent sample (defaults to absent).
/// </summary>
public OrcanodeOnlineStatus? AudioStreamStatus { get; set; }

#endregion persisted

Expand Down Expand Up @@ -295,7 +300,14 @@ public OrcanodeOnlineStatus S3StreamStatus
{
return OrcanodeOnlineStatus.Offline;
}
return (IsUnintelligible(AudioStandardDeviation)) ? OrcanodeOnlineStatus.Unintelligible : OrcanodeOnlineStatus.Online;

if (AudioStreamStatus == OrcanodeOnlineStatus.Absent && AudioStandardDeviation != 0.0)
{
// Fall back to legacy algorithm.
AudioStreamStatus = (IsUnintelligible(AudioStandardDeviation)) ? OrcanodeOnlineStatus.Unintelligible : OrcanodeOnlineStatus.Online;
}

return AudioStreamStatus ?? OrcanodeOnlineStatus.Absent;
}
}

Expand All @@ -313,6 +325,12 @@ public string OrcasoundOnlineStatusString {

#region methods

/// <summary>
/// Function used for backwards compatibility when reading a database
/// entry with no AudioStreamStatus.
/// </summary>
/// <param name="audioStandardDeviation"></param>
/// <returns></returns>
public static bool IsUnintelligible(double? audioStandardDeviation)
{
if (audioStandardDeviation.HasValue && (audioStandardDeviation < MinIntelligibleStreamDeviation))
Expand Down

0 comments on commit a4b5cc1

Please sign in to comment.