diff --git a/src/SopHelper.CrossPlatform.Engine/Sop/InspectionFrameSelector.cs b/src/SopHelper.CrossPlatform.Engine/Sop/InspectionFrameSelector.cs index 202d67e..f9d0145 100644 --- a/src/SopHelper.CrossPlatform.Engine/Sop/InspectionFrameSelector.cs +++ b/src/SopHelper.CrossPlatform.Engine/Sop/InspectionFrameSelector.cs @@ -5,11 +5,12 @@ public static class InspectionFrameSelector { public static VisionEvidenceFrame? Select(IReadOnlyList candidates, IReadOnlyDictionary inspected, IReadOnlyList boundaries, - double bufferedSpanSeconds = double.PositiveInfinity) + double bufferedSpanSeconds = double.PositiveInfinity, bool preferLatest = false) { var available = candidates.DistinctBy(f => f.FrameId).Where(f => !inspected.ContainsKey(f.FrameId)) .OrderBy(ObservationEvidenceWindow.Time).ToArray(); if (available.Length == 0) return null; + if (preferLatest) return available[^1]; if (inspected.Count == 0) { var start = ObservationEvidenceWindow.Time(available[0]); diff --git a/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs b/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs index f4f7180..0bea0ac 100644 --- a/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs +++ b/src/SopHelper.CrossPlatform.Engine/Sop/SopEngine.ContinuousChecks.cs @@ -180,7 +180,9 @@ public partial class SopEngine } var valid = candidates.Where(f => ObservationEvidenceWindow.Time(f) >= prior).ToArray(); DecisionCandidatesObserved?.Invoke(step.Id, valid); - var selected = InspectionFrameSelector.Select(valid, state.Inspected, state.Boundaries, options.ObservationMinMs / 1000d); + // 硬截止前的最后检查机会优先看正在形成的新结果,不再全部用于补查历史。 + var finalChance = options.CheckWindowMs - state.ElapsedMs <= firstWait; + var selected = InspectionFrameSelector.Select(valid, state.Inspected, state.Boundaries, options.ObservationMinMs / 1000d, finalChance); frames = selected is null ? [] : [selected]; } if (frames.Length == 0 || state.Inspected.ContainsKey(frames[^1].FrameId) diff --git a/tests/VisionDecision.Smoke/ContinuousCheckTests.cs b/tests/VisionDecision.Smoke/ContinuousCheckTests.cs index 7316b1b..1e0ba12 100644 --- a/tests/VisionDecision.Smoke/ContinuousCheckTests.cs +++ b/tests/VisionDecision.Smoke/ContinuousCheckTests.cs @@ -45,6 +45,8 @@ internal static class ContinuousCheckTests Check(recovered?.FrameId == 3, "已经检查过较晚帧后,重试须能补查缓存中间帧,不能永远只检查更晚画面"); Check(InspectionFrameSelector.Select(source, new Dictionary { [3] = 3 }, [])?.FrameId == 6, "有新画面时应交替检查新结果,不能把全部次数都用于历史补查"); + Check(InspectionFrameSelector.Select(source, new Dictionary { [1] = 1, [3] = 3 }, [], preferLatest: true)?.FrameId == 6, + "窗口硬截止前必须优先检查最新未检结果,不能把最后机会用于较早帧"); coverage[3] = 3; Check(InspectionFrameSelector.Select(source, coverage, [])?.FrameId != 3, "已检查的历史帧不能重复消耗次数"); var client = new Client(); var engine = new SopEngine { VisionDecisionClient = client }; engine.Load(Config()); engine.Start();