From f4f29955f06c7f190cd079b1569b3ac11abe18ef Mon Sep 17 00:00:00 2001 From: H Vs Date: Mon, 19 Aug 2024 11:00:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B8=B8=E8=A7=84=E5=BF=83=E7=8E=87=E8=AE=A1?= =?UTF-8?q?=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Resolver/PregnancyHeartRateResolver.cs | 69 +++++++++++-------- HealthMonitor.WebApi/Worker.cs | 5 ++ 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs b/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs index 1988d5a..23a7936 100644 --- a/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs +++ b/HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs @@ -169,7 +169,7 @@ namespace HealthMonitor.Service.Resolver // EDOC var edoc = DateTimeUtil.ToDateTime(watchConfig!["EDOC"]!.ToString()); // interval (分钟) 固定15分钟 - //var intervalFHR = 15;//int)watchConfig["interval"]!; + var intervalFHR = 15;//int)watchConfig["interval"]!; @@ -242,11 +242,14 @@ namespace HealthMonitor.Service.Resolver _logger.LogInformation($"{heartRate.Serialno} 进入高频心率启动状态 timeDiffInSeconds {timeDiffInSeconds},highFreqSampleInterval:{highFreqSampleInterval}"); // 设置高频状态 _logger.LogInformation($"{heartRate.Serialno} phr.Count {phr.Count}"); - var freqFirstPhr = phr.OrderByDescending(i => i.LastUpdate).First(); + var freqFirstPhr = phr.OrderByDescending(i => i.LastUpdate) + .Skip(1) + .First(); await _deviceCacheMgr.SetPregnancyHeartRateFreqStatusAsync(heartRate.Serialno, freqFirstPhr); _logger.LogInformation($"{heartRate.Serialno} 设置高频状态"); phrFreqstatus = await _deviceCacheMgr.GetPregnancyHeartRateFreqStatusAsync(heartRate.Serialno); } + /// phr PregnancyHeartRate 连续连续正常次数个值都是正常(大于等于triggerHighFreqLow,少于等于triggerHighFreqHig), /// 取连续正常次数正常值的平均值,推送到api/v1/open/OpenIot/SetFetalHeartRateConfig #region 检查高频状态是否连续12个心率值都是正常的 @@ -387,21 +390,22 @@ namespace HealthMonitor.Service.Resolver var phrFlashBack = daysPhr.Where(p => p.LastUpdate >= phrFreqstatus!.LastUpdate) .OrderByDescending(i => i.LastUpdate); // 取得高频数据 - var freqCollection = new List(); - PregnancyHeartRateModel? previousItem = null; - - foreach (var item in phrFlashBack) - { - if (previousItem != null) - { - var timeNextDiff = (previousItem!.LastUpdate - item.LastUpdate).TotalSeconds; - if (timeNextDiff <= highFreqSampleInterval) - { - freqCollection.Add(item); - } - } - previousItem = item; - } + var freqCollection = phrFlashBack.ToList(); + //var freqCollection = new List(); + //PregnancyHeartRateModel? previousItem = null; + + //foreach (var item in phrFlashBack) + //{ + // if (previousItem != null) + // { + // var timeNextDiff = (previousItem!.LastUpdate - item.LastUpdate).TotalSeconds; + // if (timeNextDiff <= highFreqSampleInterval) + // { + // freqCollection.Add(item); + // } + // } + // previousItem = item; + //} _logger.LogInformation($"{heartRate.Serialno} 高频数据个数{freqCollection.Count},触发高频开始时间{phrFreqstatus!.LastUpdate}"); if (freqCollection.Count>=stopHighFreqSampleCount) @@ -436,21 +440,21 @@ namespace HealthMonitor.Service.Resolver _logger.LogInformation($"{heartRate.Serialno} 超时结束高频心率状态 timeDiffInSeconds {timeDiffInSeconds},highFreqSampleInterval:{highFreqSampleInterval},高频状态持续{(firstTwoPhr[1] - phrFreqstatus!.LastUpdate).TotalSeconds} 秒"); // 计算本次常规心率的胎心数据 - //await CalculateNormalFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, intervalFHR, commonPHR); - // 使用延后计算 - var fhrScheduleKey = $"health_monitor/schedule_push/cal_fetal_heart_rate/imei/{heartRate.Serialno}"; - var fhrScheduleTTL = 60; - await SetIntervalTriggerAsync(fhrScheduleKey, heartRate.Serialno, fhrScheduleTTL, heartRate); + await CalculateNormalFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, intervalFHR, commonPHR); + //// 使用延后计算 + //var fhrScheduleKey = $"health_monitor/schedule_push/cal_fetal_heart_rate/imei/{heartRate.Serialno}"; + //var fhrScheduleTTL = 60; + //await SetIntervalTriggerAsync(fhrScheduleKey, heartRate.Serialno, fhrScheduleTTL, heartRate); } // 常规心率 else { // 计算本次常规心率的胎心数据 - //await CalculateNormalFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, intervalFHR, commonPHR); + await CalculateNormalFetalHeartRateAsync(heartRate, upperAlarmThreshold, lowerAlarmThreshold, intervalFHR, commonPHR); // 使用延后计算 - var fhrScheduleKey = $"health_monitor/schedule_push/cal_fetal_heart_rate/imei/{heartRate.Serialno}"; - var fhrScheduleTTL = 60; - await SetIntervalTriggerAsync(fhrScheduleKey, heartRate.Serialno, fhrScheduleTTL, heartRate); + //var fhrScheduleKey = $"health_monitor/schedule_push/cal_fetal_heart_rate/imei/{heartRate.Serialno}"; + //var fhrScheduleTTL = 60; + //await SetIntervalTriggerAsync(fhrScheduleKey, heartRate.Serialno, fhrScheduleTTL, heartRate); } } @@ -485,7 +489,10 @@ namespace HealthMonitor.Service.Resolver // 上15分钟的数据 // 获取当前时间 DateTime nowInterval = (DateTime)heartRate.LastUpdate!; - + if (nowInterval.Second > 0) + { + nowInterval = nowInterval.AddMinutes(1); + } // 计算last_update到上一间隔的分钟数 int minutesToSubtract = nowInterval.Minute % intervalFHR; @@ -596,7 +603,13 @@ namespace HealthMonitor.Service.Resolver await _hisFetalHeartApiClient.AddAsync(gpsFetalHeartRate).ConfigureAwait(false); // 推送到api/v1/open/OpenIot/SetFetalHeartRateConfig - await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal); + // 推送最后一条常规心率计算的胎心数据到iot设备 + var lastPhr = await _serviceTDengine.GetLastAsync(heartRate.Serialno); + if (lastPhr.MessageId == heartRate.MessageId && phrFreqstatus == null) + { + await _serviceIotApi.SetFetalHeartRateConfig(heartRate.Serialno, fetalHeartRate, sampleTime, isAbnormal); + _logger.LogInformation($"{heartRate.Serialno} 推送最后一条常规心率计算的胎心数据到iot设备"); + } var device = await _deviceCacheMgr.GetDeviceBySerialNoAsync(heartRate.Serialno).ConfigureAwait(false); diff --git a/HealthMonitor.WebApi/Worker.cs b/HealthMonitor.WebApi/Worker.cs index 6c2fb22..f98d8d7 100644 --- a/HealthMonitor.WebApi/Worker.cs +++ b/HealthMonitor.WebApi/Worker.cs @@ -266,6 +266,7 @@ namespace HealthMonitor.WebApi // health_monitor/schedule_push/cal_fetal_heart_rate/imei/ else if (key.Contains("health_monitor/schedule_push/cal_fetal_heart_rate/imei/")) { + /** var triggerValue= (JObject)JsonConvert.DeserializeObject(e.PrevKv.Value.ToStringUtf8())!; var trigger = triggerValue["trigger"]?.ToString(); if (!string.IsNullOrEmpty(trigger)) @@ -405,6 +406,10 @@ namespace HealthMonitor.WebApi { _logger.LogWarning($"{imeiDel} trigger is not set"); } + + */ + + } //health_monitor/schedule_push/cal_fetal_movement/imei/ else if (key.Contains("health_monitor/schedule_push/cal_fetal_movement/imei/"))