From b0deca721f923ae36cd5da29d18751d6e6b83673 Mon Sep 17 00:00:00 2001 From: H Vs Date: Fri, 30 Aug 2024 16:14:03 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=9E=E9=AB=98=E9=A2=91=E7=9A=84=E8=8E=B7?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Resolver/PregnancyHeartRateResolver.cs | 72 ++++++++++++++--- HealthMonitor.WebApi/Worker.cs | 79 ++++++++++++++++--- 2 files changed, 129 insertions(+), 22 deletions(-) diff --git a/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs b/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs index 474645e..d38c424 100644 --- a/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs +++ b/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs @@ -893,30 +893,82 @@ namespace HealthMonitor.Service.Resolver /// private static List GetNonFreqPregnancyHeartRate(List phr,int highFreqSampleInterval) { - phr = phr.OrderByDescending(i => i.LastUpdate).ToList(); + //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? previousItem = null; + PregnancyHeartRateModel? previousItem1 = null; - foreach (var item in phr) + foreach (var item in phr1) { - if (previousItem != null) + if (previousItem1 != null) { - var timeNextDiff =(previousItem!.LastUpdate - item.LastUpdate).TotalSeconds; + var timeNextDiff = (previousItem1!.LastUpdate - item.LastUpdate).TotalSeconds; if (timeNextDiff > highFreqSampleInterval) { - result.Add(previousItem); + result.Add(previousItem1); } } - previousItem = item; + previousItem1 = item; } // 添加上一个 - if (previousItem != null) + if (previousItem1 != null) { - result.Add(previousItem); + 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 - return result; + // 交集 + var commonElements = phr2.Intersect(result).ToList(); + return commonElements; } /// diff --git a/HealthMonitor.WebApi/Worker.cs b/HealthMonitor.WebApi/Worker.cs index e71ce35..e301d3b 100644 --- a/HealthMonitor.WebApi/Worker.cs +++ b/HealthMonitor.WebApi/Worker.cs @@ -1933,32 +1933,85 @@ namespace HealthMonitor.WebApi /// private static List GetNonFreqPregnancyHeartRate(List phr, int highFreqSampleInterval) { - phr = phr.OrderByDescending(i => i.LastUpdate).ToList(); + //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? previousItem = null; + PregnancyHeartRateModel? previousItem1 = null; - foreach (var item in phr) + foreach (var item in phr1) { - if (previousItem != null) + if (previousItem1 != null) { - var timeNextDiff = (previousItem!.LastUpdate - item.LastUpdate).TotalSeconds; + var timeNextDiff = (previousItem1!.LastUpdate - item.LastUpdate).TotalSeconds; if (timeNextDiff > highFreqSampleInterval) { - result.Add(previousItem); + result.Add(previousItem1); } } - previousItem = item; + previousItem1 = item; } // 添加上一个 - if (previousItem != null) + if (previousItem1 != null) { - result.Add(previousItem); + result.Add(previousItem1); } + #endregion - return result; + #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; } + /// /// 获取高频数据 /// @@ -2022,12 +2075,12 @@ namespace HealthMonitor.WebApi var statStartTime = segmentStatStartTime; var statEndTime = segmentStatEndTime; - _logger.LogInformation($"{heartRate.Serialno} 当前统计周期{statStartTime.ToString("yyyy-MM-dd HH:mm:ss")}-{statEndTime.ToString("yyyy-MM-dd HH:mm:ss")}"); + //_logger.LogInformation($"{heartRate.Serialno} 当前统计周期{statStartTime.ToString("yyyy-MM-dd HH:mm:ss")}-{statEndTime.ToString("yyyy-MM-dd HH:mm:ss")}"); var segmentPhr = normalPhr .Where(i => i.LastUpdate <= statEndTime && i.LastUpdate >= statStartTime) .ToList(); - + if (segmentPhr.Count == 0) { // 跳出当次迭代,进入下次迭代 @@ -2035,6 +2088,8 @@ namespace HealthMonitor.WebApi continue; } + _logger.LogInformation($"{heartRate.Serialno} 当前统计周期{statStartTime.ToString("yyyy-MM-dd HH:mm:ss")}-{statEndTime.ToString("yyyy-MM-dd HH:mm:ss")},对应的常规心率ID{string.Join(",", segmentPhr.Select(i=>i.MessageId))}"); + var sampleTime = DateTimeUtil.ConvertToTimeStamp(segmentStatStartTime).ToString(); sampleTime = sampleTime.Length > 10 ? sampleTime.Substring(0, 10) : sampleTime;