Quellcode durchsuchen

调整GetSampleTimeFromLastUpdate精度算法

datasub12_fetal_heart_rate_1
H Vs vor 1 Monat
Ursprung
Commit
311798b71a
1 geänderte Dateien mit 23 neuen und 11 gelöschten Zeilen
  1. +23
    -11
      HealthMonitor.WebApi/Worker.cs

+ 23
- 11
HealthMonitor.WebApi/Worker.cs Datei anzeigen

@@ -2633,20 +2633,32 @@ namespace HealthMonitor.WebApi
//} //}
} }


private DateTime GetSampleTimeFromLastUpdate(DateTime lastUpdate,int interval)
//private DateTime GetSampleTimeFromLastUpdate(DateTime lastUpdate,int interval)
//{
// DateTime nowInterval = lastUpdate;
// //if (nowInterval.Second > 0)
// //{
// // nowInterval = nowInterval.AddMinutes(1);
// //}
// // 计算last_update到上一间隔的分钟数
// int minutesToSubtract = nowInterval.Minute % interval;

// // 计算上一间隔的时间
// DateTime previousInterval = nowInterval.AddMinutes(-minutesToSubtract).AddSeconds(-nowInterval.Second).AddMilliseconds(-nowInterval.Millisecond);

// return previousInterval;
//}

public static DateTime GetSampleTimeFromLastUpdate(DateTime lastUpdate, int interval)
{ {
DateTime nowInterval = lastUpdate;
//if (nowInterval.Second > 0)
//{
// nowInterval = nowInterval.AddMinutes(1);
//}
// 计算last_update到上一间隔的分钟数
int minutesToSubtract = nowInterval.Minute % interval;
// 获取当前的分钟
int minute = lastUpdate.Minute;


// 计算上一间隔的时间
DateTime previousInterval = nowInterval.AddMinutes(-minutesToSubtract).AddSeconds(-nowInterval.Second).AddMilliseconds(-nowInterval.Millisecond);
// 按 15 分钟为单位划分时间段
int intervalStartMinute = (minute / interval) * interval;


return previousInterval;
// 返回当前时间刻度下的 DateTime,保留小时和新计算的分钟,秒和毫秒设为0
return new DateTime(lastUpdate.Year, lastUpdate.Month, lastUpdate.Day, lastUpdate.Hour, intervalStartMinute, 0, 0);
} }
} }
} }

Laden…
Abbrechen
Speichern