diff --git a/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressController.cs b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressController.cs index 9ad1a5a..7bf651c 100644 --- a/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressController.cs +++ b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressController.cs @@ -131,12 +131,24 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor var systolicRefValue = bpRef?.Systolic;//? var diastolicRefValue = bpRef?.Diastolic;//? - + int duration = 30; // 获取历史数据 DateTime now = DateTime.Now; - DateTime startTime = now.AddDays(-30); + DateTime startTime = now.AddDays(-duration); DateTime endTime = now; + // + var systolicAggregate = await _serviceTDengine.GetAggregateValue("systolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}'"); + var diastolicAggregate = await _serviceTDengine.GetAggregateValue("diastolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}'"); + + // 最大值 + var systolicMax = systolicAggregate.Max; + var diastolicMax = diastolicAggregate.Max; + // 最小值 + var systolicMin = systolicAggregate.Min; + var diastolicMin = diastolicAggregate.Min; + + // 计算去除最大值和最小值和异常值的平均值 var systolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValue("systolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}' and systolic_value < {systolicRefValue} and diastolic_value >{diastolicRefValue}"); var diastolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValue("diastolic_value", "hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{bp.Serialno}' and systolic_value < {systolicRefValue} and diastolic_value >{diastolicRefValue}"); @@ -144,9 +156,13 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor // 偏移参数 var avgOffset = 0.25M; + var systolicAvgOffset = avgOffset; + var diastolicAvgOffset = avgOffset; + + // 增量值=(标定值-平均值)* 0.25 - var systolicInc = systolicAvg.Equals(0M) ? 0: (int)((systolicRefValue - systolicAvg)* avgOffset)!; - var diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)((diastolicRefValue - diastolicAvg) * avgOffset)!; + var systolicInc = systolicAvg.Equals(0M) ? 0: (int)((systolicRefValue - systolicAvg)* systolicAvgOffset)!; + var diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!; #endregion @@ -157,17 +173,28 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor $"'{bp.MessageId}'," + $"'{bp.Serialno}'," + $"{bp.SystolicValue}," + - $"{bp.DiastolicValue}," + - $"'{bp.LastUpdate:yyyy-MM-ddTHH:mm:ss.fffZ}'," + + $"{systolicRefValue}," + + $"{systolicAvg}," + + $"{systolicMax}," + + $"{systolicMin}," + + $"{systolicAvgOffset}," + $"{systolicInc}," + + $"{bp.DiastolicValue}," + + $"{diastolicRefValue}," + + $"{diastolicAvg}," + + $"{diastolicMax}," + + $"{diastolicMin}," + + $"{diastolicAvgOffset}," + $"{diastolicInc}," + - $"{avgOffset}," + $"{gender}," + $"{age}," + $"{height}," + - $"{weight}," + + $"{weight}," + + $"'{bp.LastUpdate:yyyy-MM-ddTHH:mm:ss.fffZ}'," + + $"{duration}," + $"'{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}'," + - $"'{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}')"; + $"'{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}'," + + $"'{string.Empty}')"; var res = await _serviceTDengine.GernalRestSql(sql); #endregion