From 70a86d8097e9d67c1e8e2cb52a0f329d3bb41183 Mon Sep 17 00:00:00 2001 From: H Vs Date: Wed, 22 Nov 2023 18:04:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=89=8B=E5=8A=A8=E6=A0=A1?= =?UTF-8?q?=E6=AD=A3B.2.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...dPressConfigManualCalibrationController.cs | 64 ++++++++++++++----- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs index 2215dc9..dba6a87 100644 --- a/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs +++ b/HealthMonitor.WebApi/Controllers/HealthMonitor/HmBloodPressConfigManualCalibrationController.cs @@ -140,6 +140,12 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor int diastolicInc; int systolicAvg; int diastolicAvg; + + // 偏移参数 + var avgOffset = 0.25M; + var systolicAvgOffset = avgOffset; + var diastolicAvgOffset = avgOffset; + //int duration = 7; long duration = 7 * 24 * 3600 * 1000; TimeSpan ts = TimeSpan.FromMilliseconds(duration); @@ -188,10 +194,10 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor // 数据正常 else { - // 偏移参数 - var avgOffset = 0.25M; - var systolicAvgOffset = avgOffset; - var diastolicAvgOffset = avgOffset; + //// 偏移参数 + //var avgOffset = 0.25M; + //var systolicAvgOffset = avgOffset; + //var diastolicAvgOffset = avgOffset; // 增量值=(标定值-平均值)* 0.25 @@ -243,10 +249,10 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor // 数据正常 else { - // 偏移参数 - var avgOffset = 0.25M; - var systolicAvgOffset = avgOffset; - var diastolicAvgOffset = avgOffset; + //// 偏移参数 + //var avgOffset = 0.25M; + //var systolicAvgOffset = avgOffset; + //var diastolicAvgOffset = avgOffset; // 增量值=(标定值-平均值)* 0.25 systolicInc = systolicAvg.Equals(0M) ? 0 : (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!; diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!; @@ -265,26 +271,52 @@ namespace HealthMonitor.WebApi.Controllers.HealthMonitor endTime = DateTime.Now; startTime = newTs; + // 最大值,最小值 + var systolicAggregate = await _serviceTDengine.GetAggregateValueAsync("systolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{imei}'"); + var diastolicAggregate = await _serviceTDengine.GetAggregateValueAsync("diastolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{imei}'"); + // 平均值: 计算去除最大值 MAX和最小值 MIN 和异常值 ABN 的平均值 systolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("systolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{imei}' and systolic_value < {systolicRefValue} "); diastolicAvg = await _serviceTDengine.GetAvgExceptMaxMinValueAsync("diastolic_value", "stb_hm_bloodpress", $"ts>='{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and ts <='{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}' and serialno='{imei}' and diastolic_value < {diastolicRefValue}"); + // 偏移参数 + //var avgOffset = 0.25M; + //var systolicAvgOffset = avgOffset; + //var diastolicAvgOffset = avgOffset; + + + // 增量值=(标定值-平均值)* 0.25 + //systolicInc = systolicAvg.Equals(0M) ? 0 : (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!; + //diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!; + + systolicInc = (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!; + diastolicInc = (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!; // B.2.1 数据异常,将按最后一次测量值的offeset下发 if (systolicAvg.Equals(0) || diastolicAvg.Equals(0)) { - _logger.LogInformation("B.2.1 曾经下推过断言有测量记录,数据异常,平均值为0,增量值将按0下发"); - return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, 0, 0).ConfigureAwait(false); + _logger.LogInformation("B.2.1 曾经下推过断言有测量记录,数据异常,平均值为0"); + _logger.LogInformation($"{imei}本次计算结果\n{startTime:yyyy-MM-ddTHH:mm:ss.fffZ}--{endTime:yyyy-MM-ddTHH:mm:ss.fffZ}" + + $"\n systolic:REF:{systolicRefValue} - Inc:{systolicInc} - AVG:{systolicAvg} - MAX:{systolicAggregate.Max} - MIN: {systolicAggregate.Min} " + + $"\n diastolic:REF:{diastolicRefValue} - Inc:{diastolicInc} - AVG:{diastolicAvg} - MAX:{diastolicAggregate.Max} - MIN: {diastolicAggregate.Min}"); + _logger.LogInformation($"上次下发的增量值:systolic:{(int)lastPush![4]}--diastolic:{(int)lastPush![5]}"); + + if (systolicAvg.Equals(0)) + { + systolicInc = (int)lastPush[4]; + } + + if (diastolicAvg.Equals(0)) + { + diastolicInc = (int)lastPush[5]; + } + + return await IotSetBloodPressCalibrationConfigResponseAsync(model.Imei, systolicRefValue, diastolicRefValue, systolicInc, diastolicInc).ConfigureAwait(false); } // B.2.2 数据正常,按正常计算 else { - // 偏移参数 - var avgOffset = 0.25M; - var systolicAvgOffset = avgOffset; - var diastolicAvgOffset = avgOffset; - - + // 增量值=(标定值-平均值)* 0.25 systolicInc = systolicAvg.Equals(0M) ? 0 : (int)((systolicRefValue - systolicAvg) * systolicAvgOffset)!; diastolicInc = diastolicAvg.Equals(0M) ? 0 : (int)((diastolicRefValue - diastolicAvg) * diastolicAvgOffset)!;