Browse Source

非高频的获取

master
H Vs 2 months ago
parent
commit
b0deca721f
2 changed files with 129 additions and 22 deletions
  1. +62
    -10
      HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs
  2. +67
    -12
      HealthMonitor.WebApi/Worker.cs

+ 62
- 10
HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs View File

@@ -893,30 +893,82 @@ namespace HealthMonitor.Service.Resolver
/// <returns></returns>
private static List<PregnancyHeartRateModel> GetNonFreqPregnancyHeartRate(List<PregnancyHeartRateModel> phr,int highFreqSampleInterval)
{
phr = phr.OrderByDescending(i => i.LastUpdate).ToList();
//phr = phr.OrderByDescending(i => i.LastUpdate).ToList();
//var result = new List<PregnancyHeartRateModel>();
//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>();
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>();
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;
}

/// <summary>


+ 67
- 12
HealthMonitor.WebApi/Worker.cs View File

@@ -1933,32 +1933,85 @@ namespace HealthMonitor.WebApi
/// <returns></returns>
private static List<PregnancyHeartRateModel> GetNonFreqPregnancyHeartRate(List<PregnancyHeartRateModel> phr, int highFreqSampleInterval)
{
phr = phr.OrderByDescending(i => i.LastUpdate).ToList();
//phr = phr.OrderByDescending(i => i.LastUpdate).ToList();
//var result = new List<PregnancyHeartRateModel>();
//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>();
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>();
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;
}


/// <summary>
/// 获取高频数据
/// </summary>
@@ -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;



Loading…
Cancel
Save