From 6ec01264d04a2e1935ab53f8f09a51fb369a596f Mon Sep 17 00:00:00 2001 From: H Vs Date: Sat, 2 Dec 2023 10:09:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=B8=8B=E5=8F=91=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=95=B0=E6=8D=AE=E6=A0=B7=E6=9C=AC=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HealthMonitor.WebApi/Worker.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/HealthMonitor.WebApi/Worker.cs b/HealthMonitor.WebApi/Worker.cs index 10c6860..4b74a09 100644 --- a/HealthMonitor.WebApi/Worker.cs +++ b/HealthMonitor.WebApi/Worker.cs @@ -231,12 +231,17 @@ namespace HealthMonitor.WebApi var hmBpResponse = await _serviceTDengine.ExecuteSelectRestResponseAsync("stb_hm_bloodpress", condition); var hmBpParser = JsonConvert.DeserializeObject>(hmBpResponse!); var hmBp = hmBpParser?.Select(); - if (hmBp?.ToList().Count < 2) + //if (hmBp?.ToList().Count < 2) + // 1. 判断数据样本数量 + if(hmBpParser!.Rows < 5) { - _logger.LogInformation($"{imeiDel} -- {nameof(Worker)} --{nameof(WatchEvents)} -- 统计定时下发,计算增量值的数据条目不足"); + _logger.LogInformation($"{imeiDel} -- {nameof(Worker)} --{nameof(WatchEvents)} -- 统计定时下发,计算增量值的数据条目不足:{hmBpParser!.Rows} < 5"); + _logger.LogInformation($"{imeiDel} -- {nameof(Worker)} --{nameof(WatchEvents)} 没有足够的数据样本,不会定时下发"); break; } + + // 最大值 systolicMax = (int)hmBpParser?.Select(i => i.SystolicValue).Max()!; diastolicMax = (int)hmBpParser?.Select(i => i.DiastolicValue).Max()!; @@ -246,6 +251,15 @@ namespace HealthMonitor.WebApi systolicAvg = (int)(hmBpParser?.AverageAfterRemovingOneMinMaxRef(i => i.SystolicValue, SafeType.SafeInt(systolicRefValue!)))!; diastolicAvg = (int)(hmBpParser?.AverageAfterRemovingOneMinMaxRef(i => i.DiastolicValue, SafeType.SafeInt(diastolicRefValue!)))!; + // 2. 判断能否计算增量值 + if (systolicAvg.Equals(0) || diastolicAvg.Equals(0)) + { + _logger.LogInformation($"{imeiDel}--{nameof(Worker)}--计算平均值" + + $"\n currentSystolicAvg:{systolicAvg} -- lastPushSystolicInc:{lastPushSystolicInc}" + + $"\n currentDiastolicInc:{diastolicAvg} -- lastPushDiastolicInc:{lastPushDiastolicInc}"); + _logger.LogInformation($"{imeiDel}--{nameof(Worker)} 没有足够的数据样本计算平均值,不会定时下发"); + break; + } // 增量值=(标定值-平均值)* 0.25 var currentSystolicInc = (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!;