现场的需求的更改
This commit is contained in:
@@ -338,7 +338,7 @@ namespace CapMachine.Wpf.Services
|
||||
}
|
||||
else if (_superheatSubcoolCalculator.TryCalculateSuperheatK(InhPressTag.EngPvValue, InhTempTag.EngPvValue, out var superheatValue, out var superheatErr))
|
||||
{
|
||||
Superheat.EngPvValue =Math.Abs(superheatValue) ;
|
||||
Superheat.EngPvValue = Math.Abs(superheatValue);
|
||||
updated = true;
|
||||
}
|
||||
else
|
||||
@@ -651,11 +651,11 @@ namespace CapMachine.Wpf.Services
|
||||
COPCooling = result.COPCooling;
|
||||
IsentropicEfficiencyPct = result.IsentropicEfficiencyPct;
|
||||
|
||||
// 再把结果回写到对应工程量标签。
|
||||
HeatingCapacity.EngPvValue = HeatingCapacityQh_kW;
|
||||
// 再把结果回写到对应工程量标签
|
||||
HeatingCapacity.EngPvValue = HeatingCapacityQh_kW * 1000;
|
||||
COPHeat.EngPvValue = COPHeating;
|
||||
IsentrpEff.EngPvValue = IsentropicEfficiencyPct;
|
||||
CoolCapacity.EngPvValue = CoolingCapacityQc_kW;
|
||||
CoolCapacity.EngPvValue = CoolingCapacityQc_kW * 1000;
|
||||
COPCool.EngPvValue = COPCooling;
|
||||
|
||||
// 容积效率在旧逻辑中允许单独失败;
|
||||
@@ -756,21 +756,87 @@ namespace CapMachine.Wpf.Services
|
||||
{
|
||||
displacement_cc = double.NaN;
|
||||
error = string.Empty;
|
||||
const double defaultDisplacementCc = 35d;
|
||||
|
||||
displacement_cc = 35;
|
||||
if (TryGetCompressorDisplacementFromCurrentExperiment(out displacement_cc, out var experimentError))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (TryGetCompressorDisplacementFromConfig(out displacement_cc, out var configError))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
displacement_cc = defaultDisplacementCc;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从当前选中的实验信息中读取并解析压缩机排量。
|
||||
/// </summary>
|
||||
/// <param name="displacement_cc">排量输出,单位 cc。</param>
|
||||
/// <param name="error">失败原因。</param>
|
||||
/// <returns>是否读取成功。</returns>
|
||||
private bool TryGetCompressorDisplacementFromCurrentExperiment(out double displacement_cc, out string error)
|
||||
{
|
||||
displacement_cc = double.NaN;
|
||||
error = string.Empty;
|
||||
|
||||
if (ConfigService.CurExpInfo == null)
|
||||
{
|
||||
error = "当前未选择实验信息,无法从试验信息读取压缩机排量";
|
||||
return false;
|
||||
}
|
||||
|
||||
var displacementText = ConfigService.CurExpInfo.CapDisplacement;
|
||||
if (string.IsNullOrWhiteSpace(displacementText))
|
||||
{
|
||||
error = "当前试验信息未填写压缩机排量";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TryParseCompressorDisplacementText(displacementText, out displacement_cc))
|
||||
{
|
||||
error = $"当前试验信息压缩机排量无法解析: {displacementText}";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (displacement_cc <= 0)
|
||||
{
|
||||
error = $"当前试验信息压缩机排量<=0: {displacement_cc}";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从配置项读取并解析压缩机排量。
|
||||
/// </summary>
|
||||
/// <param name="displacement_cc">排量输出,单位 cc。</param>
|
||||
/// <param name="error">失败原因。</param>
|
||||
/// <returns>是否读取成功。</returns>
|
||||
private bool TryGetCompressorDisplacementFromConfig(out double displacement_cc, out string error)
|
||||
{
|
||||
displacement_cc = double.NaN;
|
||||
error = string.Empty;
|
||||
|
||||
const string key = "CompressorDisplacementCc";
|
||||
//if (!ConfigHelper.IsExist(key))
|
||||
//{
|
||||
// error = $"未配置压缩机排量,请在 App.config/appSettings 增加 {key}(单位 cc)";
|
||||
// return false;
|
||||
//}
|
||||
|
||||
string v = ConfigHelper.GetValue(key);
|
||||
if (!double.TryParse(v, out displacement_cc))
|
||||
string configValue;
|
||||
try
|
||||
{
|
||||
error = $"压缩机排量配置无法解析: {v}";
|
||||
configValue = ConfigHelper.GetValue(key);
|
||||
}
|
||||
catch
|
||||
{
|
||||
error = $"未配置压缩机排量,请在 App.config/appSettings 增加 {key}(单位 cc)";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TryParseCompressorDisplacementText(configValue, out displacement_cc))
|
||||
{
|
||||
error = $"压缩机排量配置无法解析: {configValue}";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -783,6 +849,42 @@ namespace CapMachine.Wpf.Services
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析排量文本为数值。
|
||||
/// 支持纯数字与包含单位的文本(如 34.5、34.5cc、34,5 cm3)。
|
||||
/// </summary>
|
||||
/// <param name="displacementText">排量文本。</param>
|
||||
/// <param name="displacementCc">解析后的排量数值,单位 cc。</param>
|
||||
/// <returns>是否解析成功。</returns>
|
||||
private static bool TryParseCompressorDisplacementText(string displacementText, out double displacementCc)
|
||||
{
|
||||
displacementCc = double.NaN;
|
||||
if (string.IsNullOrWhiteSpace(displacementText))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var normalizedText = displacementText.Trim();
|
||||
if (double.TryParse(normalizedText, out displacementCc))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (double.TryParse(normalizedText, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out displacementCc))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var match = System.Text.RegularExpressions.Regex.Match(normalizedText, @"[-+]?\d+(?:[\.,]\d+)?");
|
||||
if (!match.Success)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var numericText = match.Value.Replace(',', '.');
|
||||
return double.TryParse(numericText, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out displacementCc);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user