Commit 853b626c2c152cd453caf1d5619459247acb016b

Authored by 权海
1 parent 5e42fc23

feat(ui):能量消耗在原始值就统一向上取整

... ... @@ -207,11 +207,11 @@ final class HealthKitQueryReader {
return NativeActivityTarget(
healthValueTimestamp: timestamp,
move: Int(summary.activeEnergyBurnedGoal.doubleValue(for: .kilocalorie())),
move: Int(summary.activeEnergyBurnedGoal.doubleValue(for: .kilocalorie()).rounded(.up)),
stand: Int(summary.appleStandHoursGoal.doubleValue(for: .count())),
activityMoveMode: Self.activityMoveModeValue(from: summary),
activeEnergyBurned: summary.activeEnergyBurned.doubleValue(for: .kilocalorie()),
activeEnergyBurnedGoal: summary.activeEnergyBurnedGoal.doubleValue(for: .kilocalorie()),
activeEnergyBurned: summary.activeEnergyBurned.doubleValue(for: .kilocalorie()).rounded(.up),
activeEnergyBurnedGoal: summary.activeEnergyBurnedGoal.doubleValue(for: .kilocalorie()).rounded(.up),
appleMoveTime: Self.appleMoveTimeValue(from: summary),
appleMoveTimeGoal: Self.appleMoveTimeGoalValue(from: summary),
appleExerciseTime: summary.appleExerciseTime.doubleValue(for: .second()),
... ...
... ... @@ -266,8 +266,10 @@ class LocalHealthDataConvert {
totalSteps: 0,
totalStand: _sum(daily.map((e) => e.standHours).toList()),
totalExercise: _sum(daily.map((e) => e.exerciseSeconds).toList()),
avgMove: _averageOrNull(daily.map((e) => e.move).toList()),
qoqAvgMove: _averageOrNull(previousDaily.map((e) => e.move).toList()),
avgMove: _ceilOrNull(_averageOrNull(daily.map((e) => e.move).toList())),
qoqAvgMove: _ceilOrNull(
_averageOrNull(previousDaily.map((e) => e.move).toList()),
),
activityTargetInfo: _activityTargetInfo(latestWithGoal),
moveTrendList: [
for (final item in daily)
... ... @@ -412,7 +414,7 @@ class LocalHealthDataConvert {
);
return V2ActivityTarget(
userId: userId,
move: latestWithGoal?.activeEnergyBurnedGoal?.ceil(),
move: _ceilOrNull(latestWithGoal?.activeEnergyBurnedGoal),
step: 0,
stand: latestWithGoal?.standHoursGoal?.round(),
exercise: latestWithGoal?.exerciseTimeGoal == null
... ... @@ -584,10 +586,10 @@ class LocalHealthDataConvert {
final latest = dayActivity.isEmpty ? null : dayActivity.last;
return _ActivityDaySummary(
day: day,
move: (latest?.activeEnergyBurned ?? 0).ceil(),
move: _ceilOrZero(latest?.activeEnergyBurned),
standHours: latest?.appleStandHours ?? 0,
exerciseSeconds: latest?.appleExerciseTime ?? 0,
moveGoal: latest?.activeEnergyBurnedGoal,
moveGoal: _ceilOrNull(latest?.activeEnergyBurnedGoal),
standGoal: latest?.standHoursGoal,
exerciseGoalSeconds: latest?.exerciseTimeGoal,
);
... ... @@ -693,7 +695,7 @@ class LocalHealthDataConvert {
) {
if (summary == null || !summary.hasGoal) return null;
return ActivityTargetInfo(
move: summary.moveGoal,
move: _ceilOrNull(summary.moveGoal),
step: 0,
stand: summary.standGoal,
exercise: summary.exerciseGoalSeconds,
... ... @@ -1002,6 +1004,10 @@ class LocalHealthDataConvert {
}
static bool _isPositive(num? value) => value != null && value > 0;
static int _ceilOrZero(num? value) => (value ?? 0).ceil();
static int? _ceilOrNull(num? value) => value?.ceil();
}
class _ActivityDaySummary {
... ...
... ... @@ -342,7 +342,7 @@ class LocalHealthDataSource implements HealthDataSource {
for (final item in reversed) {
if (activeEnergyBurnedGoal == null &&
_isPositive(item.activeEnergyBurnedGoal)) {
activeEnergyBurnedGoal = item.activeEnergyBurnedGoal;
activeEnergyBurnedGoal = item.activeEnergyBurnedGoal?.ceilToDouble();
resolvedEndTime =
resolvedEndTime < item.endTime ? item.endTime : resolvedEndTime;
}
... ...
... ... @@ -457,9 +457,7 @@ void main() {
});
group('LocalHealthDataConvert activity unit conversion', () {
test(
'passes through exercise seconds and stand hours from raw activity data',
() {
test('uses ceiled kcal move values and raw exercise/stand units', () {
final day = DateTime(2026, 7, 16);
final endTime = LocalHealthDataConvert.unixSeconds(
day.add(const Duration(hours: 12)),
... ... @@ -468,8 +466,8 @@ void main() {
HealthKitRawActivityDataPoint(
endTime: endTime,
activityMoveMode: 0,
activeEnergyBurned: 300,
activeEnergyBurnedGoal: 500,
activeEnergyBurned: 300.1,
activeEnergyBurnedGoal: 500.1,
appleMoveTime: 8000,
appleMoveTimeGoal: 10000,
appleExerciseTime: 1800,
... ... @@ -499,13 +497,19 @@ void main() {
sleepIntervals: const [],
);
expect(healthData.move, 301);
expect(healthData.exercise, 1800);
expect(healthData.stand, 6);
expect(target.move, 501);
expect(target.exercise, 3600);
expect(target.stand, 12);
expect(statistics.totalMove, 301);
expect(statistics.avgMove, 301);
expect(statistics.moveTrendList?.single.value, 301);
expect(statistics.overallList?.single.value?.move, 301);
expect(statistics.totalExercise, 1800);
expect(statistics.totalStand, 6);
expect(statistics.activityTargetInfo?.move, 500);
expect(statistics.activityTargetInfo?.move, 501);
expect(statistics.activityTargetInfo?.exercise, 3600);
expect(statistics.activityTargetInfo?.stand, 12);
});
... ... @@ -526,7 +530,7 @@ void main() {
endTime: LocalHealthDataConvert.unixSeconds(
secondDay.add(const Duration(hours: 12)),
),
activeEnergyBurnedGoal: 600,
activeEnergyBurnedGoal: 600.1,
exerciseTimeGoal: 0,
standHoursGoal: null,
),
... ... @@ -540,7 +544,7 @@ void main() {
sleepIntervals: const [],
);
expect(statistics.activityTargetInfo?.move, 600);
expect(statistics.activityTargetInfo?.move, 601);
expect(statistics.activityTargetInfo?.exercise, 3600);
expect(statistics.activityTargetInfo?.stand, 12);
});
... ...