From e5fb605816f4d22fecfba384f6e3da075bf96ef0 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Wed, 6 Dec 2023 23:32:56 -0500 Subject: [PATCH] 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(); + } +}