parser

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TargetRecordTypes = map[string]string{

	"HKQuantityTypeIdentifierHeartRate":        "heart_rate",
	"HKQuantityTypeIdentifierStepCount":        "steps",
	"HKQuantityTypeIdentifierOxygenSaturation": "spo2",
	"HKQuantityTypeIdentifierVO2Max":           "vo2_max",
	"HKCategoryTypeIdentifierSleepAnalysis":    "sleep",

	"HKQuantityTypeIdentifierRestingHeartRate":           "resting_heart_rate",
	"HKQuantityTypeIdentifierHeartRateVariabilitySDNN":   "hrv",
	"HKQuantityTypeIdentifierHeartRateRecoveryOneMinute": "heart_rate_recovery",
	"HKQuantityTypeIdentifierRespiratoryRate":            "respiratory_rate",

	"HKQuantityTypeIdentifierBloodPressureSystolic":  "blood_pressure_systolic",
	"HKQuantityTypeIdentifierBloodPressureDiastolic": "blood_pressure_diastolic",

	"HKQuantityTypeIdentifierActiveEnergyBurned": "active_energy",
	"HKQuantityTypeIdentifierBasalEnergyBurned":  "basal_energy",
	"HKQuantityTypeIdentifierAppleExerciseTime":  "exercise_time",
	"HKQuantityTypeIdentifierAppleStandTime":     "stand_time",
	"HKQuantityTypeIdentifierFlightsClimbed":     "flights_climbed",

	"HKQuantityTypeIdentifierDistanceWalkingRunning": "distance_walking_running",
	"HKQuantityTypeIdentifierDistanceCycling":        "distance_cycling",

	"HKQuantityTypeIdentifierBodyMass":      "body_mass",
	"HKQuantityTypeIdentifierBodyMassIndex": "body_mass_index",
	"HKQuantityTypeIdentifierHeight":        "height",

	"HKQuantityTypeIdentifierWalkingSpeed":                   "walking_speed",
	"HKQuantityTypeIdentifierWalkingStepLength":              "walking_step_length",
	"HKQuantityTypeIdentifierWalkingAsymmetryPercentage":     "walking_asymmetry",
	"HKQuantityTypeIdentifierWalkingDoubleSupportPercentage": "walking_double_support",
	"HKQuantityTypeIdentifierAppleWalkingSteadiness":         "walking_steadiness",
	"HKQuantityTypeIdentifierStairAscentSpeed":               "stair_ascent_speed",
	"HKQuantityTypeIdentifierStairDescentSpeed":              "stair_descent_speed",
	"HKQuantityTypeIdentifierSixMinuteWalkTestDistance":      "six_minute_walk",

	"HKQuantityTypeIdentifierRunningSpeed":               "running_speed",
	"HKQuantityTypeIdentifierRunningPower":               "running_power",
	"HKQuantityTypeIdentifierRunningStrideLength":        "running_stride_length",
	"HKQuantityTypeIdentifierRunningGroundContactTime":   "running_ground_contact_time",
	"HKQuantityTypeIdentifierRunningVerticalOscillation": "running_vertical_oscillation",

	"HKQuantityTypeIdentifierAppleSleepingWristTemperature": "wrist_temperature",
	"HKQuantityTypeIdentifierTimeInDaylight":                "time_in_daylight",
	"HKQuantityTypeIdentifierDietaryWater":                  "dietary_water",
	"HKQuantityTypeIdentifierPhysicalEffort":                "physical_effort",
	"HKQuantityTypeIdentifierWalkingHeartRateAverage":       "walking_heart_rate",

	"HKCategoryTypeIdentifierMindfulSession": "mindful_sessions",
	"HKCategoryTypeIdentifierAppleStandHour": "stand_hours",
}

TargetRecordTypes is the set of HK types we care about, mapping to table names. Blood pressure uses sentinel names "blood_pressure_systolic"/"blood_pressure_diastolic" and is paired in the parser before writing to the "blood_pressure" table.

Functions

func BloodPressureColumns added in v0.4.0

func BloodPressureColumns() []string

BloodPressureColumns returns the column names for the blood_pressure table.

func RecordColumns

func RecordColumns(table string) []string

RecordColumns returns the column names for a given metric table.

func WorkoutColumns

func WorkoutColumns() []string

WorkoutColumns returns the column names for the workouts table.

Types

type ParseResult

type ParseResult struct {
	Stats    []*storage.InsertStats
	Total    int64
	Workouts int64
}

ParseResult holds the parsing outcome.

func ParseFile

func ParseFile(path string, db *storage.DB, progress ProgressFunc) (*ParseResult, error)

ParseFile parses an Apple Health export file (.zip or .xml) and inserts data into the DB.

type ProgressFunc

type ProgressFunc func(records int64, workouts int64)

ProgressFunc is called periodically during parsing with the count of records processed.

type Record

type Record struct {
	Type       string `xml:"type,attr"`
	Unit       string `xml:"unit,attr"`
	Value      string `xml:"value,attr"`
	SourceName string `xml:"sourceName,attr"`
	StartDate  string `xml:"startDate,attr"`
	EndDate    string `xml:"endDate,attr"`
}

Record represents a single Apple Health Record element.

type Workout

type Workout struct {
	ActivityType          string              `xml:"workoutActivityType,attr"`
	Duration              string              `xml:"duration,attr"`
	DurationUnit          string              `xml:"durationUnit,attr"`
	TotalDistance         string              `xml:"totalDistance,attr"`
	TotalDistanceUnit     string              `xml:"totalDistanceUnit,attr"`
	TotalEnergyBurned     string              `xml:"totalEnergyBurned,attr"`
	TotalEnergyBurnedUnit string              `xml:"totalEnergyBurnedUnit,attr"`
	SourceName            string              `xml:"sourceName,attr"`
	StartDate             string              `xml:"startDate,attr"`
	EndDate               string              `xml:"endDate,attr"`
	Statistics            []WorkoutStatistics `xml:"WorkoutStatistics"`
}

Workout represents a single Apple Health Workout element.

type WorkoutStatistics added in v0.4.1

type WorkoutStatistics struct {
	Type string `xml:"type,attr"`
	Sum  string `xml:"sum,attr"`
	Unit string `xml:"unit,attr"`
}

WorkoutStatistics is a child element of <Workout> that provides aggregated metrics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL