Replace Apple Health ingest with iPhone location geofences

POST /api/v1/location/{arrive,leave} records place intervals (home or a
named place, and away in between) from Shortcuts automations. A stale
"leave" for a place the device has already left is ignored. The Health
Auto Export endpoint and its normalizer are removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-14 22:06:25 +01:00
co-authored by Claude Opus 5.5
parent 230840cabd
commit 67638cdef0
10 changed files with 269 additions and 238 deletions
+48
View File
@@ -0,0 +1,48 @@
package ingest
import (
"fmt"
"strings"
"time"
)
// Location transitions come from phone geofence automations (e.g. iOS
// Shortcuts "Arrive"/"Leave"), which can only report the moment of crossing.
// The store turns them into back-to-back intervals with kind "place",
// labelled by the place, or Away between places.
const (
LocationSource = "location"
PlaceKind = "place"
Away = "away"
DefaultPlace = "home"
)
// LocationEvent is the optional body of POST /location/{arrive,leave}. An
// empty body means "home, now".
type LocationEvent struct {
Place string `json:"place"`
At time.Time `json:"at"`
}
// NormalizeLocation fills defaults and validates a transition.
func NormalizeLocation(e LocationEvent, now time.Time) (LocationEvent, error) {
e.Place = strings.ToLower(strings.TrimSpace(e.Place))
if e.Place == "" {
e.Place = DefaultPlace
}
if e.At.IsZero() {
e.At = now
}
e.At = e.At.UTC()
switch {
case e.Place == Away:
return e, fmt.Errorf("%q is reserved for time between places", Away)
case len(e.Place) > maxLabelLength:
return e, fmt.Errorf("place longer than %d characters", maxLabelLength)
case e.At.After(now.Add(maxFutureSkew)):
return e, fmt.Errorf("at is in the future")
case e.At.Before(now.Add(-maxDuration)):
return e, fmt.Errorf("at is more than %s ago", maxDuration)
}
return e, nil
}