From 858e492b9c2c9c858f69c92d2e5dc5b3659ed744 Mon Sep 17 00:00:00 2001 From: chaos Date: Sat, 16 Nov 2024 18:54:31 +0000 Subject: [PATCH] update --- .gitignore | 1 + .rustfmt.toml | 2 + Cargo.lock | 10 ++++ Cargo.toml | 1 + gojq-extended/cli.go | 2 + journal_types/Cargo.toml | 9 ++++ journal_types/src/lib.rs | 74 +++++++++++++++++++++++++++++ psychonaut_journal_types/Cargo.toml | 6 --- psychonaut_journal_types/src/lib.rs | 14 ------ src/main.rs | 18 ++++++- tool/lib/numberLib.jq | 1 - 11 files changed, 115 insertions(+), 23 deletions(-) create mode 100644 .rustfmt.toml create mode 100644 journal_types/Cargo.toml create mode 100644 journal_types/src/lib.rs delete mode 100644 psychonaut_journal_types/Cargo.toml delete mode 100644 psychonaut_journal_types/src/lib.rs diff --git a/.gitignore b/.gitignore index b1c61a9..910d727 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ export.json dev *.env /target +target diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..b204247 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,2 @@ +hard_tabs = true +use_field_init_shorthand = true \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 8e99dfa..ce75abe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -423,6 +423,15 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "journal_types" +version = "0.1.0" +dependencies = [ + "chrono", + "chrono-tz", + "serde", +] + [[package]] name = "js-sys" version = "0.3.72" @@ -573,6 +582,7 @@ dependencies = [ "chrono", "chrono-tz", "clap", + "journal_types", "log", "prettytable-rs", "serde", diff --git a/Cargo.toml b/Cargo.toml index 6761f3c..0457bcd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +journal_types = { path = "./journal_types" } chrono = { version = "0.4.38", features = ["serde"] } chrono-tz = { version = "0.10.0", features = ["serde"] } clap = { version = "4.5.21", features = ["derive"] } diff --git a/gojq-extended/cli.go b/gojq-extended/cli.go index 3f337ce..06e774f 100644 --- a/gojq-extended/cli.go +++ b/gojq-extended/cli.go @@ -257,6 +257,8 @@ Usage: } }(cli.errStream), ), + + gojq.WithFunction("stderr", 0, 0, func(errStream io.Writer) func(any, []any) any { return func(v any, _ []any) any { diff --git a/journal_types/Cargo.toml b/journal_types/Cargo.toml new file mode 100644 index 0000000..6065ea1 --- /dev/null +++ b/journal_types/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "journal_types" +version = "0.1.0" +edition = "2021" + +[dependencies] +serde = { version = "1.0.215", features = ["std", "derive", "serde_derive"] } +chrono = { version = "0.4.38", features = ["serde"] } +chrono-tz = { version = "0.10.0", features = ["serde"] } \ No newline at end of file diff --git a/journal_types/src/lib.rs b/journal_types/src/lib.rs new file mode 100644 index 0000000..b636769 --- /dev/null +++ b/journal_types/src/lib.rs @@ -0,0 +1,74 @@ +use chrono::serde::ts_milliseconds; +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; +use std::fmt::Debug; +use std::fmt::Display; + +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(rename_all = "UPPERCASE")] +pub enum AdministrationRoute { + Oral, + Sublingual, + Buccal, + Insufflated, + Rectal, + Transdermal, + Subcutaneous, + Intramuscular, + Intravenous, + Smoked, + Inhaled, +} + +impl Display for AdministrationRoute { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] +pub struct Ingestion { + pub substance_name: String, + #[serde(with = "ts_milliseconds", rename = "time")] + pub ingestion_time: DateTime, + #[serde(with = "ts_milliseconds", rename = "creationDate")] + pub creation_time: DateTime, + pub dose: Option, + #[serde(rename = "isDoseAnEstimate")] + pub is_estimate: bool, + pub units: String, + pub custom_unit_id: Option, + #[serde(rename = "administrationRoute")] + pub roa: AdministrationRoute, + pub notes: String, + pub stomach_fullness: Option, +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] +pub struct CustomSubstance { + pub name: String, + pub description: String, + pub units: String, +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] +pub struct Experience { + pub title: String, + pub text: String, + #[serde(with = "ts_milliseconds", rename = "creationDate")] + pub creation_time: DateTime, + #[serde(with = "ts_milliseconds", rename = "sortDate")] + pub modified_time: DateTime, + pub ingestions: Vec, +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] +pub struct ExportData { + //pub custom_substances: Vec, + //pub custom_units: Vec, + pub experiences: Vec, +} diff --git a/psychonaut_journal_types/Cargo.toml b/psychonaut_journal_types/Cargo.toml deleted file mode 100644 index 2becb47..0000000 --- a/psychonaut_journal_types/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "psychonaut_journal_types" -version = "0.1.0" -edition = "2021" - -[dependencies] diff --git a/psychonaut_journal_types/src/lib.rs b/psychonaut_journal_types/src/lib.rs deleted file mode 100644 index b93cf3f..0000000 --- a/psychonaut_journal_types/src/lib.rs +++ /dev/null @@ -1,14 +0,0 @@ -pub fn add(left: u64, right: u64) -> u64 { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} diff --git a/src/main.rs b/src/main.rs index e7a11a9..9bd2d51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,17 @@ -fn main() { - println!("Hello, world!"); +use std::fs::File; +use std::env; +use journal_types; +use serde_json; + +fn main() -> Result<(), Box> { + let args: Vec = env::args().collect(); + let file = File::open(args[1].clone())?; + let mut export_data: journal_types::ExportData = + serde_json::from_reader(file)?; + export_data.experiences.sort_by(|a, b| a.modified_time.cmp(&b.modified_time)); + for experience in export_data.experiences.iter_mut() { + experience.ingestions.sort_by(|a,b| a.ingestion_time.cmp(&b.ingestion_time)); + } + println!("Hello, world! {:?}", export_data); + Ok(()) } diff --git a/tool/lib/numberLib.jq b/tool/lib/numberLib.jq index 0fd64e5..6aab3d0 100644 --- a/tool/lib/numberLib.jq +++ b/tool/lib/numberLib.jq @@ -1,3 +1,2 @@ def round(precision): . * pow(10; precision) | round / pow(10; precision); - \ No newline at end of file