65 lines
2.6 KiB
C#
65 lines
2.6 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace Common
|
|||
|
|
{
|
|||
|
|
public static class PrecisionRuleHelper
|
|||
|
|
{
|
|||
|
|
// 液体加量对应的精度规则,key为加量区间下限(包含),value为精度计算方式
|
|||
|
|
public static Dictionary<double, Func<double, double>> LiquidPrecisionRules = new Dictionary<double, Func<double, double>>
|
|||
|
|
{
|
|||
|
|
{1, (target) => target * 0.015}, // 1~5ml 对应 ±1.5%,这里简单示例返回目标值*0.015作为精度值(实际可根据需求调整存储和计算)
|
|||
|
|
{0.2, (target) => target * 0.02}, // 0.2~1ml 对应 ±1%-2%,这里简单取2%示例
|
|||
|
|
{0.02, (target) => target * 0.02} // 0.02~0.2ml 对应 ±1%-2%,这里简单取2%示例
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 粉末加量对应的精度规则,key为加量区间下限(包含),value为精度计算方式
|
|||
|
|
public static Dictionary<double, Func<double, double>> PowderPrecisionRules = new Dictionary<double, Func<double, double>>
|
|||
|
|
{
|
|||
|
|
{5, (target) => target * 0.01}, // 5~10g 对应 ±1%
|
|||
|
|
{1, (target) => target * 0.015}, // 1~5g 对应 ±1.5%
|
|||
|
|
{0.1, (target) => target * 0.02}, // 0.1~1g 对应 ±1%-2%,这里简单取2%示例
|
|||
|
|
{0.05, (target) => target * 0.02}, // 0.05~0.1g 对应不低于±2%
|
|||
|
|
{0.005, (target) => 0.00025} // 0.005~0.05g 对应±0.25mg
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 获取液体加量对应的精度值
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="targetAmount">液体目标加量</param>
|
|||
|
|
/// <returns>计算后的精度值</returns>
|
|||
|
|
public static double GetLiquidPrecision(double targetAmount)
|
|||
|
|
{
|
|||
|
|
foreach (var rule in LiquidPrecisionRules)
|
|||
|
|
{
|
|||
|
|
if (targetAmount >= rule.Key)
|
|||
|
|
{
|
|||
|
|
return rule.Value(targetAmount);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return 1; // 默认精度,可根据实际需求调整
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 获取粉末加量对应的精度值
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="targetAmount">粉末目标加量</param>
|
|||
|
|
/// <returns>计算后的精度值</returns>
|
|||
|
|
public static double GetPowderPrecision(double targetAmount)
|
|||
|
|
{
|
|||
|
|
foreach (var rule in PowderPrecisionRules)
|
|||
|
|
{
|
|||
|
|
if (targetAmount >= rule.Key)
|
|||
|
|
{
|
|||
|
|
return rule.Value(targetAmount);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return 1; // 默认精度,可根据实际需求调整
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|