From f034dfcb8b8e42660125658de9b9dfb1a9f62e56 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Mon, 13 Nov 2023 08:52:10 -0500 Subject: [PATCH 1/7] Set up the basic data structures of a new fitnesstrax app. --- Cargo.lock | 22 ++++++++++++++- Cargo.toml | 1 + build.sh | 1 + fitnesstrax/Cargo.toml | 11 ++++++++ fitnesstrax/src/legacy.rs | 24 ++++++++++++++++ fitnesstrax/src/lib.rs | 6 ++++ fitnesstrax/src/main.rs | 3 ++ fitnesstrax/src/types.rs | 59 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 fitnesstrax/Cargo.toml create mode 100644 fitnesstrax/src/legacy.rs create mode 100644 fitnesstrax/src/lib.rs create mode 100644 fitnesstrax/src/main.rs create mode 100644 fitnesstrax/src/types.rs diff --git a/Cargo.lock b/Cargo.lock index f02baf5..1be57a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -756,6 +756,17 @@ dependencies = [ "typenum", ] +[[package]] +name = "dimensioned" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0b0a86c5d31c93238ff4b694fa31f3acdf67440770dc314c57d90e433914397" +dependencies = [ + "generic-array 0.14.7", + "num-traits", + "typenum", +] + [[package]] name = "displaydoc" version = "0.2.4" @@ -807,7 +818,7 @@ version = "0.6.0" dependencies = [ "chrono", "chrono-tz", - "dimensioned", + "dimensioned 0.7.0", "serde 1.0.188", "serde_derive", "serde_json", @@ -960,6 +971,15 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" +[[package]] +name = "fitnesstrax" +version = "0.1.0" +dependencies = [ + "chrono", + "dimensioned 0.8.0", + "emseries", +] + [[package]] name = "flate2" version = "1.0.27" diff --git a/Cargo.toml b/Cargo.toml index 1957e1d..0aed9b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "dashboard", "emseries", "file-service", + "fitnesstrax", "fluent-ergonomics", "geo-types", "gm-control-panel", diff --git a/build.sh b/build.sh index dcaed56..8311bd5 100755 --- a/build.sh +++ b/build.sh @@ -11,6 +11,7 @@ RUST_ALL_TARGETS=( "dashboard" "emseries" "file-service" + "fitnesstrax" "fluent-ergonomics" "geo-types" "gm-control-panel" diff --git a/fitnesstrax/Cargo.toml b/fitnesstrax/Cargo.toml new file mode 100644 index 0000000..da0b1bc --- /dev/null +++ b/fitnesstrax/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "fitnesstrax" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +chrono = { version = "0.4" } +dimensioned = {version = "0.8" } +emseries = { path = "../emseries" } diff --git a/fitnesstrax/src/legacy.rs b/fitnesstrax/src/legacy.rs new file mode 100644 index 0000000..0a79713 --- /dev/null +++ b/fitnesstrax/src/legacy.rs @@ -0,0 +1,24 @@ +use crate::types; + +#[cfg(test)] +mod test { + #[test] + fn read_a_legacy_set_rep_record() { + unimplemented!() + } + + #[test] + fn read_a_legacy_steps_record() { + unimplemented!() + } + + #[test] + fn read_a_legacy_time_distance_record() { + unimplemented!() + } + + #[test] + fn read_a_legacy_weight_record() { + unimplemented!() + } +} diff --git a/fitnesstrax/src/lib.rs b/fitnesstrax/src/lib.rs new file mode 100644 index 0000000..b591639 --- /dev/null +++ b/fitnesstrax/src/lib.rs @@ -0,0 +1,6 @@ +use chrono::NaiveDate; +use dimensioned::si; +use emseries::DateTimeTz; + +mod legacy; +mod types; diff --git a/fitnesstrax/src/main.rs b/fitnesstrax/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/fitnesstrax/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/fitnesstrax/src/types.rs b/fitnesstrax/src/types.rs new file mode 100644 index 0000000..0dfc3e5 --- /dev/null +++ b/fitnesstrax/src/types.rs @@ -0,0 +1,59 @@ +/// SetRep represents workouts like pushups or situps, which involve doing a "set" of a number of +/// actions, resting, and then doing another set. +pub struct SetRep { + /// I assume that a set/rep workout is only done once in a day. + date: NaiveDate, + /// Each set entry represents the number of times that the action was performed in a set. So, a + /// pushup workout that involved five sets would have five entries. Each entry would be x + /// number of pushups. A viable workout would be something like [6, 6, 4, 4, 5]. + sets: Vec, + comments: Option, +} + +/// The number of steps one takes in a single day. +pub struct Steps { + date: NaiveDate, + count: u32, +} + +/// TimeDistance represents workouts characterized by a duration and a distance travelled. These +/// sorts of workouts can occur many times a day, depending on how one records things. I might +/// record a single 30-km workout if I go on a long-distanec ride. Or I might record multiple 5km +/// workouts if I am out running errands. Distance and Duration are both optional because different +/// people have different priorities and may choose to measure different things. +pub struct TimeDistance { + /// The precise time (and the relevant timezone) of the workout. One of the edge cases that I + /// account for is that a ride which occurred at 11pm in one timezone would then count as 1am + /// if one moved two timezones to the east. This is kind of nonsensical from a human + /// perspective, so the DateTimeTz keeps track of the precise time in UTC, but also the + /// timezone in which the event was recorded. + datetime: DateTimeTz, + /// The distance travelled. This is optional because such a workout makes sense even without + /// the distance. + distance: Option>, + /// The duration of the workout, which is also optional. Some people may keep track of the + /// amount of distance travelled without tracking the duration. + duration: Option>, + comments: Option, +} + +/// A singular daily weight measurement. Weight changes slowly enough that it seems unlikely to +/// need to track more than a single weight in a day. +pub struct Weight { + date: NaiveDate, + weight: si::Kilogram, +} + +/// The unified data structure for all records that are part of the app. +pub enum TraxRecord { + BikeRide(TimeDistance), + Pushups, + Row(TimeDistance), + Run(TimeDistance), + Situps, + Squats, + Steps(Steps), + Swim(TimeDistance), + Walk(TimeDistance), + Weight(Weight), +} -- 2.44.1 From 0ac9bb74a694a2687493728b288a9a5c2375f138 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Sun, 19 Nov 2023 22:47:36 -0500 Subject: [PATCH 2/7] Set up the bare minimum of a GUI app, opening only a single window --- Cargo.lock | 7 +++++++ fitnesstrax/Cargo.toml | 21 ++++++++++++++++++++- fitnesstrax/src/main.rs | 35 +++++++++++++++++++++++++++++++++++ fitnesstrax/src/types.rs | 4 ++++ 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 1be57a2..b71ef7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -976,8 +976,15 @@ name = "fitnesstrax" version = "0.1.0" dependencies = [ "chrono", + "chrono-tz", "dimensioned 0.8.0", "emseries", + "gio", + "glib", + "glib-build-tools 0.18.0", + "gtk4", + "libadwaita", + "tokio", ] [[package]] diff --git a/fitnesstrax/Cargo.toml b/fitnesstrax/Cargo.toml index da0b1bc..85ba517 100644 --- a/fitnesstrax/Cargo.toml +++ b/fitnesstrax/Cargo.toml @@ -5,7 +5,26 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] +name = "fitnesstrax" +path = "src/lib.rs" + +[[bin]] +name = "fitnesstrax" +path = "src/main.rs" + [dependencies] +adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] } chrono = { version = "0.4" } -dimensioned = {version = "0.8" } +chrono-tz = { version = "0.8" } +dimensioned = { version = "0.8" } emseries = { path = "../emseries" } +gio = { version = "0.18" } +glib = { version = "0.18" } +gtk = { version = "0.7", package = "gtk4", features = [ "v4_8" ] } +tokio = { version = "1.34", features = [ "full" ] } + +[build-dependencies] +glib-build-tools = "0.18" + + diff --git a/fitnesstrax/src/main.rs b/fitnesstrax/src/main.rs index e7a11a9..3204d89 100644 --- a/fitnesstrax/src/main.rs +++ b/fitnesstrax/src/main.rs @@ -1,3 +1,38 @@ +use fitnesstrax; +use gtk::prelude::*; +use std::env; + +struct AppState {} + +struct AppWindow { + window: adw::ApplicationWindow, +} + fn main() { println!("Hello, world!"); + + let app = adw::Application::builder() + .application_id("com.luminescent-dreams.fitnesstrax") + .resource_base_path("/com/luminescent-dreams/fitnesstrax") + .build(); + + /* + let runtime = tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap(); + */ + + let app = adw::Application::builder() + .application_id("com.luminescent-dreams.fitnesstrax") + .resource_base_path("/com/luminescent-dreams/fitnesstrax") + .build(); + + app.connect_activate(move |app| { + let window = adw::ApplicationWindow::new(app); + window.present(); + }); + + let args: Vec = env::args().collect(); + ApplicationExtManual::run_with_args(&app, &args); } diff --git a/fitnesstrax/src/types.rs b/fitnesstrax/src/types.rs index 0dfc3e5..f09eab5 100644 --- a/fitnesstrax/src/types.rs +++ b/fitnesstrax/src/types.rs @@ -1,3 +1,7 @@ +use chrono::NaiveDate; +use dimensioned::si; +use emseries::DateTimeTz; + /// SetRep represents workouts like pushups or situps, which involve doing a "set" of a number of /// actions, resting, and then doing another set. pub struct SetRep { -- 2.44.1 From f9db002464174a07b143fc58e2cca35081518209 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Wed, 6 Dec 2023 23:32:33 -0500 Subject: [PATCH 3/7] Make the series open function accept anything that can be a path reference --- emseries/src/series.rs | 2 +- emseries/tests/test_io.rs | 52 +++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/emseries/src/series.rs b/emseries/src/series.rs index 71e089f..98f0cb1 100644 --- a/emseries/src/series.rs +++ b/emseries/src/series.rs @@ -42,7 +42,7 @@ where { /// Open a time series database at the specified path. `path` is the full path and filename for /// the database. - pub fn open(path: &str) -> Result, EmseriesReadError> { + pub fn open>(path: P) -> Result, EmseriesReadError> { let f = OpenOptions::new() .read(true) .append(true) diff --git a/emseries/tests/test_io.rs b/emseries/tests/test_io.rs index c599369..3f26f16 100644 --- a/emseries/tests/test_io.rs +++ b/emseries/tests/test_io.rs @@ -99,8 +99,8 @@ mod test { { let tmp_file = tempfile::NamedTempFile::new().expect("temporary path created"); let tmp_path = tmp_file.into_temp_path(); - let ts: Series = Series::open(&tmp_path.to_string_lossy()) - .expect("the time series should open correctly"); + let ts: Series = + Series::open(&tmp_path).expect("the time series should open correctly"); test(ts); } @@ -136,8 +136,8 @@ mod test { pub fn can_search_for_an_entry_with_exact_time() { run_test(|path| { let trips = mk_trips(); - let mut ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let mut ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); for trip in &trips[0..=4] { ts.put(trip.clone()).expect("expect a successful put"); @@ -157,8 +157,8 @@ mod test { pub fn can_get_entries_in_time_range() { run_test(|path| { let trips = mk_trips(); - let mut ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let mut ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); for trip in &trips[0..=4] { ts.put(trip.clone()).expect("expect a successful put"); @@ -186,8 +186,8 @@ mod test { let trips = mk_trips(); { - let mut ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let mut ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); for trip in &trips[0..=4] { ts.put(trip.clone()).expect("expect a successful put"); @@ -195,8 +195,8 @@ mod test { } { - let ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted( time_range( DateTimeTz(UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0).unwrap()).into(), @@ -220,8 +220,8 @@ mod test { let trips = mk_trips(); { - let mut ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let mut ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); for trip in &trips[0..=2] { ts.put(trip.clone()).expect("expect a successful put"); @@ -229,8 +229,8 @@ mod test { } { - let mut ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let mut ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted( time_range( DateTimeTz(UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0).unwrap()).into(), @@ -248,8 +248,8 @@ mod test { } { - let ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); let v: Vec<(&UniqueId, &BikeTrip)> = ts.search_sorted( time_range( DateTimeTz(UTC.with_ymd_and_hms(2011, 10, 31, 0, 0, 0).unwrap()).into(), @@ -273,8 +273,8 @@ mod test { run_test(|path| { let trips = mk_trips(); - let mut ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let mut ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); ts.put(trips[0].clone()).expect("expect a successful put"); ts.put(trips[1].clone()).expect("expect a successful put"); @@ -310,8 +310,8 @@ mod test { let trips = mk_trips(); { - let mut ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let mut ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); ts.put(trips[0].clone()).expect("expect a successful put"); ts.put(trips[1].clone()).expect("expect a successful put"); @@ -327,8 +327,8 @@ mod test { } { - let ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); let trips: Vec<(&UniqueId, &BikeTrip)> = ts.records().collect(); assert_eq!(trips.len(), 3); @@ -356,8 +356,8 @@ mod test { let trips = mk_trips(); { - let mut ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let mut ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); let trip_id = ts.put(trips[0].clone()).expect("expect a successful put"); ts.put(trips[1].clone()).expect("expect a successful put"); ts.put(trips[2].clone()).expect("expect a successful put"); @@ -368,8 +368,8 @@ mod test { } { - let ts: Series = Series::open(&path.to_string_lossy()) - .expect("expect the time series to open correctly"); + let ts: Series = + Series::open(&path).expect("expect the time series to open correctly"); let recs: Vec<(&UniqueId, &BikeTrip)> = ts.records().collect(); assert_eq!(recs.len(), 2); } -- 2.44.1 From e5fb605816f4d22fecfba384f6e3da075bf96ef0 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Wed, 6 Dec 2023 23:32:56 -0500 Subject: [PATCH 4/7] Create a test that verifies that a series can be made for a TraxRecord --- Cargo.lock | 3 +++ fitnesstrax/Cargo.toml | 22 +++++++++++++--------- fitnesstrax/src/types.rs | 30 +++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b71ef7f..f459e2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -764,6 +764,7 @@ checksum = "a0b0a86c5d31c93238ff4b694fa31f3acdf67440770dc314c57d90e433914397" dependencies = [ "generic-array 0.14.7", "num-traits", + "serde 1.0.188", "typenum", ] @@ -984,6 +985,8 @@ dependencies = [ "glib-build-tools 0.18.0", "gtk4", "libadwaita", + "serde 1.0.188", + "tempfile", "tokio", ] diff --git a/fitnesstrax/Cargo.toml b/fitnesstrax/Cargo.toml index 85ba517..8faa7f7 100644 --- a/fitnesstrax/Cargo.toml +++ b/fitnesstrax/Cargo.toml @@ -14,15 +14,19 @@ name = "fitnesstrax" path = "src/main.rs" [dependencies] -adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] } -chrono = { version = "0.4" } -chrono-tz = { version = "0.8" } -dimensioned = { version = "0.8" } -emseries = { path = "../emseries" } -gio = { version = "0.18" } -glib = { version = "0.18" } -gtk = { version = "0.7", package = "gtk4", features = [ "v4_8" ] } -tokio = { version = "1.34", features = [ "full" ] } +adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] } +chrono = { version = "0.4" } +chrono-tz = { version = "0.8" } +dimensioned = { version = "0.8", features = [ "serde" ] } +emseries = { path = "../emseries" } +gio = { version = "0.18" } +glib = { version = "0.18" } +gtk = { version = "0.7", package = "gtk4", features = [ "v4_8" ] } +serde = { version = "1", features = [ "derive" ] } +tokio = { version = "1.34", features = [ "full" ] } + +[dev-dependencies] +tempfile = "*" [build-dependencies] glib-build-tools = "0.18" diff --git a/fitnesstrax/src/types.rs b/fitnesstrax/src/types.rs index f09eab5..a85e3f3 100644 --- a/fitnesstrax/src/types.rs +++ b/fitnesstrax/src/types.rs @@ -1,6 +1,7 @@ use chrono::NaiveDate; use dimensioned::si; -use emseries::DateTimeTz; +use emseries::{DateTimeTz, Recordable, Timestamp}; +use serde::{Deserialize, Serialize}; /// SetRep represents workouts like pushups or situps, which involve doing a "set" of a number of /// actions, resting, and then doing another set. @@ -15,6 +16,7 @@ pub struct SetRep { } /// The number of steps one takes in a single day. +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Steps { date: NaiveDate, count: u32, @@ -25,6 +27,7 @@ pub struct Steps { /// record a single 30-km workout if I go on a long-distanec ride. Or I might record multiple 5km /// workouts if I am out running errands. Distance and Duration are both optional because different /// people have different priorities and may choose to measure different things. +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct TimeDistance { /// The precise time (and the relevant timezone) of the workout. One of the edge cases that I /// account for is that a ride which occurred at 11pm in one timezone would then count as 1am @@ -43,12 +46,14 @@ pub struct TimeDistance { /// A singular daily weight measurement. Weight changes slowly enough that it seems unlikely to /// need to track more than a single weight in a day. +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Weight { date: NaiveDate, weight: si::Kilogram, } /// The unified data structure for all records that are part of the app. +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub enum TraxRecord { BikeRide(TimeDistance), Pushups, @@ -61,3 +66,26 @@ pub enum TraxRecord { Walk(TimeDistance), Weight(Weight), } + +impl Recordable for TraxRecord { + fn timestamp(&self) -> Timestamp { + unimplemented!() + } + + fn tags(&self) -> Vec { + vec![] + } +} + +#[cfg(test)] +mod test { + use super::*; + use emseries::Series; + + #[test] + fn can_record_records() { + let file = tempfile::NamedTempFile::new().expect("a temporary file"); + let path = file.into_temp_path(); + let series: Series = Series::open(&path).unwrap(); + } +} -- 2.44.1 From 0e0d67a9ac60d2cf25a04e1bd4fdfdf59f586d29 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Wed, 6 Dec 2023 23:39:27 -0500 Subject: [PATCH 5/7] Split Fitnesstrax into two crates --- Cargo.lock | 14 ++++++++++---- Cargo.toml | 3 ++- fitnesstrax/{ => app}/Cargo.toml | 15 --------------- fitnesstrax/{ => app}/src/main.rs | 0 fitnesstrax/core/Cargo.toml | 16 ++++++++++++++++ fitnesstrax/{ => core}/src/legacy.rs | 0 fitnesstrax/{ => core}/src/lib.rs | 0 fitnesstrax/{ => core}/src/types.rs | 0 8 files changed, 28 insertions(+), 20 deletions(-) rename fitnesstrax/{ => app}/Cargo.toml (66%) rename fitnesstrax/{ => app}/src/main.rs (100%) create mode 100644 fitnesstrax/core/Cargo.toml rename fitnesstrax/{ => core}/src/legacy.rs (100%) rename fitnesstrax/{ => core}/src/lib.rs (100%) rename fitnesstrax/{ => core}/src/types.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index f459e2e..510d6f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -978,15 +978,11 @@ version = "0.1.0" dependencies = [ "chrono", "chrono-tz", - "dimensioned 0.8.0", - "emseries", "gio", "glib", "glib-build-tools 0.18.0", "gtk4", "libadwaita", - "serde 1.0.188", - "tempfile", "tokio", ] @@ -1134,6 +1130,16 @@ dependencies = [ "syn 2.0.37", ] +[[package]] +name = "ft-core" +version = "0.1.0" +dependencies = [ + "dimensioned 0.8.0", + "emseries", + "serde 1.0.188", + "tempfile", +] + [[package]] name = "fuchsia-cprng" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index 0aed9b0..73f671e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,8 @@ members = [ "dashboard", "emseries", "file-service", - "fitnesstrax", + "fitnesstrax/core", + "fitnesstrax/app", "fluent-ergonomics", "geo-types", "gm-control-panel", diff --git a/fitnesstrax/Cargo.toml b/fitnesstrax/app/Cargo.toml similarity index 66% rename from fitnesstrax/Cargo.toml rename to fitnesstrax/app/Cargo.toml index 8faa7f7..7c7b3b3 100644 --- a/fitnesstrax/Cargo.toml +++ b/fitnesstrax/app/Cargo.toml @@ -5,30 +5,15 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[lib] -name = "fitnesstrax" -path = "src/lib.rs" - -[[bin]] -name = "fitnesstrax" -path = "src/main.rs" - [dependencies] adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] } chrono = { version = "0.4" } chrono-tz = { version = "0.8" } -dimensioned = { version = "0.8", features = [ "serde" ] } -emseries = { path = "../emseries" } gio = { version = "0.18" } glib = { version = "0.18" } gtk = { version = "0.7", package = "gtk4", features = [ "v4_8" ] } -serde = { version = "1", features = [ "derive" ] } tokio = { version = "1.34", features = [ "full" ] } -[dev-dependencies] -tempfile = "*" - [build-dependencies] glib-build-tools = "0.18" - diff --git a/fitnesstrax/src/main.rs b/fitnesstrax/app/src/main.rs similarity index 100% rename from fitnesstrax/src/main.rs rename to fitnesstrax/app/src/main.rs diff --git a/fitnesstrax/core/Cargo.toml b/fitnesstrax/core/Cargo.toml new file mode 100644 index 0000000..6b838eb --- /dev/null +++ b/fitnesstrax/core/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "ft-core" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +dimensioned = { version = "0.8", features = [ "serde" ] } +emseries = { path = "../../emseries" } +serde = { version = "1", features = [ "derive" ] } + +[dev-dependencies] +tempfile = "*" + + diff --git a/fitnesstrax/src/legacy.rs b/fitnesstrax/core/src/legacy.rs similarity index 100% rename from fitnesstrax/src/legacy.rs rename to fitnesstrax/core/src/legacy.rs diff --git a/fitnesstrax/src/lib.rs b/fitnesstrax/core/src/lib.rs similarity index 100% rename from fitnesstrax/src/lib.rs rename to fitnesstrax/core/src/lib.rs diff --git a/fitnesstrax/src/types.rs b/fitnesstrax/core/src/types.rs similarity index 100% rename from fitnesstrax/src/types.rs rename to fitnesstrax/core/src/types.rs -- 2.44.1 From 83a4839b1d91ef3d21d3996a863a62212cae2d2f Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Wed, 6 Dec 2023 23:52:46 -0500 Subject: [PATCH 6/7] Implement the timestamp function --- Cargo.lock | 4 ++-- fitnesstrax/app/Cargo.toml | 2 -- fitnesstrax/core/Cargo.toml | 2 ++ fitnesstrax/core/src/types.rs | 25 +++++++++++++++++++++++-- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 510d6f2..5128401 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -976,8 +976,6 @@ checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" name = "fitnesstrax" version = "0.1.0" dependencies = [ - "chrono", - "chrono-tz", "gio", "glib", "glib-build-tools 0.18.0", @@ -1134,6 +1132,8 @@ dependencies = [ name = "ft-core" version = "0.1.0" dependencies = [ + "chrono", + "chrono-tz", "dimensioned 0.8.0", "emseries", "serde 1.0.188", diff --git a/fitnesstrax/app/Cargo.toml b/fitnesstrax/app/Cargo.toml index 7c7b3b3..4692329 100644 --- a/fitnesstrax/app/Cargo.toml +++ b/fitnesstrax/app/Cargo.toml @@ -7,8 +7,6 @@ edition = "2021" [dependencies] adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] } -chrono = { version = "0.4" } -chrono-tz = { version = "0.8" } gio = { version = "0.18" } glib = { version = "0.18" } gtk = { version = "0.7", package = "gtk4", features = [ "v4_8" ] } diff --git a/fitnesstrax/core/Cargo.toml b/fitnesstrax/core/Cargo.toml index 6b838eb..520b69c 100644 --- a/fitnesstrax/core/Cargo.toml +++ b/fitnesstrax/core/Cargo.toml @@ -6,6 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +chrono = { version = "0.4" } +chrono-tz = { version = "0.8" } dimensioned = { version = "0.8", features = [ "serde" ] } emseries = { path = "../../emseries" } serde = { version = "1", features = [ "derive" ] } diff --git a/fitnesstrax/core/src/types.rs b/fitnesstrax/core/src/types.rs index a85e3f3..091b5f2 100644 --- a/fitnesstrax/core/src/types.rs +++ b/fitnesstrax/core/src/types.rs @@ -69,7 +69,18 @@ pub enum TraxRecord { impl Recordable for TraxRecord { fn timestamp(&self) -> Timestamp { - unimplemented!() + match self { + TraxRecord::BikeRide(rec) => Timestamp::DateTime(rec.datetime.clone()), + TraxRecord::Pushups => unimplemented!(), + TraxRecord::Row(rec) => Timestamp::DateTime(rec.datetime.clone()), + TraxRecord::Run(rec) => Timestamp::DateTime(rec.datetime.clone()), + TraxRecord::Situps => unimplemented!(), + TraxRecord::Squats => unimplemented!(), + TraxRecord::Steps(rec) => Timestamp::Date(rec.date), + TraxRecord::Swim(rec) => Timestamp::DateTime(rec.datetime.clone()), + TraxRecord::Walk(rec) => Timestamp::DateTime(rec.datetime.clone()), + TraxRecord::Weight(rec) => Timestamp::Date(rec.date), + } } fn tags(&self) -> Vec { @@ -86,6 +97,16 @@ mod test { fn can_record_records() { let file = tempfile::NamedTempFile::new().expect("a temporary file"); let path = file.into_temp_path(); - let series: Series = Series::open(&path).unwrap(); + let mut series: Series = Series::open(&path).unwrap(); + + let record = TraxRecord::Steps(Steps { + date: NaiveDate::from_ymd_opt(2023, 1, 1).unwrap(), + count: 1000, + }); + + let id = series.put(record.clone()).unwrap(); + + let record_ = series.get(&id).unwrap(); + assert_eq!(record_, record); } } -- 2.44.1 From b9aa434278c7e94484dbace3de9c43b180d255ba Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Wed, 6 Dec 2023 23:55:12 -0500 Subject: [PATCH 7/7] Remove types that are not implemented yet I've gone *years* without these types, mostly because I wasn't doing these workouts. I can go longer. --- fitnesstrax/core/src/types.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/fitnesstrax/core/src/types.rs b/fitnesstrax/core/src/types.rs index 091b5f2..4c332d1 100644 --- a/fitnesstrax/core/src/types.rs +++ b/fitnesstrax/core/src/types.rs @@ -56,11 +56,8 @@ pub struct Weight { #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub enum TraxRecord { BikeRide(TimeDistance), - Pushups, Row(TimeDistance), Run(TimeDistance), - Situps, - Squats, Steps(Steps), Swim(TimeDistance), Walk(TimeDistance), @@ -71,11 +68,8 @@ impl Recordable for TraxRecord { fn timestamp(&self) -> Timestamp { match self { TraxRecord::BikeRide(rec) => Timestamp::DateTime(rec.datetime.clone()), - TraxRecord::Pushups => unimplemented!(), TraxRecord::Row(rec) => Timestamp::DateTime(rec.datetime.clone()), TraxRecord::Run(rec) => Timestamp::DateTime(rec.datetime.clone()), - TraxRecord::Situps => unimplemented!(), - TraxRecord::Squats => unimplemented!(), TraxRecord::Steps(rec) => Timestamp::Date(rec.date), TraxRecord::Swim(rec) => Timestamp::DateTime(rec.datetime.clone()), TraxRecord::Walk(rec) => Timestamp::DateTime(rec.datetime.clone()), -- 2.44.1