@@ -522,12 +522,12 @@ namespace HealthMonitor.Service.Biz.db | |||
} | |||
/// <summary> | |||
/// | |||
/// 去除最大值和最小值各一个(列表的头和尾),再去除异常值 | |||
/// </summary> | |||
/// <param name="systolicRefValue"></param> | |||
/// <param name="hmBpParser"></param> | |||
/// <returns></returns> | |||
public decimal[] AverageAfterRemovingOneMinMaxRef(int systolicRefValue, ParseTDengineRestResponse<BloodPressureModel>? hmBpParser) | |||
public decimal[] AverageAfterRemovingOneMinMaxRef(int systolicRefValue, ParseTDengineRestResponse<BloodPressureModel>? hmBpParser) | |||
{ | |||
var sortedList = hmBpParser?.Select(i => i) | |||
.Where(i => i.IsDisplay.Equals(true)) | |||
@@ -558,5 +558,43 @@ namespace HealthMonitor.Service.Biz.db | |||
return new decimal[] { (decimal)systolicAvg!, (decimal)diastolicAvg! }; | |||
} | |||
/// <summary> | |||
/// 去除最大值和最小值各一个(列表的头和尾) | |||
/// </summary> | |||
/// <param name="systolicRefValue"></param> | |||
/// <param name="hmBpParser"></param> | |||
/// <returns></returns> | |||
public decimal[] AverageAfterRemovingOneMinMaxRef(ParseTDengineRestResponse<BloodPressureModel>? hmBpParser) | |||
{ | |||
var sortedList = hmBpParser?.Select(i => i) | |||
.Where(i => i.IsDisplay.Equals(true)) | |||
.OrderByDescending(i => i.SystolicValue) | |||
.ThenByDescending(i => i.DiastolicValue) | |||
.ToList(); | |||
_logger.LogInformation($"计算时间段排列数据集:{JsonConvert.SerializeObject(sortedList)}"); | |||
// 去除最大值和最小值各一个(列表的头和尾) | |||
var trimmedList = sortedList? | |||
.Skip(1) | |||
.Take(sortedList.Count - 2) | |||
.ToList(); | |||
_logger.LogInformation($"计算去除最大值和最小值各一个数据集:{JsonConvert.SerializeObject(trimmedList)}"); | |||
var filteredList = trimmedList?.ToList(); | |||
_logger.LogInformation($"计算除异常值个数据集:{JsonConvert.SerializeObject(filteredList)}"); | |||
if (filteredList?.Count < 2) | |||
{ | |||
// throw new ArgumentException("数据不够不能计算"); | |||
// 平均值为0,说明数据不足,不能计算增量值 | |||
return new decimal[] { 0M, 0M }; | |||
} | |||
var systolicAvg = filteredList?.Select(bp => bp.SystolicValue).Average(); | |||
var diastolicAvg = filteredList?.Select(bp => bp.DiastolicValue).Average(); | |||
return new decimal[] { (decimal)systolicAvg!, (decimal)diastolicAvg! }; | |||
} | |||
} | |||
} |
@@ -192,7 +192,7 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor | |||
{ | |||
//systolicAvg = (int)(hmBpParser?.AverageAfterRemovingOneMinMaxRef(i => i.SystolicValue, SafeType.SafeInt(systolicRefValue!)))!; | |||
//diastolicAvg = (int)(hmBpParser?.AverageAfterRemovingOneMinMaxRef(i => i.DiastolicValue, SafeType.SafeInt(diastolicRefValue!)))!; | |||
var avgs = _serviceTDengine.AverageAfterRemovingOneMinMaxRef(SafeType.SafeInt(systolicRefValue!), hmBpParser!); | |||
var avgs = _serviceTDengine.AverageAfterRemovingOneMinMaxRef(hmBpParser!); | |||
systolicAvg = avgs[0]; | |||
diastolicAvg = avgs[1]; | |||
// 平均值为0,说明数据不足,不能计算增量值 | |||
@@ -219,6 +219,12 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor | |||
var statNow = DateTime.Now; | |||
return await IotSetBloodPressCalibrationConfigResponseAsync(imei, systolicRefValue, diastolicRefValue, 0, 0, 0, 0, 0, 0, statNow, statNow).ConfigureAwait(false); | |||
} | |||
// 除最大值和最小值后的平均值与标定值差值少于4后(当天计算出该结果则也不产生增量调整),就不再进行增量值调整了。 | |||
if (systolicAvg-systolicRefValue < 4) | |||
{ | |||
_logger.LogInformation($"除最大值和最小值后的平均值与标定值差值少于4后,不再进行增量值调整"); | |||
return ApiResponse<object>.Fail(502, $"平均值与标定值差值少于4,不调整增量值"); | |||
} | |||
// 增量值=(标定值-平均值)* 0.25 | |||
var currentSystolicInc = (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!; | |||
@@ -318,7 +318,7 @@ namespace HealthMonitor.WebApi | |||
//systolicAvg = (int)(hmBpParser?.AverageAfterRemovingOneMinMaxRef(i => i.SystolicValue, SafeType.SafeInt(systolicRefValue!)))!; | |||
//diastolicAvg = (int)(hmBpParser?.AverageAfterRemovingOneMinMaxRef(i => i.DiastolicValue, SafeType.SafeInt(diastolicRefValue!)))!; | |||
var avgs = _serviceTDengine.AverageAfterRemovingOneMinMaxRef(SafeType.SafeInt(systolicRefValue!), hmBpParser!); | |||
var avgs = _serviceTDengine.AverageAfterRemovingOneMinMaxRef(hmBpParser!); | |||
systolicAvg = avgs[0]; | |||
diastolicAvg = avgs[1]; | |||
@@ -332,6 +332,12 @@ namespace HealthMonitor.WebApi | |||
_logger.LogInformation($"{imeiDel}--{nameof(Worker)} 没有足够的数据样本计算平均值,不会定时下发"); | |||
break; | |||
} | |||
// 除最大值和最小值后的平均值与标定值差值少于4后(当天计算出该结果则也不产生增量调整),就不再进行增量值调整了。 | |||
if (systolicAvg-systolicRefValue < 4) | |||
{ | |||
_logger.LogInformation($"除最大值和最小值后的平均值与标定值差值少于4后,不再进行增量值调整"); | |||
break; | |||
} | |||
// 增量值=(标定值-平均值)* 0.25 | |||
var currentSystolicInc = (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!; | |||