feat: numeric tighten

master
Tongg 3 months ago
parent b9e5279f49
commit 02e9d9460f
  1. 6
      App.config
  2. 2
      Language/zh_CN.xaml
  3. 30
      Model/Helper/NetworkSpeedHelper.cs
  4. 4
      ViewModel/Grading/GradingLoadingVM.cs
  5. 123
      ViewModel/Grading/GradingResultVM.cs
  6. 4
      Views/Dialog/MessageBoxHasCheck.xaml

@ -14,8 +14,10 @@
<add key="PrintName" value="Deli DL-720C"/>
<!-- 检测结果默认DS -->
<add key="DSSet" value="NA"/>
<!-- 检测预估耗时:毫秒 -->
<add key="ProgressTime" value="50000"/>
<!--网络质量检测周期 ms-->
<add key="InternetCheckCycle" value="300000" />
<!--网络质量检测阈值 Mbps-->
<add key="InternetCheckMbps" value="866" />
<add key="RunModel" value="0" />
<add key="AppVersion" value="Nlsqq/kAPIXFHKk9dFcfqw==" />

@ -246,7 +246,7 @@
<sys:String x:Key="CustomSettingPageFactory">工厂模式</sys:String>
<sys:String x:Key="CustomSettingPageLaboratory">实验室模式</sys:String>
<sys:String x:Key="NetworkSpeedCheckedText">取消检测</sys:String>
<sys:String x:Key="NetworkSpeedCheckedText">取消网络质量检测</sys:String>
<sys:String x:Key="NetworkSpeedCheckedMessage">当前网络传输效率低,可能影响检测效率!</sys:String>
</ResourceDictionary>

