Skip to main content

strava_wrapper/models/
activity.rs

1//! Activity resource types plus the `ActivityType` / `SportType` enums.
2
3use super::athlete::{MetaAthlete, SimpleAthlete};
4use super::common::{LatLng, Map, PhotosSummary, PolylineMap};
5use super::gear::SummaryGear;
6use super::segment::DetailedSegmentEffort;
7use chrono::{DateTime, Utc};
8use serde::{Deserialize, Serialize};
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct ActivityTotal {
12    pub count: Option<i32>,
13    pub distance: Option<f64>,
14    pub moving_time: Option<f64>,
15    pub elapsed_time: Option<f64>,
16    pub elevation_gain: Option<f64>,
17    pub achievement_count: Option<i32>,
18}
19
20#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct ActivityStats {
22    pub biggest_ride_distance: Option<f64>,
23    pub biggest_climb_elevation_gain: Option<f64>,
24    pub recent_ride_totals: Option<ActivityTotal>,
25    pub recent_run_totals: Option<ActivityTotal>,
26    pub recent_swim_totals: Option<ActivityTotal>,
27    pub ytd_ride_totals: Option<ActivityTotal>,
28    pub ytd_run_totals: Option<ActivityTotal>,
29    pub ytd_swim_totals: Option<ActivityTotal>,
30    pub all_ride_totals: Option<ActivityTotal>,
31    pub all_run_totals: Option<ActivityTotal>,
32    pub all_swim_totals: Option<ActivityTotal>,
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(rename_all = "PascalCase")]
37#[non_exhaustive]
38pub enum ActivityType {
39    AlpineSki,
40    BackcountrySki,
41    Canoeing,
42    Crossfit,
43    EBikeRide,
44    Elliptical,
45    Golf,
46    Handcycle,
47    Hike,
48    IceSkate,
49    InlineSkate,
50    Kayaking,
51    Kitesurf,
52    NordicSki,
53    Ride,
54    RockClimbing,
55    RollerSki,
56    Rowing,
57    Run,
58    Sail,
59    Skateboard,
60    Snowboard,
61    Snowshoe,
62    Soccer,
63    StairStepper,
64    StandUpPaddling,
65    Surfing,
66    Swim,
67    Velomobile,
68    VirtualRide,
69    VirtualRun,
70    Walk,
71    WeightTraining,
72    Wheelchair,
73    Windsurf,
74    Workout,
75    Yoga,
76    #[serde(other)]
77    Unknown,
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
81#[serde(rename_all = "PascalCase")]
82#[non_exhaustive]
83pub enum SportType {
84    AlpineSki,
85    BackcountrySki,
86    Badminton,
87    Canoeing,
88    Crossfit,
89    EBikeRide,
90    Elliptical,
91    EMountainBikeRide,
92    Golf,
93    GravelRide,
94    Handcycle,
95    HighIntensityIntervalTraining,
96    Hike,
97    IceSkate,
98    InlineSkate,
99    Kayaking,
100    Kitesurf,
101    MountainBikeRide,
102    NordicSki,
103    Pickleball,
104    Pilates,
105    Racquetball,
106    Ride,
107    RockClimbing,
108    RollerSki,
109    Rowing,
110    Run,
111    Sail,
112    Skateboard,
113    Snowboard,
114    Snowshoe,
115    Soccer,
116    Squash,
117    StairStepper,
118    StandUpPaddling,
119    Surfing,
120    Swim,
121    TableTennis,
122    Tennis,
123    TrailRun,
124    Velomobile,
125    VirtualRide,
126    VirtualRow,
127    VirtualRun,
128    Walk,
129    WeightTraining,
130    Wheelchair,
131    Windsurf,
132    Workout,
133    Yoga,
134    #[serde(other)]
135    Unknown,
136}
137
138#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
139pub struct Activity {
140    pub id: i64,
141    pub resource_state: u8,
142    pub external_id: Option<String>,
143    pub upload_id: Option<i64>,
144    pub athlete: SimpleAthlete,
145    pub name: String,
146    pub distance: f64,
147    pub moving_time: i32,
148    pub elapsed_time: i32,
149    pub total_elevation_gain: f64,
150    #[serde(rename = "type")]
151    pub activity_type: String,
152    pub sport_type: String,
153    pub start_date: String,
154    pub start_date_local: String,
155    pub timezone: String,
156    pub utc_offset: f64,
157    pub achievement_count: i32,
158    pub kudos_count: i32,
159    pub comment_count: i32,
160    pub athlete_count: i32,
161    pub photo_count: i32,
162    pub map: Map,
163    pub trainer: bool,
164    pub commute: bool,
165    pub manual: bool,
166    pub private: bool,
167    pub flagged: bool,
168    pub gear_id: Option<String>,
169    pub from_accepted_tag: Option<bool>,
170    pub average_speed: f64,
171    pub max_speed: f64,
172    pub device_watts: Option<bool>,
173    pub has_heartrate: bool,
174    pub pr_count: i32,
175    pub total_photo_count: i32,
176    pub has_kudoed: bool,
177    pub workout_type: Option<i32>,
178    pub description: Option<String>,
179    pub calories: Option<f64>,
180    pub segment_efforts: Option<Vec<SegmentEffort>>,
181}
182
183/// Placeholder held by [`Activity::segment_efforts`]. The richer
184/// [`DetailedSegmentEffort`](super::segment::DetailedSegmentEffort) is used
185/// elsewhere; the shape here is intentionally empty because this field is
186/// always returned empty or absent on the `GET /activities/{id}` endpoint
187/// unless `include_all_efforts=true` is set.
188#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
189pub struct SegmentEffort {}
190
191#[derive(Debug, Clone, Serialize)]
192pub struct CreateActivity {
193    pub name: String,
194    #[serde(skip_serializing_if = "Option::is_none")]
195    pub activity_type: Option<String>,
196    pub sport_type: String,
197    pub start_date_local: String,
198    pub elapsed_time: i32,
199    #[serde(skip_serializing_if = "Option::is_none")]
200    pub description: Option<String>,
201    #[serde(skip_serializing_if = "Option::is_none")]
202    pub distance: Option<f64>,
203    #[serde(skip_serializing_if = "Option::is_none")]
204    pub trainer: Option<i32>,
205    #[serde(skip_serializing_if = "Option::is_none")]
206    pub commute: Option<i32>,
207}
208
209#[derive(Default, Debug, Clone, Serialize, Deserialize)]
210pub struct UpdatableActivity {
211    pub commute: Option<bool>,
212    pub trainer: Option<bool>,
213    pub hide_from_home: Option<bool>,
214    pub description: Option<String>,
215    pub name: Option<String>,
216    #[deprecated(note = "Use sport_type instead")]
217    #[serde(default)]
218    pub r#type: Option<ActivityType>,
219    pub sport_type: Option<SportType>,
220    pub gear_id: Option<String>,
221}
222
223#[derive(Debug, Clone, Serialize, Deserialize)]
224pub struct SummaryActivity {
225    pub id: Option<i64>,
226    pub external_id: Option<String>,
227    pub upload_id: Option<i64>,
228    pub athlete: Option<MetaAthlete>,
229    pub name: Option<String>,
230    pub distance: Option<f32>,
231    pub moving_time: Option<i32>,
232    pub elapsed_time: Option<i32>,
233    pub total_elevation_gain: Option<f32>,
234    pub elev_high: Option<f32>,
235    pub elev_low: Option<f32>,
236    #[deprecated(note = "Use sport_type instead")]
237    #[serde(default)]
238    pub r#type: Option<ActivityType>,
239    pub sport_type: Option<SportType>,
240    pub start_date: Option<DateTime<Utc>>,
241    pub start_date_local: Option<DateTime<Utc>>,
242    pub timezone: Option<String>,
243    pub start_latlng: Option<LatLng>,
244    pub end_latlng: Option<LatLng>,
245    pub achievement_count: Option<i32>,
246    pub kudos_count: Option<i32>,
247    pub comment_count: Option<i32>,
248    pub athlete_count: Option<i32>,
249    pub photo_count: Option<i32>,
250    pub total_photo_count: Option<i32>,
251    pub map: Option<PolylineMap>,
252    pub trainer: Option<bool>,
253    pub commute: Option<bool>,
254    pub manual: Option<bool>,
255    pub private: Option<bool>,
256    pub flagged: Option<bool>,
257    pub workout_type: Option<i32>,
258    pub upload_id_str: Option<String>,
259    pub average_speed: Option<f32>,
260    pub max_speed: Option<f32>,
261    pub has_kudoed: Option<bool>,
262    pub hide_from_home: Option<bool>,
263    pub gear_id: Option<String>,
264    pub kilojoules: Option<f32>,
265    pub average_watts: Option<f32>,
266    pub device_watts: Option<bool>,
267    pub max_watts: Option<i32>,
268    pub weighted_average_watts: Option<i32>,
269}
270
271#[derive(Debug, Clone, Serialize, Deserialize)]
272pub struct DetailedActivity {
273    pub id: Option<i64>,
274    pub external_id: Option<String>,
275    pub upload_id: Option<i64>,
276    pub athlete: Option<MetaAthlete>,
277    pub name: Option<String>,
278    pub distance: Option<f32>,
279    pub moving_time: Option<i32>,
280    pub elapsed_time: Option<i32>,
281    pub total_elevation_gain: Option<f32>,
282    pub elev_high: Option<f32>,
283    pub elev_low: Option<f32>,
284    #[deprecated(note = "Use sport_type instead")]
285    #[serde(default)]
286    pub r#type: Option<ActivityType>,
287    pub sport_type: Option<SportType>,
288    pub start_date: Option<DateTime<Utc>>,
289    pub start_date_local: Option<DateTime<Utc>>,
290    pub timezone: Option<String>,
291    pub start_latlng: Option<LatLng>,
292    pub end_latlng: Option<LatLng>,
293    pub achievement_count: Option<i32>,
294    pub kudos_count: Option<i32>,
295    pub comment_count: Option<i32>,
296    pub athlete_count: Option<i32>,
297    pub photo_count: Option<i32>,
298    pub total_photo_count: Option<i32>,
299    pub map: Option<PolylineMap>,
300    pub trainer: Option<bool>,
301    pub commute: Option<bool>,
302    pub manual: Option<bool>,
303    pub private: Option<bool>,
304    pub flagged: Option<bool>,
305    pub workout_type: Option<i32>,
306    pub upload_id_str: Option<String>,
307    pub average_speed: Option<f32>,
308    pub max_speed: Option<f32>,
309    pub has_kudoed: Option<bool>,
310    pub hide_from_home: Option<bool>,
311    pub gear_id: Option<String>,
312    pub kilojoules: Option<f32>,
313    pub average_watts: Option<f32>,
314    pub device_watts: Option<bool>,
315    pub max_watts: Option<i32>,
316    pub weighted_average_watts: Option<i32>,
317    pub description: Option<String>,
318    pub photos: Option<PhotosSummary>,
319    pub gear: Option<SummaryGear>,
320    pub calories: Option<f32>,
321    pub segment_efforts: Option<Vec<DetailedSegmentEffort>>,
322    pub device_name: Option<String>,
323    pub embed_token: Option<String>,
324    pub splits_metric: Option<Vec<Split>>,
325    pub splits_standard: Option<Vec<Split>>,
326    pub laps: Option<Vec<Lap>>,
327    pub best_efforts: Option<Vec<DetailedSegmentEffort>>,
328}
329
330#[derive(Debug, Clone, Serialize, Deserialize)]
331pub struct MetaActivity {
332    pub id: Option<i64>,
333}
334
335#[derive(Debug, Clone, Serialize, Deserialize)]
336pub struct Split {
337    pub average_speed: Option<f32>,
338    pub distance: Option<f32>,
339    pub elapsed_time: Option<i32>,
340    pub elevation_difference: Option<f32>,
341    pub pace_zone: Option<i32>,
342    pub moving_time: Option<i32>,
343    pub split: Option<i32>,
344}
345
346#[derive(Debug, Clone, Serialize, Deserialize)]
347pub struct Lap {
348    pub id: Option<i64>,
349    pub activity: Option<MetaActivity>,
350    pub athlete: Option<MetaAthlete>,
351    pub average_cadence: Option<f32>,
352    pub average_speed: Option<f32>,
353    pub distance: Option<f32>,
354    pub elapsed_time: Option<i32>,
355    pub start_index: Option<i32>,
356    pub end_index: Option<i32>,
357    pub lap_index: Option<i32>,
358    pub max_speed: Option<f32>,
359    pub moving_time: Option<i32>,
360    pub name: Option<String>,
361    pub pace_zone: Option<i32>,
362    pub split: Option<i32>,
363    pub start_date: Option<DateTime<Utc>>,
364    pub start_date_local: Option<DateTime<Utc>>,
365    pub total_elevation_gain: Option<f32>,
366}