From 0acfdd92cc9d86f6497cd607ba92dcd4f74fc3a7 Mon Sep 17 00:00:00 2001 From: tfarcraw <123211521@163.com> Date: Fri, 20 Nov 2026 09:30:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E4=B8=BB=E7=95=8C=E9=9D=A2=E8=AE=A1?= =?UTF-8?q?=E6=97=B6=E5=92=8C=E8=80=97=E6=97=B6=E6=98=BE=E7=A4=BA=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E7=B2=BE=E7=A1=AE=E5=88=B0=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VVMs/SopPage/SopPageViewModel.cs | 10 ++--- tests/Avalonia.Smoke/Program.cs | 39 ++++++++++++++++--- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/SopHelper.Avalonia/VVMs/SopPage/SopPageViewModel.cs b/src/SopHelper.Avalonia/VVMs/SopPage/SopPageViewModel.cs index 148a9ad..b7f454f 100644 --- a/src/SopHelper.Avalonia/VVMs/SopPage/SopPageViewModel.cs +++ b/src/SopHelper.Avalonia/VVMs/SopPage/SopPageViewModel.cs @@ -48,14 +48,14 @@ public class SopPageViewModel : ViewModelBase private readonly Dispatcher _dispatcher; private readonly DispatcherTimer _statisticsTimer; private long _completedCount; - private string _flowElapsedText = "00:00:00.0", _stepElapsedText = "00:00:00.0"; - private string _standardDurationText = "00:00:00.0", _averageDurationText = "00:00:00.0"; + private string _flowElapsedText = "00:00:00", _stepElapsedText = "00:00:00"; + private string _standardDurationText = "00:00:00", _averageDurationText = "00:00:00"; public long CompletedCount { get => _completedCount; private set => SetProperty(ref _completedCount, value); } public string FlowElapsedText { get => _flowElapsedText; private set => SetProperty(ref _flowElapsedText, value); } public string StepElapsedText { get => _stepElapsedText; private set => SetProperty(ref _stepElapsedText, value); } public string StandardDurationText { get => _standardDurationText; private set => SetProperty(ref _standardDurationText, value); } public string AverageDurationText { get => _averageDurationText; private set => SetProperty(ref _averageDurationText, value); } - public static string FormatDuration(TimeSpan duration) => $"{(long)duration.TotalHours:00}:{duration.Minutes:00}:{duration.Seconds:00}.{duration.Milliseconds / 100}"; + public static string FormatDuration(TimeSpan duration) => $"{(long)duration.TotalHours:00}:{duration.Minutes:00}:{duration.Seconds:00}"; private int _renderQueued; @@ -941,7 +941,7 @@ public class SopPageViewModel : ViewModelBase // 每帧均更新,无检测结果时清除上一帧的手部标记和目标框。 HandResult = result; - InferenceText = $"{result.InferenceMs:F1} ms"; + InferenceText = $"{(long)(result.InferenceMs / 1000)} 秒"; } /// @@ -1079,7 +1079,7 @@ public class SopPageViewModel : ViewModelBase /// public class StepCard : ViewModelBase { - private string _elapsedText = "00:00:00.0"; + private string _elapsedText = "00:00:00"; public string ElapsedText { get => _elapsedText; set => SetProperty(ref _elapsedText, value); } public bool SaveCompletionImage { get; init; } = true; public string CompletionImageDirectory { get; init; } = ""; diff --git a/tests/Avalonia.Smoke/Program.cs b/tests/Avalonia.Smoke/Program.cs index 13d8b52..bbd16c9 100644 --- a/tests/Avalonia.Smoke/Program.cs +++ b/tests/Avalonia.Smoke/Program.cs @@ -87,6 +87,33 @@ internal static class Smoke var userCameraBefore=File.Exists(userCameraPath)?File.ReadAllBytes(userCameraPath):null; await Task.Delay(150); var app=(App)Application.Current!;var window=lifetime.MainWindow!; + if(Environment.GetCommandLineArgs().Contains("--time-display-only")) + { + foreach(var (duration,expected) in new[]{(TimeSpan.Zero,"00:00:00"),(TimeSpan.FromMilliseconds(999),"00:00:00"), + (TimeSpan.FromMilliseconds(1999),"00:00:01"),(TimeSpan.FromMilliseconds(60001),"00:01:00"), + (TimeSpan.FromHours(25)+TimeSpan.FromMilliseconds(1250),"25:00:01")}) + Check(SopPageViewModel.FormatDuration(duration)==expected,"Elapsed time drops fractional seconds: "+duration); + var model=app.Container.Resolve(); + var engine=app.Container.Resolve(); + var name=Path.GetFileNameWithoutExtension(model.SelectedRecipe)!; + SopStandardVideoDuration.Remember(new RecipeWorkspace(Environment.GetEnvironmentVariable("SOPHELPER_WORKSPACE_ROOT")!).DirectoryFor(name),TimeSpan.FromSeconds(3.25)); + var statistics=engine.GetStatistics(name);statistics.StartRound();await Task.Delay(1150);statistics.Pause();await Task.Delay(120); + Check(model.FlowElapsedText=="00:00:01"&&model.StepElapsedText=="00:00:01" + &&model.StandardDurationText=="00:00:03"&&model.AverageDurationText=="00:00:00","Main statistics render whole seconds"); + Check(new StepCard().ElapsedText=="00:00:00","New step cards start with whole seconds"); + model.StepCards.Clear();model.StepCards.Add(new(){StepId=1,Name="计时步骤",SaveCompletionImage=false}); + typeof(SopPageViewModel).GetMethod("UpdateCard",System.Reflection.BindingFlags.NonPublic|System.Reflection.BindingFlags.Instance)! + .Invoke(model,[new SopHelper.Engine.Sop.StepSnapshot{StepId=1,Elapsed=TimeSpan.FromMilliseconds(1999)}]); + Check(model.StepCards[0].ElapsedText=="00:00:01","Step snapshots render whole seconds"); + model.IsRunning=true; + using(var frame=new Mat(48,64,MatType.CV_8UC3,new Scalar(30,60,90))) + typeof(SopPageViewModel).GetMethod("OnResultFrame",System.Reflection.BindingFlags.NonPublic|System.Reflection.BindingFlags.Instance)! + .Invoke(model,[new SopHelper.Engine.Common.FrameResult{Size=(64,48),InferenceMs=1999},frame]); + await Task.Delay(80); + Check(model.InferenceText=="1 秒","Inference duration uses whole seconds"); + model.IsRunning=false; + _exit=0;return; + } if(Environment.GetCommandLineArgs().Contains("--sidebar-layout-only")) { var model=app.Container.Resolve(); @@ -636,8 +663,8 @@ internal static class Smoke } try { - await Task.Delay(150); - Check(sop.FlowElapsedText!="00:00:00.0"&&sop.StepElapsedText!="00:00:00.0","Flow and step displays advance live without requiring a completion"); + await Task.Delay(1150); + Check(sop.FlowElapsedText!="00:00:00"&&sop.StepElapsedText!="00:00:00","Flow and step displays advance live without requiring a completion"); engine.TogglePause();await Task.Delay(120);var paused=sop.FlowElapsedText;await Task.Delay(150); Check(sop.FlowElapsedText==paused,"Runtime timer display remains frozen during pause");engine.TogglePause(); for(var round=1;round<=11;round++) @@ -645,16 +672,16 @@ internal static class Smoke if(round>1)engine.Reset(); await Task.Delay(120);await Emit();await Task.Delay(120);await Emit();await Task.Delay(110); Check(sop.CompletedCount==round,"Runtime count updates once after a complete flow"); - Check(round<=10?sop.AverageDurationText=="00:00:00.0":sop.AverageDurationText!="00:00:00.0","Average display starts only after the eleventh completion"); + Check(sop.AverageDurationText==SopPageViewModel.FormatDuration(engine.Statistics.AverageDuration),"Average display starts only after the eleventh completion"); } - Check(sop.StandardDurationText=="00:00:03.2","Runtime displays the remembered standard SOP video duration"); - Check(sop.StepCards.All(c=>c.ElapsedText!="00:00:00.0"),"Completed step cards retain their individual elapsed times"); + Check(sop.StandardDurationText=="00:00:03","Runtime displays the remembered standard SOP video duration"); + Check(sop.StepCards.All(c=>System.Text.RegularExpressions.Regex.IsMatch(c.ElapsedText,@"^\d{2,}:\d{2}:\d{2}$")),"Completed step cards display elapsed times to whole seconds"); var panel=window.GetVisualDescendants().OfType().Single(c=>c.Name=="RunStatisticsPanel"); var texts=panel.GetVisualDescendants().OfType().Select(t=>t.Text).ToArray(); Check(texts.Contains("完成次数")&&texts.Contains("流程计时")&&texts.Contains("步骤计时")&&texts.Contains("标准用时")&&texts.Contains("平均用时")&&texts.Contains("11"),"Operator page renders all five statistics and their bound values"); Save(window,"runtime-statistics"); engine.Reset();await Task.Delay(120); - Check(sop.CompletedCount==11&&sop.StepCards.All(c=>c.ElapsedText=="00:00:00.0"||c.StepId==1),"Reset begins new step timing while preserving completed count and history"); + Check(sop.CompletedCount==11&&sop.StepCards.All(c=>c.ElapsedText=="00:00:00"||c.StepId==1),"Reset begins new step timing while preserving completed count and history"); } finally{sop.IsRunning=false;sop.ApplyRecipeCommand.Execute();} }