Create a test that verifies that a series can be made for a TraxRecord

This commit is contained in:
Savanni D'Gerinel 2023-12-06 23:32:56 -05:00
parent f9db002464
commit e5fb605816
3 changed files with 45 additions and 10 deletions

3
Cargo.lock generated
View File

@ -764,6 +764,7 @@ checksum = "a0b0a86c5d31c93238ff4b694fa31f3acdf67440770dc314c57d90e433914397"
dependencies = [ dependencies = [
"generic-array 0.14.7", "generic-array 0.14.7",
"num-traits", "num-traits",
"serde 1.0.188",
"typenum", "typenum",
] ]
@ -984,6 +985,8 @@ dependencies = [
"glib-build-tools 0.18.0", "glib-build-tools 0.18.0",
"gtk4", "gtk4",
"libadwaita", "libadwaita",
"serde 1.0.188",
"tempfile",
"tokio", "tokio",
] ]

View File

@ -14,15 +14,19 @@ name = "fitnesstrax"
path = "src/main.rs" path = "src/main.rs"
[dependencies] [dependencies]
adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] } adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] }
chrono = { version = "0.4" } chrono = { version = "0.4" }
chrono-tz = { version = "0.8" } chrono-tz = { version = "0.8" }
dimensioned = { version = "0.8" } dimensioned = { version = "0.8", features = [ "serde" ] }
emseries = { path = "../emseries" } emseries = { path = "../emseries" }
gio = { version = "0.18" } gio = { version = "0.18" }
glib = { version = "0.18" } glib = { version = "0.18" }
gtk = { version = "0.7", package = "gtk4", features = [ "v4_8" ] } gtk = { version = "0.7", package = "gtk4", features = [ "v4_8" ] }
tokio = { version = "1.34", features = [ "full" ] } serde = { version = "1", features = [ "derive" ] }
tokio = { version = "1.34", features = [ "full" ] }
[dev-dependencies]
tempfile = "*"
[build-dependencies] [build-dependencies]
glib-build-tools = "0.18" glib-build-tools = "0.18"

View File

@ -1,6 +1,7 @@
use chrono::NaiveDate; use chrono::NaiveDate;
use dimensioned::si; 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 /// SetRep represents workouts like pushups or situps, which involve doing a "set" of a number of
/// actions, resting, and then doing another set. /// actions, resting, and then doing another set.
@ -15,6 +16,7 @@ pub struct SetRep {
} }
/// The number of steps one takes in a single day. /// The number of steps one takes in a single day.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Steps { pub struct Steps {
date: NaiveDate, date: NaiveDate,
count: u32, 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 /// 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 /// 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. /// people have different priorities and may choose to measure different things.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct TimeDistance { pub struct TimeDistance {
/// The precise time (and the relevant timezone) of the workout. One of the edge cases that I /// 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 /// 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 /// 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. /// need to track more than a single weight in a day.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Weight { pub struct Weight {
date: NaiveDate, date: NaiveDate,
weight: si::Kilogram<f64>, weight: si::Kilogram<f64>,
} }
/// The unified data structure for all records that are part of the app. /// The unified data structure for all records that are part of the app.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum TraxRecord { pub enum TraxRecord {
BikeRide(TimeDistance), BikeRide(TimeDistance),
Pushups, Pushups,
@ -61,3 +66,26 @@ pub enum TraxRecord {
Walk(TimeDistance), Walk(TimeDistance),
Weight(Weight), Weight(Weight),
} }
impl Recordable for TraxRecord {
fn timestamp(&self) -> Timestamp {
unimplemented!()
}
fn tags(&self) -> Vec<String> {
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<TraxRecord> = Series::open(&path).unwrap();
}
}