Sync your own workout data from your "Strong" app
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: remove rpe field from Set struct and related code

tolik518 2c4c49cb 2795cf08

+39 -17
+1 -7
strong-api-fetch/src/clickhouse_saver.rs
··· 26 26 pub set_nr: u32, 27 27 pub weight: f32, 28 28 pub reps: u32, 29 - pub rpe: f32, 30 29 } 31 30 32 31 pub struct ClickHouseSaver { ··· 95 94 set_nr, 96 95 weight: set.weight.unwrap_or(0.0), 97 96 reps: set.reps, 98 - rpe: set.rpe.unwrap_or(0.0), 99 97 }; 100 98 101 99 insert.write(&row).await?; ··· 107 105 println!("Workout {} imported successfully", workout.id); 108 106 Ok(()) 109 107 } 110 - } 111 - 112 - fn escape_string(s: &str) -> String { 113 - s.to_string() 114 - } 108 + }
+4 -1
strong-api-fetch/src/main.rs
··· 6 6 use std::fs; 7 7 use std::path::Path; 8 8 use strong_api_lib::data_transformer::{DataTransformer, Workout}; 9 - use strong_api_lib::json_response::MeasurementsResponse; 9 + use strong_api_lib::json_response::{MeasurementsResponse, UserResponse}; 10 10 use strong_api_lib::strong_api::{Includes, StrongApi}; 11 11 12 12 #[tokio::main] ··· 30 30 31 31 // Fetch user data with logs. 32 32 let user = strong_api.get_user("", 500, vec![Includes::Log]).await?; 33 + //let response_text = std::fs::read_to_string("response_1742332448.json")?; 34 + 35 + //let user: UserResponse = serde_json::from_str(&response_text)?; 33 36 34 37 println!( 35 38 "Measurements count: {}/{}",
+34 -9
strong-api-lib/src/data_transformer.rs
··· 8 8 pub id: String, 9 9 pub weight: Option<f32>, 10 10 pub reps: u32, 11 - pub rpe: Option<f32>, 12 11 } 13 12 14 13 #[derive(Debug)] ··· 163 162 .and_then(|s| s.parse::<u32>().ok()) 164 163 .unwrap_or(0); 165 164 166 - let rpe = cell_set 167 - .cells 168 - .iter() 169 - .find(|cell| cell.cell_type == "RPE") 170 - .and_then(|cell| cell.value.as_ref()) 171 - .and_then(|s| s.parse::<f32>().ok()); 172 - 173 165 Some(Set { 174 166 id: cell_set.id.clone(), 175 167 weight, 176 168 reps, 177 - rpe, 178 169 }) 179 170 } 180 171 ··· 188 179 parts[parts.len() - 1].to_string() 189 180 } 190 181 } 182 + 183 + #[cfg(test)] 184 + mod test { 185 + use crate::json_response::{CellSetGroupLinks, Link}; 186 + use super::*; 187 + 188 + #[test] 189 + fn test_can_get_workout_id_from_link() { 190 + let links = CellSetGroupLinks { 191 + measurement: Some( 192 + Link { 193 + href: "/api/users/0f9fc87d-0e60-46c6-b98d-9b1b69423218/measurements/a3f1d57d-da0e-466d-a691-c03695d39418".to_string() 194 + } 195 + ), 196 + }; 197 + 198 + assert_eq!( 199 + "a3f1d57d-da0e-466d-a691-c03695d39418".to_string(), 200 + DataTransformer::get_workout_id_from_link(&links) 201 + ); 202 + } 203 + 204 + #[test] 205 + fn test_can_get_workout_id_from_link_on_empty() { 206 + let links = CellSetGroupLinks { 207 + measurement: None, 208 + }; 209 + 210 + assert_eq!( 211 + "".to_string(), 212 + DataTransformer::get_workout_id_from_link(&links) 213 + ); 214 + } 215 + }