mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-03 18:43:42 +01:00
Activate the rest of the metric types
This commit is contained in:
@@ -20,6 +20,9 @@
|
||||
<uses-permission android:name="android.permission.health.READ_HEART_RATE"/>
|
||||
<uses-permission android:name="android.permission.health.READ_RESTING_HEART_RATE"/>
|
||||
<uses-permission android:name="android.permission.health.READ_SLEEP"/>
|
||||
<uses-permission android:name="android.permission.health.READ_STEPS"/>
|
||||
<uses-permission android:name="android.permission.health.READ_DISTANCE"/>
|
||||
<uses-permission android:name="android.permission.health.READ_ACTIVE_CALORIES_BURNED"/>
|
||||
<uses-permission android:name="android.permission.health.READ_HEALTH_DATA_HISTORY"/>
|
||||
|
||||
<queries>
|
||||
|
||||
@@ -160,11 +160,14 @@ double _heightToCm(double raw) => raw < 3 ? raw * 100 : raw;
|
||||
|
||||
double _identity(double raw) => raw;
|
||||
|
||||
/// Both platforms report a distance in meters, the category stores kilometers.
|
||||
double _metersToKm(double raw) => raw / 1000;
|
||||
|
||||
/// The V1 metric set (see `plan-measurements-health-v27.md`).
|
||||
///
|
||||
/// Only [HealthMetric.enabled] entries are imported. The rest are declared so
|
||||
/// the mapping is visible in one place; each is blocked on groundwork noted in
|
||||
/// its [HealthMetric.disabledReason].
|
||||
/// Only [HealthMetric.enabled] entries are imported. A disabled one stays
|
||||
/// declared so the mapping is visible in one place, with the groundwork it
|
||||
/// waits for in its [HealthMetric.disabledReason].
|
||||
const List<HealthMetric> healthMetrics = [
|
||||
HealthMetric(
|
||||
metricType: MetricType.bodyFat,
|
||||
@@ -248,11 +251,36 @@ const List<HealthMetric> healthMetrics = [
|
||||
dayRollsOverAtHour: 18,
|
||||
enabled: true,
|
||||
),
|
||||
// The three cumulative types below are counters, not measurements: a single
|
||||
// record covers a few minutes and means nothing on its own, so only the
|
||||
// day's total is stored. Both platforms can aggregate them themselves, which
|
||||
// would replace the raw read with one row per day; until the importer has
|
||||
// that path, they are read raw in small windows and summed here.
|
||||
HealthMetric(
|
||||
metricType: MetricType.steps,
|
||||
dataType: HealthDataType.STEPS,
|
||||
toCategoryValue: _identity,
|
||||
disabledReason: 'High-volume cumulative type, parked behind a load test.',
|
||||
dailyAggregation: DailyAggregation.sum,
|
||||
enabled: true,
|
||||
readWindow: highVolumeReadWindow,
|
||||
),
|
||||
HealthMetric(
|
||||
metricType: MetricType.distance,
|
||||
dataType: HealthDataType.DISTANCE_DELTA,
|
||||
toCategoryValue: _metersToKm,
|
||||
dailyAggregation: DailyAggregation.sum,
|
||||
enabled: true,
|
||||
readWindow: highVolumeReadWindow,
|
||||
),
|
||||
HealthMetric(
|
||||
// Active energy only: the basal part is a platform estimate the user never
|
||||
// recorded, and adding it in would make the day's number depend on which
|
||||
// platform wrote it.
|
||||
metricType: MetricType.energy,
|
||||
dataType: HealthDataType.ACTIVE_ENERGY_BURNED,
|
||||
toCategoryValue: _identity,
|
||||
dailyAggregation: DailyAggregation.sum,
|
||||
enabled: true,
|
||||
readWindow: highVolumeReadWindow,
|
||||
),
|
||||
];
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:health_bridge/health.dart';
|
||||
import 'package:wger/features/health/models/health_metric.dart';
|
||||
@@ -26,7 +25,7 @@ HealthMetric _metric(MetricType type) => healthMetrics.firstWhere((m) => m.metri
|
||||
|
||||
void main() {
|
||||
group('Enabled metric set', () {
|
||||
test('only the V1 sample metrics are imported', () {
|
||||
test('every declared metric is imported', () {
|
||||
expect(
|
||||
enabledHealthMetrics.map((m) => m.metricType),
|
||||
containsAll([
|
||||
@@ -37,9 +36,12 @@ void main() {
|
||||
MetricType.heartRate,
|
||||
MetricType.restingHeartRate,
|
||||
MetricType.sleep,
|
||||
MetricType.steps,
|
||||
MetricType.distance,
|
||||
MetricType.energy,
|
||||
]),
|
||||
);
|
||||
expect(enabledHealthMetrics.length, 7);
|
||||
expect(enabledHealthMetrics.length, 10);
|
||||
});
|
||||
|
||||
test('daily aggregation is set per metric', () {
|
||||
@@ -49,6 +51,21 @@ void main() {
|
||||
expect(_metric(MetricType.sleep).dailyAggregation, DailyAggregation.mergedDuration);
|
||||
// The platforms compute the resting rate per day themselves
|
||||
expect(_metric(MetricType.restingHeartRate).dailyAggregation, isNull);
|
||||
// One record of a counter covers minutes, only the day's total is a
|
||||
// measurement
|
||||
for (final type in [MetricType.steps, MetricType.distance, MetricType.energy]) {
|
||||
expect(_metric(type).dailyAggregation, DailyAggregation.sum);
|
||||
}
|
||||
});
|
||||
|
||||
test('the cumulative types are read in small windows', () {
|
||||
for (final type in [MetricType.steps, MetricType.distance, MetricType.energy]) {
|
||||
expect(_metric(type).readWindow, highVolumeReadWindow);
|
||||
}
|
||||
});
|
||||
|
||||
test('a distance arrives in meters and is stored in kilometers', () {
|
||||
expect(_metric(MetricType.distance).toCategoryValue(5300), closeTo(5.3, 0.001));
|
||||
});
|
||||
|
||||
test('sleep is attributed to the wake day', () {
|
||||
@@ -73,9 +90,9 @@ void main() {
|
||||
});
|
||||
|
||||
test('every disabled metric explains why', () {
|
||||
final disabled = healthMetrics.where((m) => !m.enabled);
|
||||
expect(disabled, isNotEmpty);
|
||||
expect(disabled.every((m) => m.disabledReason != null), isTrue);
|
||||
// Nothing is parked at the moment; the rule is for the next type that is
|
||||
// declared before its groundwork exists
|
||||
expect(healthMetrics.where((m) => !m.enabled).every((m) => m.disabledReason != null), isTrue);
|
||||
});
|
||||
|
||||
test('metric types are unique', () {
|
||||
@@ -113,7 +130,5 @@ void main() {
|
||||
enabledHealthMetrics,
|
||||
healthMetrics.where((m) => m.enabled).toList(),
|
||||
);
|
||||
// sanity: the disabled ones really are excluded
|
||||
expect(enabledHealthMetrics.firstWhereOrNull((m) => m.metricType == MetricType.steps), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user