瀏覽代碼

胎动处理改为一个小时计算一次

datasub12_fetal_heart_rate_1
H Vs 1 月之前
父節點
當前提交
3d695dcbe7
共有 3 個文件被更改,包括 447 次插入795 次删除
  1. +17
    -0
      HealthMonitor.Common/DateTimeUtil.cs
  2. +42
    -29
      HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs
  3. +388
    -766
      HealthMonitor.WebApi/Worker.cs

+ 17
- 0
HealthMonitor.Common/DateTimeUtil.cs 查看文件

@@ -722,6 +722,23 @@ namespace HealthMonitor.Common
return timeDifference.TotalSeconds;
}

/// <summary>
/// 时间转换逻辑
/// 当前时间是的0~1小时返回2小时 ,当前时间是的1 ~2小时返回3小时 ,如此类推,当前时间是的21 ~22小时返回23小时 ,当前时间是的23 ~0小时返回次日1小时
/// </summary>
/// <param name="currentHour">当前消息</param>
/// <returns></returns>
public static int GetNextHour(int currentHour)
{
// 处理 23 点特殊情况
if (currentHour == 23)
{
return 1; // 23点到0点时,返回次日1小时
}

// 计算其他时间的返回值
return (currentHour / 2 + 1) * 2;
}

///// <summary>
///// 是否为日期型字符串


+ 42
- 29
HealthMonitor.Service/Resolver/PregnancyHeartRateResolver.cs 查看文件

@@ -183,36 +183,8 @@ namespace HealthMonitor.Service.Resolver
var nonFreqPhr = GetNonFreqPregnancyHeartRate(phr, highFreqSampleInterval);
if (nonFreqPhr.Count >= 30)
{
#region 定时计算胎动数据触发器两小时间隔开始

/**
var fetalMovementKey = $"health_monitor/schedule_push/cal_fetal_movement/imei/{heartRate.Serialno}";
///// 计算 0 点秒数
var fetalMovementLastUpdate = (DateTime)heartRate.LastUpdate!;
DateTime fmScheduleNow = DateTime.Now;
// 小于两小时
if (fmScheduleNow > fetalMovementLastUpdate && (fmScheduleNow - fetalMovementLastUpdate).TotalHours <= 2)
{
var rand = new Random();
var pushSec = rand.Next(59);
int pushMin = int.TryParse(heartRate.Serialno.AsSpan(heartRate.Serialno.Length - 1), out pushMin) ? pushMin : 10;

var scheduleHourDiff = SCHEDULE_HOUR
.Where(h => h > fetalMovementLastUpdate.Hour)
.OrderBy(h => h - fetalMovementLastUpdate.Hour)
.FirstOrDefault() - fetalMovementLastUpdate.Hour;
var scheduleTime = fetalMovementLastUpdate.AddHours(scheduleHourDiff);

DateTime nextRunTime = new(scheduleTime.Year, scheduleTime.Month, scheduleTime.Day, scheduleTime.Hour, pushMin, pushSec);
TimeSpan timeUntilNextRun = nextRunTime - fmScheduleNow;
var ttl = (long)timeUntilNextRun.TotalSeconds;

await SetIntervalTriggerAsync(fetalMovementKey, heartRate.Serialno, ttl, heartRate);
}
*/
#endregion

#region 定时计算胎动数据触发器两小时间隔开始(奇数小时计算)
/**
var fetalMovementKey = $"health_monitor/schedule_push/cal_fetal_movement/imei/{heartRate.Serialno}";
var rand = new Random();
var pushSec = rand.Next(59);
@@ -254,9 +226,50 @@ namespace HealthMonitor.Service.Resolver

await SetIntervalTriggerAsync(fetalMovementKey, heartRate.Serialno, ttl, heartRate);
_logger.LogInformation($"{heartRate.Serialno}-{heartRate.MessageId} 创建计划统计胎动时间{scheduledDateTime.ToString("yyyy-MM-dd HH:mm:ss")}");
*/
#endregion


#region 定时计算胎动数据触发器每小时间隔开始,延时一个小时计算
///当前时间是的0~1小时返回2小时 ,
///当前时间是的1~2小时返回3小时 ,如此类推,
///当前时间是的21~22小时返回23小时
///当前时间是的23~0小时返回次日1小时

var fetalMovementKey = $"health_monitor/schedule_push/cal_fetal_movement/imei/{heartRate.Serialno}";
var rand = new Random();
var pushSec = rand.Next(59);
int pushMin = int.TryParse(heartRate.Serialno.AsSpan(heartRate.Serialno.Length - 1), out pushMin) ? pushMin : 10;

DateTime fmScheduleNow = DateTime.Now;
int hour = fmScheduleNow.Hour;
int selectedScheduleHour=DateTimeUtil.GetNextHour(fmScheduleNow.Hour);



DateTime scheduledDateTime = new DateTime(
fmScheduleNow.Year,
fmScheduleNow.Month,
fmScheduleNow.Day,
selectedScheduleHour,
pushMin,
pushSec
);

// 跨天
if (selectedScheduleHour == 1)
{
scheduledDateTime = scheduledDateTime.AddDays(1);
}

TimeSpan timeUntilNextRun = scheduledDateTime - fmScheduleNow;
var ttl = (long)timeUntilNextRun.TotalSeconds;

await SetIntervalTriggerAsync(fetalMovementKey, heartRate.Serialno, ttl, heartRate);
_logger.LogInformation($"{heartRate.Serialno}-{heartRate.MessageId} 创建计划统计胎动时间{scheduledDateTime.ToString("yyyy-MM-dd HH:mm:ss")}");

#endregion


#region 计算胎心数据(按心率时间LastUpdate)
var commonPHR = await _serviceTDengine.GetLastAsync<PregnancyCommonHeartRateModel>(heartRate.Serialno);


+ 388
- 766
HealthMonitor.WebApi/Worker.cs
文件差異過大導致無法顯示
查看文件


Loading…
取消
儲存