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; + } + + /// /// 获取孕妇心率众数 ///