Harden Well shakedown capture
This commit is contained in:
parent
71c436622b
commit
93986ebe0a
5 changed files with 127 additions and 10 deletions
|
|
@ -114,7 +114,7 @@ internal sealed class EveSensorReceiver(EveSensorReceiverOptions options) : IDis
|
|||
if (TryValidateCultMeshObservation(frame.Payload, out var normalizedObservation)
|
||||
|| TryValidateCultMeshMediaObservation(frame.Payload, out normalizedObservation))
|
||||
{
|
||||
Console.WriteLine(normalizedObservation);
|
||||
Console.WriteLine(ObservationStdoutLine(normalizedObservation));
|
||||
Console.Out.Flush();
|
||||
await BroadcastAsync(normalizedObservation).ConfigureAwait(false);
|
||||
}
|
||||
|
|
@ -130,13 +130,45 @@ internal sealed class EveSensorReceiver(EveSensorReceiverOptions options) : IDis
|
|||
var text = Encoding.UTF8.GetString(frame.Payload);
|
||||
if (TryValidateFrameEvent(text, out var normalized))
|
||||
{
|
||||
Console.WriteLine(normalized);
|
||||
Console.WriteLine(ObservationStdoutLine(normalized));
|
||||
Console.Out.Flush();
|
||||
await BroadcastAsync(normalized).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string ObservationStdoutLine(string normalized)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var document = JsonDocument.Parse(normalized);
|
||||
var root = document.RootElement;
|
||||
if (root.TryGetProperty("document", out var documentKind)
|
||||
&& string.Equals(documentKind.GetString(), "mimir.well_capture_page.v1", StringComparison.Ordinal))
|
||||
{
|
||||
var sampleCount = root.TryGetProperty("samples", out var samples)
|
||||
&& samples.ValueKind == JsonValueKind.Array
|
||||
? samples.GetArrayLength()
|
||||
: 0;
|
||||
return JsonSerializer.Serialize(new
|
||||
{
|
||||
type = root.GetProperty("type").GetString(),
|
||||
document = "mimir.well_capture_page.v1",
|
||||
sourceId = root.TryGetProperty("sourceId", out var sourceId) ? sourceId.GetString() : null,
|
||||
nodeId = root.TryGetProperty("nodeId", out var nodeId) ? nodeId.GetString() : null,
|
||||
captureSequence = root.TryGetProperty("captureSequence", out var sequence) ? sequence.GetInt64() : 0,
|
||||
sampleCount,
|
||||
stdoutBodyPolicy = "body-redacted",
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
private async Task SubscribeAsync(NetworkStream stream)
|
||||
{
|
||||
var id = Interlocked.Increment(ref nextSubscriberId);
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@ while (!stopping.IsCancellationRequested)
|
|||
options,
|
||||
presentation,
|
||||
frame,
|
||||
hub.Buffers.Buffers,
|
||||
++captureSequence,
|
||||
startedAt);
|
||||
await publisher.PublishAsync(capturePage, stopping.Token).ConfigureAwait(false);
|
||||
|
|
@ -285,6 +286,7 @@ internal static class MimirWellCapturePage
|
|||
MimirWellOptions options,
|
||||
MimirPresentationControlState presentation,
|
||||
MimirSynchronizedBufferFrame frame,
|
||||
IEnumerable<MimirRollingStreamBuffer> buffers,
|
||||
long captureSequence,
|
||||
DateTimeOffset startedAt) => new
|
||||
{
|
||||
|
|
@ -335,12 +337,30 @@ internal static class MimirWellCapturePage
|
|||
reason = "Fensalir/OBS program-output capture is a separate producer; this page records the configured composite contract and synchronized source bodies.",
|
||||
},
|
||||
},
|
||||
samples = frame.Slices
|
||||
.Where(slice => slice.Sample.HasValue)
|
||||
.Select(slice => CaptureSample(options, captureSequence, slice))
|
||||
samples = CaptureSamples(options, captureSequence, frame, buffers)
|
||||
.ToArray(),
|
||||
};
|
||||
|
||||
private static IEnumerable<object> CaptureSamples(
|
||||
MimirWellOptions options,
|
||||
long captureSequence,
|
||||
MimirSynchronizedBufferFrame frame,
|
||||
IEnumerable<MimirRollingStreamBuffer> buffers)
|
||||
{
|
||||
var sliceSamples = frame.Slices
|
||||
.Where(slice => slice.Sample.HasValue)
|
||||
.Select(slice => CaptureSample(options, captureSequence, slice))
|
||||
.ToArray();
|
||||
if (sliceSamples.Length > 0)
|
||||
{
|
||||
return sliceSamples;
|
||||
}
|
||||
|
||||
return buffers
|
||||
.Where(buffer => buffer.Latest.HasValue)
|
||||
.Select(buffer => CaptureLatestFallbackSample(options, captureSequence, buffer));
|
||||
}
|
||||
|
||||
private static object CaptureSample(
|
||||
MimirWellOptions options,
|
||||
long captureSequence,
|
||||
|
|
@ -371,6 +391,36 @@ internal static class MimirWellCapturePage
|
|||
};
|
||||
}
|
||||
|
||||
private static object CaptureLatestFallbackSample(
|
||||
MimirWellOptions options,
|
||||
long captureSequence,
|
||||
MimirRollingStreamBuffer buffer)
|
||||
{
|
||||
var sample = buffer.Latest!.Value;
|
||||
var bodyId = $"{options.NodeId}:{captureSequence}:{sample.SourceId}:{sample.Sequence}:latest";
|
||||
return new
|
||||
{
|
||||
bodyId,
|
||||
slice = new
|
||||
{
|
||||
sample.SourceId,
|
||||
Kind = sample.Kind.ToString(),
|
||||
Origin = sample.Origin.ToString(),
|
||||
Status = "LatestUnalignedFallback",
|
||||
SourceTimestampNs = sample.TimestampNs,
|
||||
CanonicalStartNs = sample.TimestampNs,
|
||||
CanonicalEndNs = sample.TimestampNs,
|
||||
PresentationTimeNs = 0L,
|
||||
TimingOffsetNs = 0L,
|
||||
DistanceFromPresentationNs = 0L,
|
||||
TimingConfidence = 0.0,
|
||||
TimingEvidenceKind = "unsynchronized-fallback",
|
||||
},
|
||||
sample = SampleMetadata(sample),
|
||||
body = CaptureBody(options, sample),
|
||||
};
|
||||
}
|
||||
|
||||
private static object SampleMetadata(MimirStreamSample sample) => new
|
||||
{
|
||||
sample.SourceId,
|
||||
|
|
|
|||
Loading…
Reference in a new issue