1
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
namespace Evergreen.Health.Application.Health.Policies;
|
||||
|
||||
/// <summary>Demo 起点,可由用户手动修改,不是医学或人体工学判断。</summary>
|
||||
public static class BmiFirmnessPolicy
|
||||
{
|
||||
public static decimal? Calculate(decimal? heightCm, decimal? weightKg)
|
||||
{
|
||||
if (heightCm is null or <= 0 || weightKg is null or <= 0) return null;
|
||||
try
|
||||
{
|
||||
var height = heightCm.Value / 100m;
|
||||
return Math.Round(weightKg.Value / (height * height), 1);
|
||||
}
|
||||
catch (ArithmeticException) { return null; }
|
||||
}
|
||||
|
||||
public static string? Firmness(decimal? bmi) => bmi switch
|
||||
{
|
||||
< 18.5m => "很软", < 24m => "稍软", < 28m => "稍硬",
|
||||
< 32m => "很硬", >= 32m => "最硬", _ => null
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Evergreen.Health.Application.Health.Models;
|
||||
|
||||
namespace Evergreen.Health.Application.Health.Policies;
|
||||
|
||||
public sealed record RecommendedRoomRange(int Minimum, int Maximum)
|
||||
{
|
||||
public string Display => $"{Minimum}–{Maximum}℃";
|
||||
public static RecommendedRoomRange ForConstitution(string code) => code switch
|
||||
{
|
||||
"yang_deficient" => new(24, 26), "yin_deficient" or "damp_heat" => new(21, 24),
|
||||
"phlegm_damp" => new(22, 24), "blood_stasis" => new(23, 25), _ => new(22, 25)
|
||||
};
|
||||
}
|
||||
|
||||
public sealed record IndoorTemperatureSample(double? Celsius, DateTimeOffset? ObservedAt, bool Available, string Reason);
|
||||
|
||||
public static class RoomTemperaturePolicy
|
||||
{
|
||||
public static ClimateAdviceOutput Evaluate(IndoorTemperatureSample sample, RecommendedRoomRange range)
|
||||
{
|
||||
var mode = !sample.Available || sample.Celsius is null ? "unavailable"
|
||||
: sample.Celsius < range.Minimum ? "heat" : sample.Celsius > range.Maximum ? "cool" : "off";
|
||||
return new()
|
||||
{
|
||||
Mode = mode, RecommendedMinimumCelsius = range.Minimum, RecommendedMaximumCelsius = range.Maximum,
|
||||
Reason = mode switch
|
||||
{
|
||||
"heat" => $"室温低于建议 {range.Display}:床垫低档加热,建议空调制热",
|
||||
"cool" => $"室温高于建议 {range.Display}:床垫不加热,建议空调制冷",
|
||||
"off" => $"室温在建议 {range.Display} 内:床垫不加热,空调不开启",
|
||||
_ => $"{sample.Reason},不自动加热或开启空调"
|
||||
},
|
||||
PendingIntegration = mode is "heat" or "cool"
|
||||
};
|
||||
}
|
||||
|
||||
// 仅在启动新舒睡场景时调用,状态查询和预览不随机更改目标值。
|
||||
public static void PickTargetForSession(ClimateAdviceOutput advice)
|
||||
{
|
||||
if (advice.TargetTemperatureCelsius is null && (advice.Mode is "heat" or "cool"))
|
||||
advice.TargetTemperatureCelsius = Random.Shared.Next(advice.RecommendedMinimumCelsius,
|
||||
advice.RecommendedMaximumCelsius + 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user