← All repositories

reportage

A life-logging app for iPhone

git clone https://code.inqk.net/reportage.git


Shared/Models/HealthContext.swift (1468B)

1import Foundation
2
3/// What Health had for a report. It's a local cache, filled in after the
4/// report is filed and never synced: HealthKit already syncs Health data, so
5/// another device rebuilds it from its own store. A value left out means
6/// Health had nothing for it, which includes Health access being denied.
7struct HealthContext: Codable, Hashable, Sendable {
8    var activity: ActivityHealth?
9    /// Only for wake reports: the night before.
10    var sleep: SleepHealth?
11}
12
13/// Activity from local midnight in the report's time zone up to the report.
14struct ActivityHealth: Codable, Hashable, Sendable {
15    var steps: Int?
16    /// Walking and running, metres.
17    var distance: Double?
18    var flightsClimbed: Int?
19}
20
21/// One sleep session, from a single source.
22struct SleepHealth: Codable, Hashable, Sendable {
23    var start: Date
24    var end: Date
25    /// Seconds asleep, in any stage.
26    var asleep: TimeInterval
27    /// Seconds in each stage, where the source records stages.
28    var core: TimeInterval?
29    var deep: TimeInterval?
30    var rem: TimeInterval?
31    /// Seconds awake between falling asleep and waking.
32    var awake: TimeInterval?
33}
34
35/// A report's Health cache entry.
36struct HealthRecord: Equatable, Sendable {
37    var health: HealthContext
38    /// When it was read from Health.
39    var derivedAt: Date
40    /// Whether Health is taken to have finished changing for the report, so
41    /// it isn't read again.
42    var isSettled: Bool
43}