@ -1,3 +1,6 @@
using System.Diagnostics;
using System.Windows;
using System.Windows.Threading;
using log4net;
using SparkClient.Views.Dialog;
@ -8,7 +11,7 @@ public class NetworkSpeedHelper
private static readonly ILog Logger = LogManager.GetLogger(typeof(NetworkSpeedHelper));
private static int _cycle = 300000;
private static double _value = 866;
private static bool _ignore = false;
public static bool Ignore {
get => _ignore;
@ -26,7 +29,14 @@ public class NetworkSpeedHelper
public static void StartMonitoring()
{
Logger.Info($"周期网络检测开始,周期: {_cycle}");
var configCycle = ConfigurationHelper.ReadConfigValue("InternetCheckCycle");
var configMbps = ConfigurationHelper.ReadConfigValue("InternetCheckMbps");
_cycle = int.TryParse(configCycle, out int cycle)? cycle: 300000;
_value = double.TryParse(configMbps, out double valueMbps)? valueMbps: 866;
Logger.Info($"周期网络检测开始,周期: {_cycle};阈值:{_value}");
lock (_lock)
{
if (_monitorTimer == null)
@ -54,7 +64,7 @@ public class NetworkSpeedHelper
var speed = InternetSpeedDetection();
// 触发阈值报警
if (speed < 866)
if (speed < _value)
{
ShowSpeedAlert(speed);
}
@ -86,8 +96,18 @@ public class NetworkSpeedHelper
private static void ShowSpeedAlert(double speed)
{
var result = MessageBoxHasCheck.ShowMessageDialog() ;
NetworkSpeedHelper.Ignore = result;
Application.Current.Dispatcher.Invoke(() =>
{
try
{
var result = MessageBoxHasCheck.ShowMessageDialog();
NetworkSpeedHelper.Ignore = result;
}
catch (Exception ex)
{
Debug.WriteLine($"对话框操作异常: {ex.Message}");
}
}, DispatcherPriority.Normal);
}
private static double InternetSpeedDetection()

@ -484,8 +484,8 @@ public class GradingLoadingVM : BaseViewModel,IDisposable
[Log]
private async Task RunProgressAsync(CancellationToken token)
{
var configValue = ConfigurationHelper.ReadConfigValue("ProgressTime");
int totalDuration = int.TryParse(configValue, out var result) ? result : 50000;
// var configValue = ConfigurationHelper.ReadConfigValue("ProgressTime");
int totalDuration = 50000;
int stepTime = totalDuration / 97;
// 使用 IProgress 实现线程安全的进度报告

@ -742,7 +742,7 @@ public class GradingResultVM : BaseViewModel
DataInfo info = new DataInfo();
info.TestItemId = "TOTAL_DEPTH";
info.TestItemName = GetName("TOTAL_DEPTH");
info.Avg = FormatDouble_Avg(result.Measurements.TOTAL_DEPTH*100,Accuracy.ZD1);
info.Avg = FormatDouble_Avg(result.Measurements.TOTAL_DEPTH*100,Accuracy.ForceOneDecimal);
info.CutLevel = calGrade_TOTAL_DEPTH(result.Measurements.TOTAL_DEPTH);
info.isEnabled = false;
return info;
@ -754,7 +754,7 @@ public class GradingResultVM : BaseViewModel
DataInfo info = new DataInfo();
info.TestItemId = "TABLE";
info.TestItemName = GetName("TABLE");
info.Avg = FormatDouble_Avg(result.Measurements.TABLE*100, Accuracy.ZD5);
info.Avg = FormatDouble_Avg(result.Measurements.TABLE*100, Accuracy.IntegerFloor);
info.Min = FormatDouble_P(result.Measurements.TABLE_MIN);
info.Max = FormatDouble_P(result.Measurements.TABLE_MAX);
info.CutLevel = calGrade_TABLE(result.Measurements.TABLE_MIN, result.Measurements.TABLE_MAX);
@ -776,7 +776,7 @@ public class GradingResultVM : BaseViewModel
DataInfo info = new DataInfo();
info.TestItemId = "CROWN_ANGLE";
info.TestItemName = GetName("CROWN_ANGLE");
info.Avg = FormatDouble_Avg(result.Measurements.CROWN_ANGLE, Accuracy.ZD5);
info.Avg = FormatDouble_Avg(result.Measurements.CROWN_ANGLE, Accuracy.DecimalTwoStepRounding);
info.Dev = FormatDouble_A(result.Measurements.CROWN_ANGLE_DEV);
info.Min = FormatDouble_A(result.Measurements.CROWN_ANGLE_MIN);
info.Max = FormatDouble_A(result.Measurements.CROWN_ANGLE_MAX);
@ -804,7 +804,7 @@ public class GradingResultVM : BaseViewModel
DataInfo info = new DataInfo();
info.TestItemId = "CROWN_HEIGHT";
info.TestItemName = GetName("CROWN_HEIGHT");
info.Avg = FormatDouble_Avg(result.Measurements.CROWN_HEIGHT * 100, Accuracy.ZD5);
info.Avg = FormatDouble_Avg(result.Measurements.CROWN_HEIGHT * 100, Accuracy.HalfStepRounding);
info.Dev = FormatDouble_P(result.Measurements.CROWN_H_DEV);
info.Min = FormatDouble_P(result.Measurements.CROWN_H_MIN);
info.Max = FormatDouble_P(result.Measurements.CROWN_H_MAX);
@ -832,7 +832,7 @@ public class GradingResultVM : BaseViewModel
DataInfo info = new DataInfo();
info.TestItemId = "GIRDLE_BEZEL";
info.TestItemName = GetName("GIRDLE_BEZEL");
info.Avg = FormatDouble_Avg(result.Measurements.GIRDLE_BEZEL * 100, Accuracy.ZD1);
info.Avg = FormatDouble_Avg(result.Measurements.GIRDLE_BEZEL * 100, Accuracy.ForceOneDecimal);
info.Dev = FormatDouble_P(result.Measurements.GIRDLE_BEZEL_DEV);
info.Min = FormatDouble_P(result.Measurements.GIRDLE_BEZEL_MIN);
info.Max = FormatDouble_P(result.Measurements.GIRDLE_BEZEL_MAX);
@ -859,7 +859,7 @@ public class GradingResultVM : BaseViewModel
DataInfo info = new DataInfo();
info.TestItemId = "GIRDLE_BONE";
info.TestItemName = GetName("GIRDLE_BONE");
info.Avg = FormatDouble_Avg(result.Measurements.GIRDLE_BONE * 100, Accuracy.ZD1);
info.Avg = FormatDouble_Avg(result.Measurements.GIRDLE_BONE * 100, Accuracy.ForceOneDecimal);
info.Min = FormatDouble_P(result.Measurements.GIRDLE_BONE_MIN);
info.Max = FormatDouble_P(result.Measurements.GIRDLE_BONE_MAX);
info.isEnabled = false;
@ -886,7 +886,7 @@ public class GradingResultVM : BaseViewModel
DataInfo info = new DataInfo();
info.TestItemId = "GIRDLE";
info.TestItemName = GetName("GIRDLE");
info.Avg = FormatDouble_Avg(result.Measurements.GIRDLE_VALLEY * 100, Accuracy.ZD1);
info.Avg = FormatDouble_Avg(result.Measurements.GIRDLE_VALLEY * 100, Accuracy.HalfStepRounding);
info.Dev = FormatDouble_P(result.Measurements.GIRDLE_VALLEY_DEV);
info.Min = FormatDouble_P(result.Measurements.GIRDLE_VALLEY_MIN);
info.Max = FormatDouble_P(result.Measurements.GIRDLE_VALLEY_MAX);
@ -936,7 +936,7 @@ public class GradingResultVM : BaseViewModel
DataInfo info = new DataInfo();
info.TestItemId = "PAV_ANGLE";
info.TestItemName = GetName("PAV_ANGLE");
info.Avg = FormatDouble_Avg(result.Measurements.PAV_ANGLE, Accuracy.ZD1);
info.Avg = FormatDouble_Avg(result.Measurements.PAV_ANGLE, Accuracy.DecimalTwoStepRounding);
info.Dev = FormatDouble_A(result.Measurements.PAV_ANGLE_DEV);
info.Min = FormatDouble_A(result.Measurements.PAV_ANGLE_MIN);
info.Max = FormatDouble_A(result.Measurements.PAV_ANGLE_MAX);
@ -964,7 +964,7 @@ public class GradingResultVM : BaseViewModel
DataInfo info = new DataInfo();
info.TestItemId = "PAV_DEPTH";
info.TestItemName = GetName("PAV_DEPTH");
info.Avg = FormatDouble_Avg(result.Measurements.PAV_DEPTH*100, Accuracy.ZD5);
info.Avg = FormatDouble_Avg(result.Measurements.PAV_DEPTH*100, Accuracy.HalfStepRounding);
info.Dev = FormatDouble_P(result.Measurements.PAV_DEPTH_DEV);
info.Min = FormatDouble_P(result.Measurements.PAV_DEPTH_MIN);
info.Max = FormatDouble_P(result.Measurements.PAV_DEPTH_MAX);
@ -993,7 +993,7 @@ public class GradingResultVM : BaseViewModel
DataInfo info = new DataInfo();
info.TestItemId = "STAR";
info.TestItemName = GetName("STAR");
info.Avg = FormatDouble_Avg(result.Measurements.STAR*100, Accuracy.Z5);
info.Avg = FormatDouble_Avg(result.Measurements.STAR*100, Accuracy.MultipleOfFive);
info.Min = FormatDouble_P(result.Measurements.STAR_MIN);
info.Max = FormatDouble_P(result.Measurements.STAR_MAX);
info.CutLevel = calGrade_STAR(result.Measurements.STAR_MIN, result.Measurements.STAR_MAX);
@ -1019,7 +1019,7 @@ public class GradingResultVM : BaseViewModel
DataInfo info = new DataInfo();
info.TestItemId = "LOWER_HALVES_RATIO";
info.TestItemName = GetName("LOWER_HALVES_RATIO");
info.Avg = FormatDouble_Avg(result.Measurements.LOWER_HALVES_RATIO*100, Accuracy.Z5);
info.Avg = FormatDouble_Avg(result.Measurements.LOWER_HALVES_RATIO*100, Accuracy.MultipleOfFive);
info.Min = FormatDouble_P(result.Measurements.LOWER_HALVES_RATIO_MIN);
info.Max = FormatDouble_P(result.Measurements.LOWER_HALVES_RATIO_MAX);
info.CutLevel = calGrade_LOWER_HALVES_RATIO(result.Measurements.LOWER_HALVES_RATIO_MIN, result.Measurements.LOWER_HALVES_RATIO_MAX);
@ -1045,7 +1045,7 @@ public class GradingResultVM : BaseViewModel
DataInfo info = new DataInfo();
info.TestItemId = "CULET";
info.TestItemName = GetName("CULET");
info.Avg = FormatDouble_Avg(result.Measurements.CULET * 100, Accuracy.ZD1);
info.Avg = FormatDouble_Avg(result.Measurements.CULET * 100, Accuracy.ForceOneDecimal);
info.CutLevel = calGrade_CULET(result.Measurements.CULET);
info.isEnabled = false;
@ -1058,7 +1058,7 @@ public class GradingResultVM : BaseViewModel
DataInfo info = new DataInfo();
info.TestItemId = "TOC";
info.TestItemName = GetName("TOC");
info.Avg = FormatDouble_Avg(result.Measurements.TOC * 100, Accuracy.ZD1);
info.Avg = FormatDouble_Avg(result.Measurements.TOC * 100, Accuracy.ForceOneDecimal);
var data = result.Measurements;
info.SymLevel = calGradeSym(info.TestItemId, data.TOC * 100);
@ -1071,7 +1071,7 @@ public class GradingResultVM : BaseViewModel
DataInfo info = new DataInfo();
info.TestItemId = "COC";
info.TestItemName = GetName("COC");
info.Avg = FormatDouble_Avg(result.Measurements.COC*100, Accuracy.ZD1);
info.Avg = FormatDouble_Avg(result.Measurements.COC*100, Accuracy.ForceOneDecimal);
var data = result.Measurements;
info.SymLevel = calGradeSym(info.TestItemId, data.COC * 100);
return info;
@ -1084,7 +1084,7 @@ public class GradingResultVM : BaseViewModel
DataInfo info = new DataInfo();
info.TestItemId = "TWIST";
info.TestItemName = GetName("TWIST");
info.Avg = FormatDouble_Avg(result.Measurements.TWIST, Accuracy.ZD1);
info.Avg = FormatDouble_Avg(result.Measurements.TWIST, Accuracy.ForceOneDecimal);
info.Dev = FormatDouble_A(result.Measurements.TWIST_DEV);
info.Min = FormatDouble_A(result.Measurements.TWIST_MIN);
info.Max = FormatDouble_A(result.Measurements.TWIST_MAX);
@ -1111,7 +1111,7 @@ public class GradingResultVM : BaseViewModel
DataInfo info = new DataInfo();
info.TestItemId = "CULET_TO_TABLE";
info.TestItemName = GetName("CULET_TO_TABLE");
info.Avg = FormatDouble_Avg(result.Measurements.CULET_TO_TABLE*100,Accuracy.ZD1);
info.Avg = FormatDouble_Avg(result.Measurements.CULET_TO_TABLE*100,Accuracy.ForceOneDecimal);
var data = result.Measurements;
info.SymLevel = calGradeSym(info.TestItemId, data.CULET_TO_TABLE * 100);
return info;
@ -1654,21 +1654,52 @@ public class GradingResultVM : BaseViewModel
private string FormatDouble_Avg(double value, Accuracy accuracy)
{
string result = "";
switch (accuracy)
if (Common.RunMode == 0)
{
case Accuracy.ZDZ1:
result = (Math.Floor(value * 100) / 100).ToString("f2");
break;
case Accuracy.ZD1:
result = (Math.Floor(value * 10) / 10).ToString(digitsFormat);
break;
case Accuracy.ZD5:
result = (RoundFiveDownSixUp(value * 2) / 2).ToString("f1");
break;
case Accuracy.Z5:
result = (RoundFiveDownSixUp(value / 5) * 5).ToString();
break;
switch (accuracy)
{
case Accuracy.ForceTwoDecimals:
result = (Math.Floor(value * 100) / 100).ToString("f2");
break;
case Accuracy.ForceOneDecimal:
result = (Math.Floor(value * 10) / 10).ToString("f1");
break;
case Accuracy.HalfStepRounding:
result = (RoundFiveDownSixUp(value * 2) / 2).ToString("f1");
break;
case Accuracy.MultipleOfFive:
result = (RoundFiveDownSixUp(value / 5) * 5).ToString();
break;
case Accuracy.DecimalTwoStepRounding:
result = RoundToPointTwo(value).ToString("f1"); // 保留1位小数
break;
case Accuracy.IntegerFloor:
result = Math.Floor(value).ToString(); // 直接取整
break;
}
}
else
{
//工厂模式不量化
switch (accuracy)
{
case Accuracy.ForceTwoDecimals:
result = (Math.Floor(value * 100) / 100).ToString("f2");
break;
case Accuracy.HalfStepRounding:
case Accuracy.ForceOneDecimal:
case Accuracy.DecimalTwoStepRounding:
result = (Math.Floor(value * 10) / 10).ToString("f1");
break;
case Accuracy.IntegerFloor:
case Accuracy.MultipleOfFive:
result = Math.Floor(value).ToString(); // 直接取整
break;
}
}
return result;
}
[Log]
@ -1680,14 +1711,16 @@ public class GradingResultVM : BaseViewModel
double fractionalPart = value - integerPart;
// 判断小数部分是否大于 0.5
if (fractionalPart > 0.5)
{
return integerPart + 1; // 大于 0.5,进一
}
else
{
return integerPart; // 小于或等于 0.5,舍去
}
return fractionalPart > 0.5 ? integerPart + 1 : integerPart;
}
private static double RoundToPointTwo(double value)
{
// 转换到10倍精度空间处理
double scaled = value * 10;
double remainder = scaled % 2; // 求模得到余数
// 核心舍入规则:余数>=1.5时进位
return remainder >= 1.5 ? (scaled - remainder + 2) / 10 : (scaled - remainder) / 10;
}
/// <summary>
/// 直接值(角度,直径)用的小数格式化
@ -2866,8 +2899,16 @@ public enum SaveStatus
public enum Accuracy
{
ZDZ1 = 0,
ZD1 = 1,
ZD5 = 2,
Z5 = 3
[Description("强制保留两位小数,向下取整(ZDZ1)")]
ForceTwoDecimals,
[Description("强制保留一位小数,向下取整(ZD1)")]
ForceOneDecimal,
[Description("将数值舍入到最近的 0.5 倍数(ZD5)")]
HalfStepRounding,
[Description("将数值舍入到最近的 5 的整数倍(Z5)")]
MultipleOfFive,
[Description("将数值舍入到最近的0.2倍数(ZD2)")]
DecimalTwoStepRounding,
[Description("强制向下取整为整数(Floor)")]
IntegerFloor
}

@ -7,9 +7,11 @@
mc:Ignorable="d"
WindowStyle="None"
AllowsTransparency="True"
WindowStartupLocation="CenterScreen"
Topmost="True"
Background="Transparent"
ResizeMode="NoResize"
Title="MessageBox" Height="Auto" Width="600">
Title="MessageBox" Height="250" Width="600">
<Window.Resources>
<Style x:Key="CloseHoverImageStyle" TargetType="Image">
<Setter Property="Source" Value="pack://application:,,,/Resource/Images/UIResource/01-8.png"/>

Loading…
Cancel
Save