From 023f0a8c5e568a4080f79a5b8bc8383223b62854 Mon Sep 17 00:00:00 2001 From: H Vs Date: Tue, 7 May 2024 11:46:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=A4=E6=9C=80=E5=A4=A7=E5=80=BC=E5=92=8C?= =?UTF-8?q?=E6=9C=80=E5=B0=8F=E5=80=BC=E5=90=8E=E7=9A=84=E5=B9=B3=E5=9D=87?= =?UTF-8?q?=E5=80=BC=E4=B8=8E=E6=A0=87=E5=AE=9A=E5=80=BC=E5=B7=AE=E5=80=BC?= =?UTF-8?q?=E5=B0=91=E4=BA=8E4=E5=90=8E=EF=BC=8C=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E5=A2=9E=E9=87=8F=E5=80=BC=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Biz/db/TDengineService.cs | 42 ++++++++++++++++++- ...dPressConfigManualCalibrationController.cs | 8 +++- HealthMonitor.WebApi/Worker.cs | 8 +++- 3 files changed, 54 insertions(+), 4 deletions(-) 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.Fail(502, $"平均值与标定值差值少于4,不调整增量值"); + } // 增量值=(标定值-平均值)* 0.25 var currentSystolicInc = (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!; diff --git a/HealthMonitor.WebApi/Worker.cs b/HealthMonitor.WebApi/Worker.cs index 3c59d66..57bcbed 100644 --- a/HealthMonitor.WebApi/Worker.cs +++ b/HealthMonitor.WebApi/Worker.cs @@ -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)!;