diff --git a/HealthMonitor.Service/Biz/db/TDengineService.cs b/HealthMonitor.Service/Biz/db/TDengineService.cs
index 2b080d9..bfc7062 100644
--- a/HealthMonitor.Service/Biz/db/TDengineService.cs
+++ b/HealthMonitor.Service/Biz/db/TDengineService.cs
@@ -522,12 +522,12 @@ namespace HealthMonitor.Service.Biz.db
}
///
- ///
+ /// 去除最大值和最小值各一个(列表的头和尾),再去除异常值
///
///
///
///
- public decimal[] AverageAfterRemovingOneMinMaxRef(int systolicRefValue, ParseTDengineRestResponse? hmBpParser)
+ public decimal[] AverageAfterRemovingOneMinMaxRef(int systolicRefValue, ParseTDengineRestResponse? 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! };
}
+
+ ///
+ /// 去除最大值和最小值各一个(列表的头和尾)
+ ///
+ ///
+ ///
+ ///
+ public decimal[] AverageAfterRemovingOneMinMaxRef(ParseTDengineRestResponse? 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! };
+ }
}
}
diff --git a/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs
index 52b721d..485ef1c 100644
--- a/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs
+++ b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs
@@ -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