update
This commit is contained in:
parent
466b386bc7
commit
858e492b9c
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@ export.json
|
|||
dev
|
||||
*.env
|
||||
/target
|
||||
target
|
||||
|
|
2
.rustfmt.toml
Normal file
2
.rustfmt.toml
Normal file
|
@ -0,0 +1,2 @@
|
|||
hard_tabs = true
|
||||
use_field_init_shorthand = true
|
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -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",
|
||||
|
|
|
@ -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"] }
|
||||
|
|
|
@ -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 {
|
||||
|
|
9
journal_types/Cargo.toml
Normal file
9
journal_types/Cargo.toml
Normal 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
74
journal_types/src/lib.rs
Normal 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>,
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
[package]
|
||||
name = "psychonaut_journal_types"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
|
@ -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);
|
||||
}
|
||||
}
|
18
src/main.rs
18
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<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(())
|
||||
}
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
def round(precision):
|
||||
. * pow(10; precision) | round / pow(10; precision);
|
||||
|
Loading…
Reference in a new issue