From f6062820016bae11620f9483118b7a62e9c12910 Mon Sep 17 00:00:00 2001 From: H Vs Date: Wed, 30 Oct 2024 10:11:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BB=BA=E6=A8=A1=E6=98=AF?= =?UTF-8?q?=E7=9A=84=E9=9D=9E=E9=AB=98=E9=A2=91=E6=95=B0=E6=8D=AE=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Biz/db/TDengineService.cs | 151 ++++++++++++++---- 1 file changed, 124 insertions(+), 27 deletions(-) diff --git a/HealthMonitor.Service/Biz/db/TDengineService.cs b/HealthMonitor.Service/Biz/db/TDengineService.cs index 4fa8009..a7521c1 100644 --- a/HealthMonitor.Service/Biz/db/TDengineService.cs +++ b/HealthMonitor.Service/Biz/db/TDengineService.cs @@ -1021,35 +1021,10 @@ namespace HealthMonitor.Service.Biz.db .Where(i => i.SerialNumber.Equals(serialNo)) .Where(i => i.LastUpdate > daysAgo) .OrderByDescending(i => i.LastUpdate) - .ToArrayAsync(); + .ToListAsync(); // 去除高频数据 - var filteredCollection = new List(); - PregnancyHeartRateModel? previousItem = null; - - //foreach (var item in collection) - //{ - // if (previousItem == null || Math.Abs((previousItem.LastUpdate - item.LastUpdate).TotalSeconds) >= highFreqSampleInterval) - // { - // filteredCollection.Add(item); - // previousItem = item; - // } - //} - - - foreach (var item in collection) - { - if (previousItem!=null) - { - var timeDiff = (previousItem.LastUpdate - item.LastUpdate).TotalSeconds; - Console.WriteLine($"previousItem:{previousItem.PregnancyHeartRate} -- item:{previousItem.PregnancyHeartRate} timeDiff:{timeDiff}--highFreqSampleInterval:{highFreqSampleInterval}"); - if (timeDiff >= highFreqSampleInterval) - { - filteredCollection.Add(item); - } - } - previousItem = item; - } + var filteredCollection = GetNonFreqPregnancyHeartRate(collection, highFreqSampleInterval); // 心率数据量必须30个以上才进行计算 if (filteredCollection.Count < 30) @@ -1217,6 +1192,128 @@ namespace HealthMonitor.Service.Biz.db } + /// + /// 去除高频数据 + /// + /// + /// + /// + private static List GetNonFreqPregnancyHeartRate(List phr, int highFreqSampleInterval) + { + //phr = phr.OrderByDescending(i => i.LastUpdate).ToList(); + //var result = new List(); + //PregnancyHeartRateModel? previousItem = null; + + //foreach (var item in phr) + //{ + // if (previousItem != null) + // { + // var timeNextDiff =(previousItem!.LastUpdate - item.LastUpdate).TotalSeconds; + // if (timeNextDiff > highFreqSampleInterval) + // { + // result.Add(previousItem); + // } + // } + // previousItem = item; + //} + + //// 添加上一个 + //if (previousItem != null) + //{ + // result.Add(previousItem); + //} + + //return result; + + #region 反向 + var phr1 = phr.OrderByDescending(i => i.LastUpdate).ToList(); + var result = new List(); + PregnancyHeartRateModel? previousItem1 = null; + + foreach (var item in phr1) + { + if (previousItem1 != null) + { + var timeNextDiff = (previousItem1!.LastUpdate - item.LastUpdate).TotalSeconds; + if (timeNextDiff > highFreqSampleInterval) + { + result.Add(previousItem1); + } + } + previousItem1 = item; + } + + // 添加上一个 + if (previousItem1 != null) + { + result.Add(previousItem1); + } + #endregion + + #region 正向 + var phr2 = phr.OrderByDescending(i => i.LastUpdate).ToList(); ; + var freqCollection = new List(); + PregnancyHeartRateModel? previousItem = null; + foreach (var item in phr2) + { + if (previousItem != null) + { + var timeNextDiff = (previousItem!.LastUpdate - item.LastUpdate).TotalSeconds; + if (timeNextDiff <= highFreqSampleInterval) + { + freqCollection.Add(item); + } + } + previousItem = item; + } + //去除高频 + foreach (var item in freqCollection) + { + phr2.Remove(item); + } + #endregion + + // 交集 + var commonElements = phr2.Intersect(result).ToList(); + return commonElements; + } + + + /// + /// 获取高频数据 + /// + /// + /// + /// + private static List GetFreqPregnancyHeartRate(List phr, int highFreqSampleInterval) + { + phr = phr.OrderByDescending(i => i.LastUpdate).ToList(); + var freqCollection = new List(); + PregnancyHeartRateModel? previousItem = null; + + foreach (var item in phr) + { + if (previousItem != null) + { + var timeNextDiff = (previousItem.LastUpdate - item.LastUpdate).TotalSeconds; + if (timeNextDiff <= highFreqSampleInterval) + { + freqCollection.Add(previousItem); + } + } + previousItem = item; + } + + // 检查最后一条是否高频 + if (previousItem != null && (phr.Last().LastUpdate - previousItem.LastUpdate).TotalSeconds <= highFreqSampleInterval) + { + freqCollection.Add(previousItem); + } + + return freqCollection; + } + + /// /// 获取孕妇心率众数 ///