日常更新
This commit is contained in:
@@ -76,15 +76,27 @@ internal static class EctoolRunner
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>解析 temps 输出为摄氏温度。支持 "315 K (= 42 C)" 等格式,多传感器时取最高值。</summary>
|
/// <summary>解析 temps 输出为摄氏温度。支持 "329 K (= 56 C)" 等格式,多传感器时取最高值。排除 ratio 行中的 (313 K and 333 K) 等阈值。</summary>
|
||||||
public static float? TryParseTemp(string stdout)
|
public static float? TryParseTemp(string stdout)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(stdout))
|
if (string.IsNullOrWhiteSpace(stdout))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
float? best = null;
|
float? best = null;
|
||||||
// 匹配 "315 K" 或 "315 K (= 42 C)"
|
// 匹配 "= 56 C":最可靠,且不会被 ratio 行的 (313 K and 333 K) 干扰
|
||||||
foreach (Match m in Regex.Matches(stdout, @"(\d{2,3})\s*K\b", RegexOptions.IgnoreCase))
|
foreach (Match m in Regex.Matches(stdout, @"=\s*(\d{1,3})\s*[Cc]\b"))
|
||||||
|
{
|
||||||
|
if (int.TryParse(m.Groups[1].Value, out var c) && c is >= 0 and <= 120)
|
||||||
|
{
|
||||||
|
if (best == null || c > best)
|
||||||
|
best = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (best != null)
|
||||||
|
return best;
|
||||||
|
|
||||||
|
// 若无 "= X C",再匹配 "329 K",排除 ratio 中的 "313 K and" 与 "and 333 K"
|
||||||
|
foreach (Match m in Regex.Matches(stdout, @"(?<!and\s)(\d{2,3})\s*K\b(?!\s+and)", RegexOptions.IgnoreCase))
|
||||||
{
|
{
|
||||||
if (int.TryParse(m.Groups[1].Value, out var k) && k is >= 250 and <= 400)
|
if (int.TryParse(m.Groups[1].Value, out var k) && k is >= 250 and <= 400)
|
||||||
{
|
{
|
||||||
@@ -93,15 +105,6 @@ internal static class EctoolRunner
|
|||||||
best = c;
|
best = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 匹配 "= 42 C" 或 "42 C"
|
|
||||||
foreach (Match m in Regex.Matches(stdout, @"(?:=\s*)?(\d{1,3})\s*[Cc]\b"))
|
|
||||||
{
|
|
||||||
if (int.TryParse(m.Groups[1].Value, out var c) && c is >= 0 and <= 120)
|
|
||||||
{
|
|
||||||
if (best == null || c > best)
|
|
||||||
best = c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return best;
|
return best;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user