1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
//! Models for the Oura API
//!
//! This module contains the models for the Oura API. These models are used to deserialize the JSON responses from the API into Rust structs.
//!
//! See the [Oura API documentation](https://cloud.ouraring.com/v2/docs) for more information.

use serde::Deserialize;

#[derive(Deserialize, Debug, PartialEq)]
pub struct Sample {
    pub interval: f32,
    pub items: Vec<Option<f32>>,
    pub timestamp: String,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct ActivityContributors {
    pub meet_daily_targets: Option<u8>,
    pub move_every_hour: Option<u8>,
    pub recovery_time: Option<u8>,
    pub stay_active: Option<u8>,
    pub training_frequency: Option<u8>,
    pub training_volume: Option<u8>,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct DailyActivity {
    pub id: String,
    pub class_5_min: Option<String>,
    pub score: Option<u8>,
    pub active_calories: u32,
    pub average_met_minutes: f32,
    pub contributors: ActivityContributors,
    pub equivalent_walking_distance: u32,
    pub high_activity_met_minutes: u32,
    pub high_activity_time: u32,
    pub inactivity_alerts: u32,
    pub low_activity_met_minutes: u32,
    pub low_activity_time: u32,
    pub medium_activity_met_minutes: u32,
    pub medium_activity_time: u32,
    pub met: Sample,
    pub meters_to_target: u32,
    pub non_wear_time: u32,
    pub resting_time: u32,
    pub sedentary_met_minutes: u32,
    pub sedentary_time: u32,
    pub steps: u32,
    pub target_calories: u32,
    pub target_meters: u32,
    pub total_calories: u32,
    pub day: String,
    pub timestamp: String,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct ReadinessContributors {
    pub activity_balance: Option<u8>,
    pub body_temperature: Option<u8>,
    pub hrv_balance: Option<u8>,
    pub previous_day_activity: Option<u8>,
    pub previous_night: Option<u8>,
    pub recovery_index: Option<u8>,
    pub resting_heart_rate: Option<u8>,
    pub sleep_balance: Option<u8>,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct DailyReadiness {
    pub id: String,
    pub contributors: ReadinessContributors,
    pub day: String,
    pub score: Option<u8>,
    pub temperature_deviation: Option<f32>,
    pub temperature_trend_deviation: Option<f32>,
    pub timestamp: String,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct SleepContributors {
    pub deep_sleep: Option<u8>,
    pub efficiency: Option<u8>,
    pub latency: Option<u8>,
    pub rem_sleep: Option<u8>,
    pub restfulness: Option<u8>,
    pub timing: Option<u8>,
    pub total_sleep: Option<u8>,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct DailySleep {
    pub id: String,
    pub contributors: SleepContributors,
    pub day: String,
    pub timestamp: String,
    pub score: Option<u8>,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct DailySpO2AggregatedValues {
    pub average: f32,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct DailySpO2 {
    pub id: String,
    pub day: String,
    pub spo2_percentage: Option<DailySpO2AggregatedValues>,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct HeartRate {
    pub bpm: u8,
    pub source: String,
    pub timestamp: String,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct PersonalInfo {
    pub id: String,
    pub age: Option<u32>,
    pub weight: Option<f32>,
    pub height: Option<f32>,
    pub biological_sex: Option<String>,
    pub email: Option<String>,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct RestModeEpisode {
    pub tags: Vec<String>,
    pub timestamp: String,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct RestModePeriod {
    pub id: String,
    pub end_day: Option<String>,
    pub end_time: Option<String>,
    pub episodes: Vec<RestModeEpisode>,
    pub start_day: String,
    pub start_time: String,
}

#[derive(Deserialize, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum RingColor {
    GlossyBlack,
    StealthBlack,
    Rose,
    Silver,
    GlossyGold,
}

#[derive(Deserialize, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum RingDesign {
    Heritage,
    Horizon,
}

#[derive(Deserialize, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum RingHardwareType {
    Gen1,
    Gen2,
    Gen2m,
    Gen3,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct RingConfiguration {
    pub id: String,
    pub color: Option<RingColor>,
    pub design: Option<RingDesign>,
    pub firmware_version: Option<String>,
    pub hardware_type: Option<RingHardwareType>,
    pub set_up_at: Option<String>,
    pub size: Option<u32>,
}

#[derive(Deserialize, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum MomentType {
    Breathing,
    Meditation,
    Nap,
    Relaxation,
    Rest,
    BodyStatus,
}

#[derive(Deserialize, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum MomentMood {
    Bad,
    Worse,
    Same,
    Good,
    Great,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct Session {
    pub id: String,
    pub day: String,
    pub start_datetime: String,
    pub end_datetime: String,
    pub r#type: MomentType,
    pub heart_rate: Option<Sample>,
    pub heart_rate_variability: Option<Sample>,
    pub mood: Option<MomentMood>,
    pub motion_count: Option<Sample>,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct ReadinessSummary {
    pub contributors: ReadinessContributors,
    pub score: Option<u8>,
    pub temperature_devation: Option<f32>,
    pub temperature_trend_deviation: Option<f32>,
}

#[derive(Deserialize, Debug, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum SleepAlgorithmVersion {
    V1,
    V2,
}

#[derive(Deserialize, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum SleepType {
    Deleted,
    Sleep,
    LongSleep,
    LateNap,
    Rest,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct Sleep {
    pub id: String,
    pub average_breath: Option<f32>,
    pub average_heart_rate: Option<f32>,
    pub average_hrv: Option<u32>,
    pub awake_time: Option<u32>,
    pub bedtime_end: String,
    pub bedtime_start: String,
    pub day: String,
    pub deep_sleep_duration: Option<u32>,
    pub efficiency: Option<u8>,
    pub heart_rate: Option<Sample>,
    pub hrv: Option<Sample>,
    pub latency: Option<u32>,
    pub light_sleep_duration: Option<u32>,
    pub low_battery_alert: bool,
    pub lowest_heart_rate: Option<u32>,
    pub movement_30_sec: Option<String>,
    pub period: u32,
    pub readiness: Option<ReadinessSummary>,
    pub readiness_score_delta: Option<u8>,
    pub rem_sleep_duration: Option<u32>,
    pub restless_periods: Option<u32>,
    pub sleep_phase_5_min: Option<String>,
    pub sleep_score_delta: Option<u8>,
    pub sleep_algorithm_version: Option<SleepAlgorithmVersion>,
    pub time_in_bed: u32,
    pub total_sleep_duration: Option<u32>,
    pub r#type: SleepType,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct SleepTimeWindow {
    pub day_tz: u32,
    pub end_offset: u32,
    pub start_offset: u32,
}

#[derive(Deserialize, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum SleepTimeRecommendation {
    ImproveEfficiency,
    EarlierBedtime,
    LaterBedtime,
    EarlierWakeUpTime,
    LaterWakeUpTime,
    FollowOptimalBedtime,
}

#[derive(Deserialize, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum SleepTimeStatus {
    NotEnoughNights,
    NotEnoughRecentNights,
    BadSleepQuality,
    OnlyRecommendedFound,
    OptimalFound,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct SleepTime {
    pub id: String,
    pub day: String,
    pub optimal_bedtime: Option<SleepTimeWindow>,
    pub recommendation: Option<SleepTimeRecommendation>,
    pub status: Option<SleepTimeStatus>,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct Tag {
    pub id: String,
    pub day: String,
    pub text: Option<String>,
    pub timestamp: String,
    pub tags: Vec<String>,
}

#[derive(Deserialize, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum WorkoutIntensity {
    Easy,
    Moderate,
    Hard,
}

#[derive(Deserialize, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum WorkoutSource {
    Manual,
    Autodetected,
    Confirmed,
    WorkoutHeartRate,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct Workout {
    pub id: String,
    pub activity: String,
    pub calories: Option<f32>,
    pub day: String,
    pub distance: Option<f32>,
    pub end_datetime: String,
    pub intensity: WorkoutIntensity,
    pub label: Option<String>,
    pub source: WorkoutSource,
    pub start_datetime: String,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct TagV2 {
    pub id: String,
    pub tag_type_code: Option<String>,
    pub start_time: String,
    pub end_time: Option<String>,
    pub start_day: String,
    pub end_day: Option<String>,
    pub comment: Option<String>,
}