|
...
|
...
|
@@ -19,6 +19,7 @@ import '../health_raw_models.dart'; |
|
|
|
import '../health_raw_stress_calculator.dart';
|
|
|
|
import '../health_sleep_calculator.dart';
|
|
|
|
import '../platform_ios/apple_health_raw_data_core_service.dart';
|
|
|
|
import 'ohos_health_raw_data_sync_service.dart';
|
|
|
|
|
|
|
|
class OHOSHealthRawDataCoreService {
|
|
|
|
static const int defaultLookbackDays = 183;
|
|
...
|
...
|
@@ -226,10 +227,14 @@ class OHOSHealthRawDataCoreService { |
|
|
|
if (effectiveEndTime < requestedStartTime) {
|
|
|
|
throw ArgumentError.value(endTime, 'endTime');
|
|
|
|
}
|
|
|
|
await _syncCalculationRawDataIfNeeded(
|
|
|
|
final syncResults = await _syncCalculationRawDataIfNeeded(
|
|
|
|
startTime: requestedStartTime,
|
|
|
|
endTime: effectiveEndTime,
|
|
|
|
);
|
|
|
|
_logInfo(
|
|
|
|
'calculate_sync_finish startTime=$requestedStartTime '
|
|
|
|
'endTime=$effectiveEndTime syncResults=$syncResults',
|
|
|
|
);
|
|
|
|
|
|
|
|
final hrvContextStart = await _localStore.latestHrvSourceStartTime(userId);
|
|
|
|
final realtimeContextStart =
|
|
...
|
...
|
@@ -258,6 +263,17 @@ class OHOSHealthRawDataCoreService { |
|
|
|
: latestSleepResultTime - Duration.secondsPerDay,
|
|
|
|
earliestStartTime,
|
|
|
|
);
|
|
|
|
_logInfo(
|
|
|
|
'calculate_context userId=$userId '
|
|
|
|
'requestedStartTime=$requestedStartTime endTime=$effectiveEndTime '
|
|
|
|
'hrvContextStart=$hrvContextStart '
|
|
|
|
'realtimeContextStart=$realtimeContextStart '
|
|
|
|
'latestHrvRawEndTime=$latestHrvRawEndTime '
|
|
|
|
'latestRealtimeRawEndTime=$latestRealtimeRawEndTime '
|
|
|
|
'latestSleepResultTime=$latestSleepResultTime '
|
|
|
|
'hrvStartTime=$hrvStartTime heartRateStartTime=$heartRateStartTime '
|
|
|
|
'sleepStartTime=$sleepStartTime',
|
|
|
|
);
|
|
|
|
|
|
|
|
final hrvPoints = await _fetchRawDataInChunks(
|
|
|
|
HealthDataUploadType.hrv.type,
|
|
...
|
...
|
@@ -287,6 +303,13 @@ class OHOSHealthRawDataCoreService { |
|
|
|
effectiveEndTime,
|
|
|
|
readChunkDays: readChunkDays,
|
|
|
|
);
|
|
|
|
_logInfo(
|
|
|
|
'calculate_raw_counts userId=$userId '
|
|
|
|
'hrv=${hrvPoints.length} heartRate=${heartRatePoints.length} '
|
|
|
|
'restingHeartRate=${restingHeartRatePoints.length} '
|
|
|
|
'sleepIntervals=${sleepIntervals.length} '
|
|
|
|
'workoutIntervals=${workoutIntervals.length}',
|
|
|
|
);
|
|
|
|
|
|
|
|
final result = await Isolate.run(
|
|
|
|
() => HealthRawStressCalculator(userId: userId).calculate(
|
|
...
|
...
|
@@ -300,6 +323,11 @@ class OHOSHealthRawDataCoreService { |
|
|
|
),
|
|
|
|
debugName: 'OHOSHealthRawStressCalculator',
|
|
|
|
);
|
|
|
|
_logInfo(
|
|
|
|
'calculate_result_counts userId=$userId '
|
|
|
|
'hrv=${result.hrvStressPoints.length} '
|
|
|
|
'realtime=${result.realtimeStressPoints.length}',
|
|
|
|
);
|
|
|
|
final newResult = result.copyWith(
|
|
|
|
hrvStressPoints: _filterNewHrvStressPoints(
|
|
|
|
result.hrvStressPoints,
|
|
...
|
...
|
@@ -310,7 +338,17 @@ class OHOSHealthRawDataCoreService { |
|
|
|
latestRealtimeRawEndTime,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
_logInfo(
|
|
|
|
'calculate_new_result_counts userId=$userId '
|
|
|
|
'hrv=${newResult.hrvStressPoints.length} '
|
|
|
|
'realtime=${newResult.realtimeStressPoints.length}',
|
|
|
|
);
|
|
|
|
await _localStore.upsertResult(newResult);
|
|
|
|
_logInfo(
|
|
|
|
'calculate_result_stored userId=$userId '
|
|
|
|
'hrv=${newResult.hrvStressPoints.length} '
|
|
|
|
'realtime=${newResult.realtimeStressPoints.length}',
|
|
|
|
);
|
|
|
|
|
|
|
|
final dailyStressPoints = await _calculateAndStoreDailyStressPoints(
|
|
|
|
userId: userId,
|
|
...
|
...
|
@@ -322,6 +360,10 @@ class OHOSHealthRawDataCoreService { |
|
|
|
sleepIntervals: sleepIntervals,
|
|
|
|
latestSleepResultTime: latestSleepResultTime,
|
|
|
|
);
|
|
|
|
_logInfo(
|
|
|
|
'calculate_daily_sleep_stored userId=$userId '
|
|
|
|
'daily=${dailyStressPoints.length} sleep=${sleepResults.length}',
|
|
|
|
);
|
|
|
|
if (_uploadResultsAfterCalculation) {
|
|
|
|
await _uploadResults();
|
|
|
|
}
|
|
...
|
...
|
@@ -511,13 +553,15 @@ class OHOSHealthRawDataCoreService { |
|
|
|
if (_serverHealthApi == null) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _syncCalculationRawDataIfNeeded({
|
|
|
|
Future<List<OhosHealthRawDataSyncResult>> _syncCalculationRawDataIfNeeded({
|
|
|
|
required int startTime,
|
|
|
|
required int endTime,
|
|
|
|
}) async {
|
|
|
|
final rawDataSource = _rawDataSource;
|
|
|
|
if (rawDataSource is! OhosHealthRawDataSource) return;
|
|
|
|
await rawDataSource.syncCalculationRawData(
|
|
|
|
if (rawDataSource is! OhosHealthRawDataSource) {
|
|
|
|
return const <OhosHealthRawDataSyncResult>[];
|
|
|
|
}
|
|
|
|
return rawDataSource.syncCalculationRawData(
|
|
|
|
startTime: startTime,
|
|
|
|
endTime: endTime,
|
|
|
|
);
|
...
|
...
|
|