Support Health Auto Export metric names
This commit is contained in:
+17
-6
@@ -493,17 +493,17 @@ final class App
|
|||||||
$sleepBuckets = [];
|
$sleepBuckets = [];
|
||||||
|
|
||||||
foreach ($metrics as $metric) {
|
foreach ($metrics as $metric) {
|
||||||
$name = strtolower((string) ($metric['name'] ?? ''));
|
$name = $this->healthMetricName((string) ($metric['name'] ?? ($metric['metric'] ?? '')));
|
||||||
$data = array_values(array_filter(is_array($metric['data'] ?? null) ? $metric['data'] : [], 'is_array'));
|
$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') {
|
if ($name === 'step_count') {
|
||||||
foreach ($data as $point) {
|
foreach ($data as $point) {
|
||||||
$date = $this->healthPointDate($point['date'] ?? null);
|
$date = $this->healthPointDate($point['date'] ?? ($point['startDate'] ?? null));
|
||||||
if ($date === null) {
|
if ($date === null) {
|
||||||
continue;
|
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
|
private function healthEventsFromWorkouts(array $workouts, array &$settings): array
|
||||||
{
|
{
|
||||||
$sport = [];
|
$sport = [];
|
||||||
@@ -598,8 +609,8 @@ final class App
|
|||||||
$sportTypesAdded = 0;
|
$sportTypesAdded = 0;
|
||||||
|
|
||||||
foreach ($workouts as $workout) {
|
foreach ($workouts as $workout) {
|
||||||
$start = $this->healthDateTime($workout['start'] ?? null);
|
$start = $this->healthDateTime($workout['start'] ?? ($workout['startDate'] ?? null));
|
||||||
$end = $this->healthDateTime($workout['end'] ?? null);
|
$end = $this->healthDateTime($workout['end'] ?? ($workout['endDate'] ?? null));
|
||||||
if ($start === null) {
|
if ($start === null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user