healthautoexport

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TimeFormat is the format to parse time.Time in this package.
	TimeFormat        = "2006-01-02 15:04:05 -0700"
	SleepAnalysisName = "sleep_analysis"
)

Variables

This section is empty.

Functions

func Marshal

func Marshal(payload *Payload, w io.Writer) error

Marshal payload to io.Writer.

func MarshalToString

func MarshalToString(payload *Payload) (string, error)

MarshalToString marshals payload to a string.

Types

type AggregatedSleepAnalysis added in v0.3.0

type AggregatedSleepAnalysis struct {

	// Start time of sleep.
	SleepStart *Time `json:"sleepStart"`

	// End time of sleep.
	SleepEnd *Time `json:"sleepEnd"`

	// InBed duration in hours.
	InBed Qty `json:"inBed"`

	// Asleep duration in hours.
	Asleep Qty `json:"asleep"`

	// Awake duration in hours.
	// Only available from HAE v6.6.2 onwards.
	Awake Qty `json:"awake,omitempty"`

	// Core sleep duration in hours.
	// Only available from HAE v6.6.2 onwards.
	Core Qty `json:"core,omitempty"`

	// Deep sleep duration in hours.
	// Only available from HAE v6.6.2 onwards.
	Deep Qty `json:"deep,omitempty"`

	// REM sleep duration in hours.
	// Only available from HAE v6.6.2 onwards.
	REM Qty `json:"rem,omitempty"`

	// Start time of inBed phase.
	// Only available prior to HAE v6.6.2.
	InBedStart *Time `json:"inBedStart,omitempty"`

	// End time of inBed phase.
	// Only available prior to HAE v6.6.2.
	InBedEnd *Time `json:"inBedEnd,omitempty"`

	// Data source of sleep data.
	// Multiple source names will be joined together with a pipe (|).
	// Only available from HAE v6.6.2 onwards.
	Source string `json:"source,omitempty"`

	// Data source of sleep phase.
	// Only available prior to HAE v6.6.2.
	SleepSource string `json:"sleepSource,omitempty"`

	// Data source of inBed phase.
	// Only available prior to HAE v6.6.2.
	InBedSource string `json:"inBedSource,omitempty"`
}

AggregatedSleepAnalysis defines an aggregated period of an entire night of sleep. It is only valid for aggregate sleep analysis data ("Aggregate Sleep Data" is enabled)

type Datapoint

type Datapoint struct {
	Date *Time `json:"date"`

	// Qty may not be specified for some types of metrics.
	Qty Qty `json:"qty,omitempty"`

	// Other fields.
	Fields DatapointFields `json:"-"`
}

Datapoint is a point-in-time value of a metric.

func (*Datapoint) MarshalJSON

func (w *Datapoint) MarshalJSON() ([]byte, error)

func (*Datapoint) UnmarshalJSON

func (w *Datapoint) UnmarshalJSON(bytes []byte) error

UnmarshalJSON implements a custom json.Unmarshaler for Datapoint. This is necessary to unmarshal arbitrary DatapointFields.

type DatapointFields

type DatapointFields map[string]interface{}

DatapointFields is a map of fields with an arbitrary type in a single Datapoint.

type DatapointWithUnit

type DatapointWithUnit struct {
	Date *Time `json:"date"`
	QtyWithUnit
}

DatapointWithUnit is a point-in-time value of a QtyWithUnit.

type Elevation

type Elevation struct {
	Units   Units `json:"units"`
	Ascent  Qty   `json:"ascent"`
	Descent Qty   `json:"descent"`
}

Elevation is a specify QtyWithUnit that specifies Ascent and Descent values. It is only used for the Elevation field.

func (Elevation) GetUnits

func (e Elevation) GetUnits() Units

type Field added in v0.3.0

type Field struct {
	Key   string
	Value *QtyWithUnit
}

type Metric

