From 2ed2b235a601728599f508e71696b8503ff05cfa Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Thu, 19 Nov 2026 02:06:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E6=A3=80=E6=9F=A5=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E7=A1=AC=E6=88=AA=E6=AD=A2=E5=89=8D=E4=BC=98=E5=85=88=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E6=9C=80=E6=96=B0=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sop/InspectionFrameSelector.cs | 3 ++- .../Sop/SopEngine.ContinuousChecks.cs | 4 +++- tests/VisionDecision.Smoke/ContinuousCheckTests.cs | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) 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();