Переглянути джерело

优化建模是的非高频数据过滤数据

datasub12_fetal_heart_rate_1
H Vs 3 тижднів тому
джерело
коміт
f606282001
1 змінених файлів з 124 додано та 27 видалено
  1. +124
    -27
      HealthMonitor.Service/Biz/db/TDengineService.cs

+ 124
- 27
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>();
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
}


/// <summary>
/// 去除高频数据
/// </summary>
/// <param name="phr"></param>
/// <param name="highFreqSampleInterva"></param>
/// <returns></returns>
private static List<PregnancyHeartRateModel> GetNonFreqPregnancyHeartRate(List<PregnancyHeartRateModel> phr, int highFreqSampleInterval)
{
//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? 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>();
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>
/// <param name="phr"></param>
/// <param name="highFreqSampleInterval"></param>
/// <returns></returns>
private static List<PregnancyHeartRateModel> GetFreqPregnancyHeartRate(List<PregnancyHeartRateModel> phr, int highFreqSampleInterval)
{
phr = phr.OrderByDescending(i => i.LastUpdate).ToList();
var freqCollection = new List<PregnancyHeartRateModel>();
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;
}


/// <summary>
/// 获取孕妇心率众数
/// </summary>


Завантаження…
Відмінити
Зберегти