Showing
1 changed file
with
18 additions
and
10 deletions
| 1 | import 'dart:async'; | 1 | import 'dart:async'; |
| 2 | import 'dart:io'; | 2 | import 'dart:io'; |
| 3 | import 'dart:developer' as developer; | 3 | import 'dart:developer' as developer; |
| 4 | +import 'dart:isolate'; | ||
| 4 | import 'dart:math' as math; | 5 | import 'dart:math' as math; |
| 5 | 6 | ||
| 6 | import 'package:flutter/foundation.dart'; | 7 | import 'package:flutter/foundation.dart'; |
| @@ -307,14 +308,20 @@ class HealthRawDataCoreService { | @@ -307,14 +308,20 @@ class HealthRawDataCoreService { | ||
| 307 | readChunkDays: readChunkDays, | 308 | readChunkDays: readChunkDays, |
| 308 | ); | 309 | ); |
| 309 | 310 | ||
| 310 | - final result = calculate( | ||
| 311 | - hrvPoints: hrvPoints, | ||
| 312 | - heartRatePoints: heartRatePoints, | ||
| 313 | - restingHeartRatePoints: restingHeartRatePoints, | ||
| 314 | - sleepIntervals: sleepIntervals, | ||
| 315 | - workoutIntervals: workoutIntervals, | ||
| 316 | - startTime: math.min(hrvStartTime, heartRateStartTime), | ||
| 317 | - endTime: effectiveEndTime, | 311 | + final capturedUserId = userId; |
| 312 | + final capturedStartTime = math.min(hrvStartTime, heartRateStartTime); | ||
| 313 | + final result = await Isolate.run( | ||
| 314 | + () => calculate( | ||
| 315 | + userId: capturedUserId, | ||
| 316 | + hrvPoints: hrvPoints, | ||
| 317 | + heartRatePoints: heartRatePoints, | ||
| 318 | + restingHeartRatePoints: restingHeartRatePoints, | ||
| 319 | + sleepIntervals: sleepIntervals, | ||
| 320 | + workoutIntervals: workoutIntervals, | ||
| 321 | + startTime: capturedStartTime, | ||
| 322 | + endTime: effectiveEndTime, | ||
| 323 | + ), | ||
| 324 | + debugName: 'HealthRawStressCalculator', | ||
| 318 | ); | 325 | ); |
| 319 | final newResult = result.copyWith( | 326 | final newResult = result.copyWith( |
| 320 | hrvStressPoints: _filterNewHrvStressPoints( | 327 | hrvStressPoints: _filterNewHrvStressPoints( |
| @@ -710,7 +717,8 @@ class HealthRawDataCoreService { | @@ -710,7 +717,8 @@ class HealthRawDataCoreService { | ||
| 710 | return '当前非 Debug 模式,未记录本地上传日志'; | 717 | return '当前非 Debug 模式,未记录本地上传日志'; |
| 711 | } | 718 | } |
| 712 | 719 | ||
| 713 | - HealthRawStressCalculationResult calculate({ | 720 | + static HealthRawStressCalculationResult calculate({ |
| 721 | + required int userId, | ||
| 714 | required List<HealthKitRawDataPoint> hrvPoints, | 722 | required List<HealthKitRawDataPoint> hrvPoints, |
| 715 | required List<HealthKitRawDataPoint> heartRatePoints, | 723 | required List<HealthKitRawDataPoint> heartRatePoints, |
| 716 | required List<HealthKitRawDataPoint> restingHeartRatePoints, | 724 | required List<HealthKitRawDataPoint> restingHeartRatePoints, |
| @@ -721,7 +729,7 @@ class HealthRawDataCoreService { | @@ -721,7 +729,7 @@ class HealthRawDataCoreService { | ||
| 721 | required int startTime, | 729 | required int startTime, |
| 722 | required int endTime, | 730 | required int endTime, |
| 723 | }) { | 731 | }) { |
| 724 | - return HealthRawStressCalculator(userId: _userId).calculate( | 732 | + return HealthRawStressCalculator(userId: userId).calculate( |
| 725 | hrvPoints: hrvPoints, | 733 | hrvPoints: hrvPoints, |
| 726 | heartRatePoints: heartRatePoints, | 734 | heartRatePoints: heartRatePoints, |
| 727 | restingHeartRatePoints: restingHeartRatePoints, | 735 | restingHeartRatePoints: restingHeartRatePoints, |
-
Please register or login to post a comment