Commit 570248cd31541554011ac8fe4e73856315c33f8f
1 parent
e93ef899
Revert "feat(ui):实时压力推送剔除is_workout"
This reverts commit 0df5140e.
Showing
4 changed files
with
15 additions
and
58 deletions
| @@ -410,7 +410,10 @@ class HealthRawDataCoreService { | @@ -410,7 +410,10 @@ class HealthRawDataCoreService { | ||
| 410 | : result.realtimeStressPoints.reduce( | 410 | : result.realtimeStressPoints.reduce( |
| 411 | (a, b) => a.rawEndTime >= b.rawEndTime ? a : b, | 411 | (a, b) => a.rawEndTime >= b.rawEndTime ? a : b, |
| 412 | ); | 412 | ); |
| 413 | - final realtimeWindow = latestRealtimeStressPoint == null | 413 | + final shouldSkipRealtimeStressNotification = |
| 414 | + latestRealtimeStressPoint?.isWorkout ?? false; | ||
| 415 | + final realtimeWindow = latestRealtimeStressPoint == null || | ||
| 416 | + shouldSkipRealtimeStressNotification | ||
| 414 | ? const <HealthRawRealtimeStressPoint>[] | 417 | ? const <HealthRawRealtimeStressPoint>[] |
| 415 | : await _localStore.queryRealtimeStressPoints( | 418 | : await _localStore.queryRealtimeStressPoints( |
| 416 | userId: result.userId, | 419 | userId: result.userId, |
| @@ -108,16 +108,10 @@ class HealthRawLocalNotificationBuilder { | @@ -108,16 +108,10 @@ class HealthRawLocalNotificationBuilder { | ||
| 108 | List<HealthRawRealtimeStressPoint> realtimeWindow, | 108 | List<HealthRawRealtimeStressPoint> realtimeWindow, |
| 109 | HealthRawLocalNotificationRecord? record, | 109 | HealthRawLocalNotificationRecord? record, |
| 110 | ) { | 110 | ) { |
| 111 | - final window = [...realtimeWindow] | 111 | + final valid = realtimeWindow |
| 112 | + .where((e) => e.result >= 1 && e.result <= 100) | ||
| 113 | + .toList() | ||
| 112 | ..sort((a, b) => a.rawEndTime.compareTo(b.rawEndTime)); | 114 | ..sort((a, b) => a.rawEndTime.compareTo(b.rawEndTime)); |
| 113 | - final lastWorkoutIndex = window.lastIndexWhere( | ||
| 114 | - (point) => point.isWorkout || point.isWorkoutRecovery, | ||
| 115 | - ); | ||
| 116 | - final stressWindow = lastWorkoutIndex < 0 | ||
| 117 | - ? window | ||
| 118 | - : window.skip(lastWorkoutIndex + 1).toList(); | ||
| 119 | - final valid = | ||
| 120 | - stressWindow.where((e) => e.result >= 1 && e.result <= 100).toList(); | ||
| 121 | if (valid.length < _realtimeMinPointCount) return null; | 115 | if (valid.length < _realtimeMinPointCount) return null; |
| 122 | 116 | ||
| 123 | final latest = valid.last; | 117 | final latest = valid.last; |
| @@ -80,6 +80,7 @@ void main() { | @@ -80,6 +80,7 @@ void main() { | ||
| 80 | ); | 80 | ); |
| 81 | 81 | ||
| 82 | api.calls.clear(); | 82 | api.calls.clear(); |
| 83 | + store.realtimeNotificationWindowQueryCount = 0; | ||
| 83 | final second = await service.startCoreCaculate( | 84 | final second = await service.startCoreCaculate( |
| 84 | endTime: base + 800, | 85 | endTime: base + 800, |
| 85 | readChunkDays: 1, | 86 | readChunkDays: 1, |
| @@ -90,6 +91,7 @@ void main() { | @@ -90,6 +91,7 @@ void main() { | ||
| 90 | second.realtimeStressPoints.map((e) => e.rawEndTime), | 91 | second.realtimeStressPoints.map((e) => e.rawEndTime), |
| 91 | [base + 720], | 92 | [base + 720], |
| 92 | ); | 93 | ); |
| 94 | + expect(store.realtimeNotificationWindowQueryCount, 0); | ||
| 93 | expect( | 95 | expect( |
| 94 | api.firstCallStart(HealthDataUploadType.hrv.type), | 96 | api.firstCallStart(HealthDataUploadType.hrv.type), |
| 95 | lessThanOrEqualTo(base + 120), | 97 | lessThanOrEqualTo(base + 120), |
| @@ -869,6 +871,7 @@ class _MemoryHealthRawStressLocalStore extends HealthRawStressLocalStore { | @@ -869,6 +871,7 @@ class _MemoryHealthRawStressLocalStore extends HealthRawStressLocalStore { | ||
| 869 | final Map<int, List<HealthRawDailyStressPoint>> _daily = {}; | 871 | final Map<int, List<HealthRawDailyStressPoint>> _daily = {}; |
| 870 | final Map<int, List<HealthRawSleepResult>> _sleep = {}; | 872 | final Map<int, List<HealthRawSleepResult>> _sleep = {}; |
| 871 | final List<String> operationLog; | 873 | final List<String> operationLog; |
| 874 | + var realtimeNotificationWindowQueryCount = 0; | ||
| 872 | 875 | ||
| 873 | void insertDailyStress(HealthRawDailyStressPoint point) { | 876 | void insertDailyStress(HealthRawDailyStressPoint point) { |
| 874 | final byDate = <int, HealthRawDailyStressPoint>{ | 877 | final byDate = <int, HealthRawDailyStressPoint>{ |
| @@ -1039,6 +1042,9 @@ class _MemoryHealthRawStressLocalStore extends HealthRawStressLocalStore { | @@ -1039,6 +1042,9 @@ class _MemoryHealthRawStressLocalStore extends HealthRawStressLocalStore { | ||
| 1039 | required int endTime, | 1042 | required int endTime, |
| 1040 | }) async { | 1043 | }) async { |
| 1041 | operationLog.add('queryRealtimeStressPoints'); | 1044 | operationLog.add('queryRealtimeStressPoints'); |
| 1045 | + if (endTime - startTime <= Duration.secondsPerHour) { | ||
| 1046 | + realtimeNotificationWindowQueryCount += 1; | ||
| 1047 | + } | ||
| 1042 | return (_realtime[userId] ?? <HealthRawRealtimeStressPoint>[]) | 1048 | return (_realtime[userId] ?? <HealthRawRealtimeStressPoint>[]) |
| 1043 | .where((e) => e.rawEndTime >= startTime && e.rawEndTime <= endTime) | 1049 | .where((e) => e.rawEndTime >= startTime && e.rawEndTime <= endTime) |
| 1044 | .toList(); | 1050 | .toList(); |
| @@ -123,50 +123,6 @@ void main() { | @@ -123,50 +123,6 @@ void main() { | ||
| 123 | 123 | ||
| 124 | expect(notifications, isEmpty); | 124 | expect(notifications, isEmpty); |
| 125 | }); | 125 | }); |
| 126 | - | ||
| 127 | - test('resets realtime stress window after workout point', () { | ||
| 128 | - final base = _seconds(DateTime(2026, 1, 1, 9)); | ||
| 129 | - final notifications = builder.build( | ||
| 130 | - result: HealthRawStressCalculationResult( | ||
| 131 | - userId: 1, | ||
| 132 | - hrvStressPoints: const [], | ||
| 133 | - realtimeStressPoints: [_realtimePoint(base + 12 * 300, 70)], | ||
| 134 | - dailyStressPoints: const [], | ||
| 135 | - ), | ||
| 136 | - hasExistingHrv: false, | ||
| 137 | - realtimeWindow: [ | ||
| 138 | - for (var i = 0; i < 3; i++) _realtimePoint(base + i * 300, 70), | ||
| 139 | - _realtimePoint(base + 3 * 300, 70, isWorkout: true), | ||
| 140 | - for (var i = 4; i < 13; i++) _realtimePoint(base + i * 300, 70), | ||
| 141 | - ], | ||
| 142 | - record: const HealthRawLocalNotificationRecord(), | ||
| 143 | - ); | ||
| 144 | - | ||
| 145 | - expect(notifications, isEmpty); | ||
| 146 | - }); | ||
| 147 | - | ||
| 148 | - test('builds realtime stress notification after workout reset window refills', | ||
| 149 | - () { | ||
| 150 | - final base = _seconds(DateTime(2026, 1, 1, 9)); | ||
| 151 | - final notifications = builder.build( | ||
| 152 | - result: HealthRawStressCalculationResult( | ||
| 153 | - userId: 1, | ||
| 154 | - hrvStressPoints: const [], | ||
| 155 | - realtimeStressPoints: [_realtimePoint(base + 13 * 300, 70)], | ||
| 156 | - dailyStressPoints: const [], | ||
| 157 | - ), | ||
| 158 | - hasExistingHrv: false, | ||
| 159 | - realtimeWindow: [ | ||
| 160 | - for (var i = 0; i < 3; i++) _realtimePoint(base + i * 300, 30), | ||
| 161 | - _realtimePoint(base + 3 * 300, 30, isWorkoutRecovery: true), | ||
| 162 | - for (var i = 4; i < 14; i++) _realtimePoint(base + i * 300, 70), | ||
| 163 | - ], | ||
| 164 | - record: const HealthRawLocalNotificationRecord(), | ||
| 165 | - ); | ||
| 166 | - | ||
| 167 | - expect(notifications, hasLength(1)); | ||
| 168 | - expect(notifications.single.title, '注意压力 · 09:05-10:05'); | ||
| 169 | - }); | ||
| 170 | } | 126 | } |
| 171 | 127 | ||
| 172 | int _seconds(DateTime time) => time.millisecondsSinceEpoch ~/ 1000; | 128 | int _seconds(DateTime time) => time.millisecondsSinceEpoch ~/ 1000; |
| @@ -191,8 +147,6 @@ HealthRawRealtimeStressPoint _realtimePoint( | @@ -191,8 +147,6 @@ HealthRawRealtimeStressPoint _realtimePoint( | ||
| 191 | int rawEndTime, | 147 | int rawEndTime, |
| 192 | double result, { | 148 | double result, { |
| 193 | bool isSleepLikely = false, | 149 | bool isSleepLikely = false, |
| 194 | - bool isWorkout = false, | ||
| 195 | - bool isWorkoutRecovery = false, | ||
| 196 | }) { | 150 | }) { |
| 197 | return HealthRawRealtimeStressPoint( | 151 | return HealthRawRealtimeStressPoint( |
| 198 | userId: 1, | 152 | userId: 1, |
| @@ -203,8 +157,8 @@ HealthRawRealtimeStressPoint _realtimePoint( | @@ -203,8 +157,8 @@ HealthRawRealtimeStressPoint _realtimePoint( | ||
| 203 | sourceEndTime: rawEndTime, | 157 | sourceEndTime: rawEndTime, |
| 204 | flags: HealthRawPointFlags( | 158 | flags: HealthRawPointFlags( |
| 205 | isSleepLikely: isSleepLikely, | 159 | isSleepLikely: isSleepLikely, |
| 206 | - isWorkout: isWorkout, | ||
| 207 | - isWorkoutRecovery: isWorkoutRecovery, | 160 | + isWorkout: false, |
| 161 | + isWorkoutRecovery: false, | ||
| 208 | isSuspectedActivity: false, | 162 | isSuspectedActivity: false, |
| 209 | ), | 163 | ), |
| 210 | ); | 164 | ); |
-
Please register or login to post a comment