This commit is contained in:
chaos 2024-11-16 18:54:31 +00:00
parent 466b386bc7
commit 858e492b9c
11 changed files with 115 additions and 23 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@ export.json
dev dev
*.env *.env
/target /target
target

2
.rustfmt.toml Normal file
View file

@ -0,0 +1,2 @@
hard_tabs = true
use_field_init_shorthand = true

10
Cargo.lock generated
View file

@ -423,6 +423,15 @@ version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
[[package]]
name = "journal_types"
version = "0.1.0"
dependencies = [
"chrono",
"chrono-tz",
"serde",
]
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.72" version = "0.3.72"
@ -573,6 +582,7 @@ dependencies = [
"chrono", "chrono",
"chrono-tz", "chrono-tz",
"clap", "clap",
"journal_types",
"log", "log",
"prettytable-rs", "prettytable-rs",
"serde", "serde",

View file

@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
journal_types = { path = "./journal_types" }
chrono = { version = "0.4.38", features = ["serde"] } chrono = { version = "0.4.38", features = ["serde"] }
chrono-tz = { version = "0.10.0", features = ["serde"] } chrono-tz = { version = "0.10.0", features = ["serde"] }
clap = { version = "4.5.21", features = ["derive"] } clap = { version = "4.5.21", features = ["derive"] }

View file

@ -257,6 +257,8 @@ Usage:
} }
}(cli.errStream), }(cli.errStream),
), ),
gojq.WithFunction("stderr", 0, 0, gojq.WithFunction("stderr", 0, 0,
func(errStream io.Writer) func(any, []any) any { func(errStream io.Writer) func(any, []any) any {
return func(v any, _ []any) any { return func(v any, _ []any) any {

9
journal_types/Cargo.toml Normal file
View file

@ -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"] }

74
journal_types/src/lib.rs Normal file
View file

@ -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<Utc>,
#[serde(with = "ts_milliseconds", rename = "creationDate")]
pub creation_time: DateTime<Utc>,
pub dose: Option<f64>,
#[serde(rename = "isDoseAnEstimate")]
pub is_estimate: bool,
pub units: String,
pub custom_unit_id: Option<i64>,
#[serde(rename = "administrationRoute")]
pub roa: AdministrationRoute,
pub notes: String,
pub stomach_fullness: Option<String>,
}
#[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<Utc>,
#[serde(with = "ts_milliseconds", rename = "sortDate")]
pub modified_time: DateTime<Utc>,
pub ingestions: Vec<Ingestion>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ExportData {
//pub custom_substances: Vec<CustomSubstance>,
//pub custom_units: Vec<CustomUnit>,
pub experiences: Vec<Experience>,
}

View file

@ -1,6 +0,0 @@
[package]
name = "psychonaut_journal_types"
version = "0.1.0"
edition = "2021"
[dependencies]

View file

@ -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);
}
}

View file

@ -1,3 +1,17 @@
fn main() { use std::fs::File;
println!("Hello, world!"); use std::env;
use journal_types;
use serde_json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = 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(())
} }

View file

@ -1,3 +1,2 @@
def round(precision): def round(precision):
. * pow(10; precision) | round / pow(10; precision); . * pow(10; precision) | round / pow(10; precision);