type Metric struct {
	Name                    string                     `json:"name"`
	Units                   Units                      `json:"units"`
	Datapoints              []*Datapoint               `json:"-"`
	SleepAnalyses           []*SleepAnalysis           `json:"-"`
	AggregatedSleepAnalyses []*AggregatedSleepAnalysis `json:"-"`
}

Metric defines a single measurement with units, as well as time-series data points.

func (*Metric) GetUnits

func (m *Metric) GetUnits() Units

func (*Metric) MarshalJSON added in v0.2.0

func (m *Metric) MarshalJSON() ([]byte, error)

func (*Metric) UnmarshalJSON added in v0.2.0

func (m *Metric) UnmarshalJSON(bytes []byte) error

type Payload

type Payload struct {
	Data *PayloadData `json:"data,omitempty"`
}

func Unmarshal

func Unmarshal(r io.Reader) (*Payload, error)

Unmarshal payload from io.Reader.

func UnmarshalFromString

func UnmarshalFromString(s string) (*Payload, error)

UnmarshalFromString unmarshals payload from a string.

type PayloadData

type PayloadData struct {
	Metrics  []*Metric  `json:"metrics,omitempty"`
	Workouts []*Workout `json:"workouts,omitempty"`
}

type Qty

type Qty float64

Qty is used to define an arbitrary quantity.

type QtyWithUnit

type QtyWithUnit struct {
	Qty   Qty   `json:"qty"`
	Units Units `json:"units"`
}

QtyWithUnit combines a Qty with Units of measurement.

func (QtyWithUnit) GetUnits

func (q QtyWithUnit) GetUnits() Units

type RouteDatapoint

type RouteDatapoint struct {
	Lat       float64 `json:"lat"`
	Lon       float64 `json:"lon"`
	Altitude  float64 `json:"altitude"`
	Timestamp *Time   `json:"timestamp"`
}

RouteDatapoint is a point-in-time location in 3D coordinates.

type SleepAnalysis added in v0.2.0

type SleepAnalysis struct {
	StartDate *Time  `json:"startDate"`
	EndDate   *Time  `json:"endDate"`
	Qty       Qty    `json:"qty,omitempty"`
	Source    string `json:"source"`
	Value     string `json:"value"`
}

SleepAnalysis defines a period during sleep of various types (Value). It is only valid for non-aggregate sleep analysis data ("Aggregate Sleep Data" is disabled)

type Time

type Time struct {
	time.Time
}

Time is a custom time type for this package.

func NewTime

func NewTime(t time.Time) *Time

func (*Time) IsZero

func (t *Time) IsZero() bool

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. This implementation overrides the default time.Time json.Marshaler implementation, and marshals using TimeFormat.

func (*Time) String

func (t *Time) String() string

String returns a RFC3339 formatted timestamp string.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. This implementation overrides the default time.Time json.Unmarshaler implementation, and parses timestamps using TimeFormat.

type Units

type Units string

Units is used to define a unit of measurement.

type Workout

type Workout struct {
	Name  string `json:"name"`
	Start *Time  `json:"start"`
	End   *Time  `json:"end"`

	// Route data
	Route []*RouteDatapoint `json:"route,omitempty"`

	// Heart rate data.
	HeartRateData     []*DatapointWithUnit `json:"heartRateData,omitempty"`
	HeartRateRecovery []*DatapointWithUnit `json:"heartRateRecovery,omitempty"`

	// Elevation data.
	Elevation *Elevation `json:"elevation,omitempty"`

	// Other workout fields.
	Fields WorkoutFields `json:"-"`
}

Workout defines a single recorded Workout.

func (*Workout) MarshalJSON

func (w *Workout) MarshalJSON() ([]byte, error)

func (*Workout) UnmarshalJSON

func (w *Workout) UnmarshalJSON(bytes []byte) error

UnmarshalJSON implements a custom json.Unmarshaler for Workout. This is necessary to unmarshal arbitrary Fields that may match QtyWithUnit.

type WorkoutFields

type WorkoutFields []Field

WorkoutFields is a map of generic QtyWithUnit fields in a Workout.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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