记录实际触发事件并区分服务未答与视觉未通过
This commit is contained in:
parent
1f4242875f
commit
262f630b69
@ -76,6 +76,7 @@ public sealed class SopDraftVideoVerifier : ISopDraftVideoVerifier
|
||||
while (!playback.IsAtEnd && failure is null) await Task.Delay(100, budget.Token);
|
||||
if (failure is not null) throw new IOException(failure);
|
||||
await test.FinishPendingDecisionAsync(budget.Token);
|
||||
infrastructureFailure |= test.StepResults.Any(s => s.Message.Contains("检查服务未配置") || s.Message.Contains("不支持所需证据"));
|
||||
EnsureSource();
|
||||
var blocked = test.StepResults.FirstOrDefault(s => !s.Completed);
|
||||
var references = new List<SopDraftReferenceCheck>();
|
||||
|
||||
@ -28,6 +28,7 @@ public partial class SopEngine
|
||||
public long LastFrame = -1, SentFrame = -1, StartedAt, LastSubmittedAt, FinishedAt;
|
||||
public double BudgetSeconds, LatestSeconds, LastMotionSeconds;
|
||||
public double LatestTriggerSeconds = double.NegativeInfinity, LastSubmittedSourceSeconds = double.NegativeInfinity;
|
||||
public VisionTriggerObservation? TriggerObservation;
|
||||
public int Attempts, SentVersion;
|
||||
public Dictionary<HandType, (double X, double Y)> Anchors = [];
|
||||
public string Reason = "尚未获得检查结果";
|
||||
@ -74,7 +75,11 @@ public partial class SopEngine
|
||||
else if ((seconds - state.LastMotionSeconds) * 1000 >= state.Step.AiConfirmation!.CheckSettleMs)
|
||||
state.SawQuiet = true;
|
||||
var trigger = EvaluateCaptureGate(state.Step, frame, state.Gate, "continuous");
|
||||
if (trigger.IsMet && !state.GateWasMet) state.LatestTriggerSeconds = seconds;
|
||||
if (trigger.IsMet && !state.GateWasMet)
|
||||
{
|
||||
state.LatestTriggerSeconds = seconds;
|
||||
state.TriggerObservation = new(frame.FrameId, frame.Timestamp, frame.SourceSeconds, state.Step.Detection!.Method);
|
||||
}
|
||||
state.GateWasMet = trigger.IsMet;
|
||||
if (!state.Triggered && trigger.IsMet)
|
||||
{
|
||||
@ -156,7 +161,11 @@ public partial class SopEngine
|
||||
}
|
||||
if (expired)
|
||||
{
|
||||
if (_pendingDecision is not null) state.Reason = "已发送的检查未在预算内返回,结果仍未确认";
|
||||
if (_pendingDecision is { } unfinished)
|
||||
{
|
||||
state.Reason = "检查窗口超时或已取消,未获得模型结果";
|
||||
DecisionEvaluated?.Invoke(unfinished.Request, new(false, 0, state.Reason, VisionDecisionStatus.Insufficient), false);
|
||||
}
|
||||
InvalidateDecision(discardBuffered: false);
|
||||
return new() { IsSkipped = true, Message = $"检查窗口到期,{state.Attempts} 次送检未确认通过,已跳过并继续后续步骤:{state.Reason}" };
|
||||
}
|
||||
@ -213,7 +222,7 @@ public partial class SopEngine
|
||||
var last = frames[^1];
|
||||
var request = new VisionDecisionRequest(_config.Sop.Name, step.Id, step.Name, step.Description, step.Description,
|
||||
last.FrameId, last.CapturedAt, last.Jpeg, options.EvidenceMode,
|
||||
options.EvidenceMode == VisionEvidenceMode.Sequence ? frames : null, last.SourceSeconds);
|
||||
options.EvidenceMode == VisionEvidenceMode.Sequence ? frames : null, last.SourceSeconds, TriggerObservation: state.TriggerObservation);
|
||||
var remaining = Math.Max(1, options.CheckWindowMs - state.ElapsedMs);
|
||||
var cancellation = new CancellationTokenSource(TimeSpan.FromMilliseconds(Math.Min(options.TimeoutSeconds * 1000d, remaining)));
|
||||
state.Attempts++; state.SentVersion = state.Window.Version; state.SentFrame = last.FrameId; state.LastSubmittedAt = Environment.TickCount64;
|
||||
|
||||
@ -46,6 +46,7 @@ public static class VisionEvidenceMode
|
||||
|
||||
public enum VisionDecisionStatus { Unspecified, Completed, NotCompleted, Insufficient, Unsupported }
|
||||
public sealed record VisionEvidenceFrame(long FrameId, DateTime CapturedAt, byte[] Jpeg, double? SourceSeconds = null);
|
||||
public sealed record VisionTriggerObservation(long FrameId, DateTime ObservedAt, double? SourceSeconds, string Method);
|
||||
|
||||
public static class VisionImageMode
|
||||
{
|
||||
@ -61,7 +62,8 @@ public static class VisionImageMode
|
||||
public sealed record VisionDecisionRequest(string Recipe, int StepId, string Step, string Description,
|
||||
string Criteria, long FrameId, DateTime CapturedAt, byte[] Jpeg,
|
||||
string EvidenceMode = VisionEvidenceMode.SingleFrame, IReadOnlyList<VisionEvidenceFrame>? Frames = null, double? SourceSeconds = null,
|
||||
[property: System.Text.Json.Serialization.JsonIgnore] VisionEvidenceFrame? ConfirmationEvidence = null);
|
||||
[property: System.Text.Json.Serialization.JsonIgnore] VisionEvidenceFrame? ConfirmationEvidence = null,
|
||||
VisionTriggerObservation? TriggerObservation = null);
|
||||
public sealed record VisionDecisionResult(bool Completed, double Confidence, string Reason,
|
||||
VisionDecisionStatus Status = VisionDecisionStatus.Unspecified, IReadOnlyList<long>? EvidenceFrameIds = null, long? CompletionFrameId = null)
|
||||
{
|
||||
|
||||
@ -51,7 +51,7 @@ internal static class SequenceTrialChecks
|
||||
var frames = collected.Select(f => new { f.FrameId, f.SourceSeconds, Bytes = f.Jpeg.Length,
|
||||
ImageFile = $"step-{request.StepId:D2}-frame-{f.FrameId:D6}.jpg" }).ToArray();
|
||||
requests.Add(new { Number = number, WallSeconds = watch.Elapsed.TotalSeconds, CurrentVideoSeconds = latestSeconds,
|
||||
request.StepId, request.EvidenceMode, request.Criteria, Frames = frames });
|
||||
request.StepId, request.EvidenceMode, request.Criteria, request.TriggerObservation, Frames = frames });
|
||||
Console.WriteLine($"提交 {number}: 步骤 {request.StepId},视频 {latestSeconds:F2}s,{frames.Length} 张真实画面");
|
||||
};
|
||||
test.DecisionEvaluated += (request, result, accepted) =>
|
||||
|
||||
@ -83,10 +83,14 @@ internal static class ContinuousCheckTests
|
||||
|
||||
// 服务永不返回:窗口硬截止取消本步;迟到的 true 不得影响下一步。
|
||||
var slow = new Client(); var timed = new SopEngine { VisionDecisionClient = slow }; timed.Load(Config()); timed.Start();
|
||||
var timedOut = 0;
|
||||
timed.DecisionEvaluated += (_, result, accepted) =>
|
||||
{ if (!accepted && result.EffectiveStatus == VisionDecisionStatus.Insufficient && result.Reason.Contains("未获得模型结果")) timedOut++; };
|
||||
void SlowFeed(int id, double seconds, int x) => timed.ProcessFrame(Frame(id, seconds, x), () => [(byte)id]);
|
||||
SlowFeed(1, 0, 10); SlowFeed(2, .2, 10); await Until(() => slow.Calls.Count == 1);
|
||||
SlowFeed(3, .4, 120); SlowFeed(4, .6, 120); SlowFeed(5, 2.1, 120);
|
||||
Check(timed.CurrentStep?.Id == 2 && timed.SkippedSteps.Contains(1), "服务挂起也不能阻塞到检查窗口之外");
|
||||
Check(timed.CurrentStep?.Id == 2 && timed.SkippedSteps.Contains(1) && timedOut == 1,
|
||||
"服务挂起不能阻塞到检查窗口之外,且须明确反馈未收到结果而不是误记为模型否决");
|
||||
slow.Calls.ElementAt(0).Result.SetResult(new(true, 1, "迟到结果"));
|
||||
timed.ProcessFrame(Frame(5, 2.1, 120)); await Until(() => slow.Calls.Count == 2);
|
||||
Check(timed.CurrentStep?.Id == 2 && timed.SkippedSteps.Contains(1), "已跳过步骤的迟到结果不能放行后续步骤");
|
||||
@ -147,7 +151,7 @@ internal static class ContinuousCheckTests
|
||||
Check(leaveClient.Calls.Count == 1, "离散动作不能复用早于前序完成的旧离开事件");
|
||||
LeaveFeed(5, .9, 120); LeaveFeed(6, 1.1, 10); LeaveFeed(7, 1.3, 10);
|
||||
await Until(() => leaveClient.Calls.Count == 2);
|
||||
Check(leaveClient.Calls.ElementAt(1).Request.SourceSeconds >= 1.1,
|
||||
Check(leaveClient.Calls.ElementAt(1).Request.SourceSeconds >= 1.1 && leaveClient.Calls.ElementAt(1).Request.TriggerObservation?.SourceSeconds == 1.1,
|
||||
"必须用前序结果之后新发生的离开事件触发检查,已采集的后续证据仍须保留");
|
||||
leave.Stop();
|
||||
Console.WriteLine("PASS: 停稳触发、新帧重试、限时跳过、后续动作持续取证、挂起硬截止、迟到结果隔离和非合格整轮统计");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user