From c807a846864787c8e0e65a20087cea17a9dc7ef2 Mon Sep 17 00:00:00 2001 From: H Vs Date: Mon, 27 Nov 2023 16:28:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Person=20Remarks=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Biz/db/TDengineService.cs | 42 +++++++++++++++++++ .../Resolver/BloodpressResolver.cs | 11 +++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/HealthMonitor.Service/Biz/db/TDengineService.cs b/HealthMonitor.Service/Biz/db/TDengineService.cs index 5d31d2a..940d835 100644 --- a/HealthMonitor.Service/Biz/db/TDengineService.cs +++ b/HealthMonitor.Service/Biz/db/TDengineService.cs @@ -2,6 +2,7 @@ using HealthMonitor.Common.helper; using HealthMonitor.Model.Config; using HealthMonitor.Service.Biz.db.Dto; +using HealthMonitor.Util.Models; using Microsoft.EntityFrameworkCore.Metadata.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -472,5 +473,46 @@ namespace HealthMonitor.Service.Biz.db } #endregion + /// + /// 平均值算法(去除最大值,最小值和大于标定值的平均值) + /// + /// + /// + /// + /// + /// + public static decimal AverageAfterRemovingOneMinMaxRef(List collection, int max, int min,int refValue) + { + collection.Remove(max); + collection.Remove(min); + collection.RemoveAll(_ => _ > refValue); + if (collection.Count < 2) + { + throw new ArgumentException($"数据集{collection.ToArray()},去掉一个最大值 {max}和一个最小值{min},异常值(大于标定值{refValue}),后数据值不足"); + } + + return (decimal)collection.Average(x => x); + //var values = ParseData.Select(valueSelector).ToList(); + //collection = values.Select(i => (int)i).ToArray(); + //if (values.Count <= 2) + //{ + // throw new ArgumentException("Not enough elements to remove."); + //} + + //// Remove the specified number of minimum and maximum values + ////values.RemoveAll(_ => _ == values.Min()); + ////values.RemoveAll(_ => _ == values.Max()); + //max = (int)values.Max(); + //min = (int)values.Min(); + //values.Remove(max); + //values.Remove(min); + + //// Remove values less than the specified threshold + //values.RemoveAll(_ => _ > numToRemove); + + //// Calculate and return the average of the remaining values + //return values.Average(); + } + } } diff --git a/HealthMonitor.Service/Resolver/BloodpressResolver.cs b/HealthMonitor.Service/Resolver/BloodpressResolver.cs index dae6329..2ed5474 100644 --- a/HealthMonitor.Service/Resolver/BloodpressResolver.cs +++ b/HealthMonitor.Service/Resolver/BloodpressResolver.cs @@ -26,6 +26,7 @@ using HealthMonitor.Model.Service; using Microsoft.Extensions.Options; using HealthMonitor.Model.Config; using HealthMonitor.Model.Service.Mapper; +using Mvccpb; namespace HealthMonitor.Service.Resolver { @@ -157,7 +158,7 @@ namespace HealthMonitor.Service.Resolver systolicRefValue = bpRef!.Systolic;//? diastolicRefValue = bpRef!.Diastolic;//? #endregion - + _logger.LogInformation($"Person Remarks 值:{person?.Person.Remarks}"); if (string.IsNullOrWhiteSpace(person?.Person.Remarks)) { #region 初始化计算增量值(个人血压信息) @@ -172,7 +173,7 @@ namespace HealthMonitor.Service.Resolver remarkFlag = await _serviceIotWebApi.UpdatePersonRemarksAsync(bp.Serialno, (int)systolicRefValue!, (int)diastolicRefValue!, systolicInc, diastolicInc).ConfigureAwait(false); if (remarkFlag) { - Console.WriteLine($"{nameof(BloodpressResolver)} 开启血压标定值下发: {_configBoodPressResolver.EnableBPRefPush}"); + _logger.LogInformation($"{nameof(BloodpressResolver)} 开启血压标定值下发: {_configBoodPressResolver.EnableBPRefPush}"); // 启血压标定值下发开关 if (_configBoodPressResolver.EnableBPRefPush) { @@ -277,7 +278,11 @@ namespace HealthMonitor.Service.Resolver var hmBpResponse = await _serviceTDengine.ExecuteSelectRestResponseAsync("stb_hm_bloodpress", condition); var hmBpParser = JsonConvert.DeserializeObject>(hmBpResponse!); var hmBp = hmBpParser?.Select(); - + if (hmBp?.ToList().Count < 2) + { + _logger.LogInformation($"{bp.Serialno} 数据值不足"); + return; + } // 最大值 systolicMax = (int)hmBpParser?.Select(i => i.SystolicValue).Max()!; diastolicMax = (int)hmBpParser?.Select(i => i.DiastolicValue).Max()!;