Support Health Auto Export metric names
This commit is contained in:
+17
-6
@@ -493,17 +493,17 @@ final class App
|
||||
$sleepBuckets = [];
|
||||
|
||||
foreach ($metrics as $metric) {
|
||||
$name = strtolower((string) ($metric['name'] ?? ''));
|
||||
$data = array_values(array_filter(is_array($metric['data'] ?? null) ? $metric['data'] : [], 'is_array'));
|
||||
$name = $this->healthMetricName((string) ($metric['name'] ?? ($metric['metric'] ?? '')));
|
||||
$data = array_values(array_filter(is_array($metric['data'] ?? null) ? $metric['data'] : (is_array($metric['records'] ?? null) ? $metric['records'] : []), 'is_array'));
|
||||
|
||||
if ($name === 'step_count') {
|
||||
foreach ($data as $point) {
|
||||
$date = $this->healthPointDate($point['date'] ?? null);
|
||||
$date = $this->healthPointDate($point['date'] ?? ($point['startDate'] ?? null));
|
||||
if ($date === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$steps[$date] = ($steps[$date] ?? 0) + max(0, (int) round((float) ($point['qty'] ?? 0)));
|
||||
$steps[$date] = ($steps[$date] ?? 0) + max(0, (int) round((float) ($point['qty'] ?? ($point['value'] ?? 0))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -590,6 +590,17 @@ final class App
|
||||
];
|
||||
}
|
||||
|
||||
private function healthMetricName(string $name): string
|
||||
{
|
||||
$normalized = normalize_sport_type_id($name);
|
||||
|
||||
return match ($normalized) {
|
||||
'step-count', 'steps', 'hkquantitytypeidentifierstepcount' => 'step_count',
|
||||
'sleep-analysis', 'sleep', 'hkcategorytypeidentifiersleepanalysis' => 'sleep_analysis',
|
||||
default => str_replace('-', '_', $normalized),
|
||||
};
|
||||
}
|
||||
|
||||
private function healthEventsFromWorkouts(array $workouts, array &$settings): array
|
||||
{
|
||||
$sport = [];
|
||||
@@ -598,8 +609,8 @@ final class App
|
||||
$sportTypesAdded = 0;
|
||||
|
||||
foreach ($workouts as $workout) {
|
||||
$start = $this->healthDateTime($workout['start'] ?? null);
|
||||
$end = $this->healthDateTime($workout['end'] ?? null);
|
||||
$start = $this->healthDateTime($workout['start'] ?? ($workout['startDate'] ?? null));
|
||||
$end = $this->healthDateTime($workout['end'] ?? ($workout['endDate'] ?? null));
|
||||
if ($start === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user