Implement the timestamp function

This commit is contained in:
Savanni D'Gerinel 2023-12-06 23:52:46 -05:00
parent 0e0d67a9ac
commit 83a4839b1d
4 changed files with 27 additions and 6 deletions

4
Cargo.lock generated
View File

@ -976,8 +976,6 @@ checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6"
name = "fitnesstrax" name = "fitnesstrax"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"chrono",
"chrono-tz",
"gio", "gio",
"glib", "glib",
"glib-build-tools 0.18.0", "glib-build-tools 0.18.0",
@ -1134,6 +1132,8 @@ dependencies = [
name = "ft-core" name = "ft-core"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"chrono",
"chrono-tz",
"dimensioned 0.8.0", "dimensioned 0.8.0",
"emseries", "emseries",
"serde 1.0.188", "serde 1.0.188",

View File

@ -7,8 +7,6 @@ edition = "2021"
[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-tz = { version = "0.8" }
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" ] }

View File

@ -6,6 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
chrono = { version = "0.4" }
chrono-tz = { version = "0.8" }
dimensioned = { version = "0.8", features = [ "serde" ] } dimensioned = { version = "0.8", features = [ "serde" ] }
emseries = { path = "../../emseries" } emseries = { path = "../../emseries" }
serde = { version = "1", features = [ "derive" ] } serde = { version = "1", features = [ "derive" ] }

View File

@ -69,7 +69,18 @@ pub enum TraxRecord {
impl Recordable for TraxRecord { impl Recordable for TraxRecord {
fn timestamp(&self) -> Timestamp { 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<String> { fn tags(&self) -> Vec<String> {
@ -86,6 +97,16 @@ mod test {
fn can_record_records() { fn can_record_records() {
let file = tempfile::NamedTempFile::new().expect("a temporary file"); let file = tempfile::NamedTempFile::new().expect("a temporary file");
let path = file.into_temp_path(); let path = file.into_temp_path();
let series: Series<TraxRecord> = Series::open(&path).unwrap(); let mut series: Series<TraxRecord> = 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);
} }
} }