This commit is contained in:
chaos 2024-11-20 13:47:34 +00:00
parent 215662e1c8
commit 4b7244e4b3
8 changed files with 268 additions and 414 deletions

373
Cargo.lock generated
View file

@ -2,15 +2,6 @@
# It is not intended for manual editing.
version = 4
[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]]
name = "android-tzdata"
version = "0.1.1"
@ -81,12 +72,6 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]]
name = "base64"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
[[package]]
name = "bitflags"
version = "2.6.0"
@ -129,28 +114,6 @@ dependencies = [
"windows-targets",
]
[[package]]
name = "chrono-tz"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd6dd8046d00723a59a2f8c5f295c515b9bb9a331ee4f8f3d4dd49e428acd3b6"
dependencies = [
"chrono",
"chrono-tz-build",
"phf",
"serde",
]
[[package]]
name = "chrono-tz-build"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e94fea34d77a245229e7746bd2beb786cd2a896f306ff491fb8cecb3074b10a7"
dependencies = [
"parse-zoneinfo",
"phf_codegen",
]
[[package]]
name = "clap"
version = "4.5.21"
@ -224,51 +187,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "darling"
version = "0.20.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.20.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn",
]
[[package]]
name = "darling_macro"
version = "0.20.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806"
dependencies = [
"darling_core",
"quote",
"syn",
]
[[package]]
name = "deranged"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4"
dependencies = [
"powerfmt",
"serde",
]
[[package]]
name = "dirs-next"
version = "2.0.0"
@ -296,18 +214,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "getrandom"
version = "0.2.15"
@ -319,18 +225,6 @@ dependencies = [
"wasi",
]
[[package]]
name = "hashbrown"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "hashbrown"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3"
[[package]]
name = "heck"
version = "0.5.0"
@ -343,12 +237,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc"
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "iana-time-zone"
version = "0.1.61"
@ -372,34 +260,6 @@ dependencies = [
"cc",
]
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "indexmap"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [
"autocfg",
"hashbrown 0.12.3",
"serde",
]
[[package]]
name = "indexmap"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da"
dependencies = [
"equivalent",
"hashbrown 0.15.1",
"serde",
]
[[package]]
name = "is-terminal"
version = "0.4.13"
@ -423,15 +283,6 @@ version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
[[package]]
name = "journal"
version = "0.1.0"
dependencies = [
"chrono",
"chrono-tz",
"serde",
]
[[package]]
name = "js-sys"
version = "0.3.72"
@ -478,12 +329,6 @@ version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "num-conv"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
[[package]]
name = "num-traits"
version = "0.2.19"
@ -499,59 +344,6 @@ version = "1.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
[[package]]
name = "parse-zoneinfo"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f2a05b18d44e2957b88f96ba460715e295bc1d7510468a2f3d3b44535d26c24"
dependencies = [
"regex",
]
[[package]]
name = "phf"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc"
dependencies = [
"phf_shared",
]
[[package]]
name = "phf_codegen"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a"
dependencies = [
"phf_generator",
"phf_shared",
]
[[package]]
name = "phf_generator"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0"
dependencies = [
"phf_shared",
"rand",
]
[[package]]
name = "phf_shared"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b"
dependencies = [
"siphasher",
]
[[package]]
name = "powerfmt"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]]
name = "prettytable-rs"
version = "0.10.0"
@ -580,17 +372,11 @@ name = "psychonaut_journal_cli"
version = "0.1.0"
dependencies = [
"chrono",
"chrono-tz",
"clap",
"journal",
"log",
"prettytable-rs",
"serde",
"serde_json",
"serde_with",
"string-error",
"termcolor",
"thiserror 2.0.3",
]
[[package]]
@ -602,21 +388,6 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
[[package]]
name = "redox_users"
version = "0.4.6"
@ -625,38 +396,9 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
dependencies = [
"getrandom",
"libredox",
"thiserror 1.0.69",
"thiserror",
]
[[package]]
name = "regex"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]]
name = "rustversion"
version = "1.0.18"
@ -701,54 +443,12 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_with"
version = "3.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e28bdad6db2b8340e449f7108f020b3b092e8583a9e3fb82713e1d4e71fe817"
dependencies = [
"base64",
"chrono",
"hex",
"indexmap 1.9.3",
"indexmap 2.6.0",
"serde",
"serde_derive",
"serde_json",
"serde_with_macros",
"time",
]
[[package]]
name = "serde_with_macros"
version = "3.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d846214a9854ef724f3da161b426242d8de7c1fc7de2f89bb1efcb154dca79d"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "siphasher"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d"
[[package]]
name = "string-error"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439558b73299d7afdf52c36399c3c812cca10fe5ca08429f38815df5bacf3ef7"
[[package]]
name = "strsim"
version = "0.11.1"
@ -777,31 +477,13 @@ dependencies = [
"winapi",
]
[[package]]
name = "termcolor"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"
dependencies = [
"winapi-util",
]
[[package]]
name = "thiserror"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
dependencies = [
"thiserror-impl 1.0.69",
]
[[package]]
name = "thiserror"
version = "2.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa"
dependencies = [
"thiserror-impl 2.0.3",
"thiserror-impl",
]
[[package]]
@ -815,48 +497,6 @@ dependencies = [
"syn",
]
[[package]]
name = "thiserror-impl"
version = "2.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "time"
version = "0.3.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885"
dependencies = [
"deranged",
"itoa",
"num-conv",
"powerfmt",
"serde",
"time-core",
"time-macros",
]
[[package]]
name = "time-core"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
[[package]]
name = "time-macros"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf"
dependencies = [
"num-conv",
"time-core",
]
[[package]]
name = "unicode-ident"
version = "1.0.13"
@ -952,15 +592,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"

View file

@ -7,16 +7,18 @@ edition = "2021"
name = "journal-cli"
path = "journal_cli/src/main.rs"
[lib]
name = "journal"
path = "journal/src/lib.rs"
[dependencies]
journal = { path = "./journal" }
chrono = { version = "0.4.38", features = ["serde"] }
chrono-tz = { version = "0.10.0", features = ["serde"] }
clap = { version = "4.5.21", features = ["derive", "env"] }
log = { version = "0.4.22", features = ["std", "serde"] }
prettytable-rs = "0.10.0"
serde = { version = "1.0.215", features = ["std", "derive", "serde_derive"] }
serde_json = "1.0.132"
serde_with = "3.11.0"
string-error = "0.1.0"
termcolor = "1.4.1"
thiserror = "2.0.3"
#serde_with = "3.11.0"
#string-error = "0.1.0"
#termcolor = "1.4.1"
#thiserror = "2.0.3"

View file

@ -75,7 +75,6 @@ pub fn ingestion_standard_deviation(
.expect("Custom Unit could not be found");
if custom_unit.estimate_standard_deviation.is_none() {
println!("{:?}", ingestion.estimate_standard_deviation);
return ingestion.estimate_standard_deviation;
};

View file

@ -44,6 +44,7 @@ pub struct Ingestion {
pub custom_unit_id: Option<i64>,
#[serde(rename = "administrationRoute")]
pub roa: AdministrationRoute,
pub consumer_name: Option<String>,
pub notes: String,
pub stomach_fullness: Option<String>,
}

View file

@ -1,21 +1,24 @@
use crate::args::Args;
use crate::utils::load_export_data;
use crate::utils::{
format_ingestion_dose, format_ingestion_roa, format_ingestion_time, load_export_data,
};
use journal;
use journal::helpers::{
ingestion_contains_estimate, ingestion_dose, ingestion_standard_deviation, ingestion_unit,
};
use journal::types::Experiences;
#[derive(Debug, Clone, clap::Args)]
#[derive(Debug, Clone, clap::Args)]
pub struct PrintExperienceArgs {
pub experience_title: String,
#[clap(long, env = "EXPORT_FILE")]
pub export_file: String,
pub experience_title: String,
#[clap(long, env = "EXPORT_FILE")]
pub export_file: String,
}
pub fn print_experience(_global_args: &Args, args: &PrintExperienceArgs) -> Result<(), Box<dyn std::error::Error>> {
let export_data = load_export_data(&args.export_file).expect("could not load export data");
pub fn print_experience(
_global_args: &Args,
args: &PrintExperienceArgs,
) -> Result<(), Box<dyn std::error::Error>> {
let export_data = load_export_data(&args.export_file).expect("could not load export data");
let experience = export_data
.experiences
@ -23,29 +26,19 @@ pub fn print_experience(_global_args: &Args, args: &PrintExperienceArgs) -> Resu
.expect("could not find experience");
for ingestion in experience.ingestions.iter() {
let contains_estimate = ingestion_contains_estimate(ingestion, &export_data.custom_units);
let standard_deviation = ingestion_standard_deviation(ingestion, &export_data.custom_units);
println!(
"{}: {}{}{}{}",
"{}|{}|{}|{}|{}",
ingestion.substance_name,
if contains_estimate { "~" } else { "" },
format!(
"{:.2}",
ingestion_dose(ingestion, &export_data.custom_units).unwrap()
)
.trim_end_matches(".00"),
if standard_deviation.is_some() {
format!(
"±{:.2}",
standard_deviation.unwrap()
)
} else {
"".to_string()
}
.trim_end_matches(".00"),
ingestion_unit(ingestion, &export_data.custom_units),
format_ingestion_dose(&ingestion, &export_data.custom_units),
format_ingestion_roa(&ingestion, &export_data.custom_units),
ingestion
.consumer_name
.clone()
.or(Some("default".to_string()))
.unwrap(),
format_ingestion_time(&ingestion)
)
}
Ok(())
}
Ok(())
}

View file

@ -1,8 +1,13 @@
use journal::{
helpers::{
ingestion_contains_estimate, ingestion_dose, ingestion_standard_deviation, ingestion_unit,
},
types::{CustomUnits, CustomUnitsType, Experience, ExportData, Ingestion},
};
use std::fs::File;
use journal::types::ExportData;
pub fn load_export_data(filename: &String) -> Result<ExportData, Box<dyn std::error::Error>> {
let file = File::open(filename)?;
pub fn load_export_data(filename: &String) -> Result<ExportData, Box<dyn std::error::Error>> {
let file = File::open(filename)?;
let export_data: ExportData = serde_json::from_reader(file)?;
@ -16,5 +21,117 @@ pub fn load_export_data(filename: &String) -> Result<ExportData, Box<dyn std::e
// .sort_by(|a, b| a.ingestion_time.cmp(&b.ingestion_time));
//}
Ok(export_data)
}
Ok(export_data)
}
pub fn format_experience_title(experience: &Experience) -> String {
format!("{}: {}", experience.title, experience.creation_time)
}
pub fn format_dose(
dose: Option<f64>,
unit: &String,
estimate: bool,
standard_deviation: Option<f64>,
) -> String {
if let Some(dose) = dose {
let estimate = if estimate { "~" } else { "" };
let standard_deviation = if let Some(standard_deviation) = standard_deviation {
format!("±{}", (standard_deviation * 100.0).round() / 100.0)
} else {
"".to_string()
};
let dose = (dose * 100.0).round() / 100.0;
format!("{estimate}{dose}{standard_deviation} {unit}")
} else {
format!("Unknown {unit}")
}
}
pub fn format_ingestion_dose(ingestion: &Ingestion, custom_units: &CustomUnitsType) -> String {
let dose = ingestion_dose(ingestion, custom_units);
let unit = ingestion_unit(ingestion, custom_units);
let standard_deviation = ingestion_standard_deviation(ingestion, custom_units);
if let Some(dose) = dose {
if let Some(custom_unit_id) = ingestion.custom_unit_id {
let estimate = if ingestion_contains_estimate(&ingestion, &custom_units) {
"~"
} else {
""
};
let custom_unit = custom_units
.get_by_id(custom_unit_id)
.expect("custom unit not found");
let canonical_dose =
format_dose(Some(dose), &unit, ingestion.is_estimate, standard_deviation);
let custom_unit_dose_per = format_dose(
Some(custom_unit.dose),
&custom_unit.original_unit,
custom_unit.is_estimate,
custom_unit.estimate_standard_deviation,
);
let custom_unit_dose = format_dose(
ingestion.dose,
&custom_unit.unit,
ingestion.is_estimate,
ingestion.estimate_standard_deviation,
);
format!("{estimate}{canonical_dose} ({custom_unit_dose_per} * {custom_unit_dose})")
} else {
format_dose(Some(dose), &unit, ingestion.is_estimate, standard_deviation)
}
} else {
"Unknown".to_string()
}
}
pub fn format_ingestion_time(ingestion: &Ingestion) -> String {
ingestion.ingestion_time.format("%a %I:%M %p").to_string()
}
pub fn format_ingestion_roa(ingestion: &Ingestion, custom_units: &CustomUnitsType) -> String {
if let Some(custom_unit_id) = ingestion.custom_unit_id {
let custom_unit = custom_units
.get_by_id(custom_unit_id)
.expect("custom unit not found");
format!("{:?} ({})", ingestion.roa, custom_unit.name)
} else {
format!("{:?}", ingestion.roa)
}
}
/*
def formatIngestionROA($customUnits; $substitutions):
. as $ingestion |
$ingestion.administrationRoute as $roa |
$ingestion.customUnitId as $customUnitId |
if
$customUnitId == null
then
$roaText
else
$customUnits | map(select(.id == $customUnitId))[0] as $customUnit |
"\($roaText) (\($customUnit.name))"
end;
def formatIngestionROA($customUnits): formatIngestionROA($customUnits; {});
def formatIngestionInfo:
. as $ingestionInfo |
formatDose(.dose; .unit; .isEstimate; .standardDeviation);
*/

View file

@ -0,0 +1,7 @@
[package]
name = "journal"
version = "0.1.0"
edition = "2021"
[dependencies]
serde = { version = "1.0.215", features = ["std", "derive", "serde_derive"] }

View file

@ -0,0 +1,104 @@
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use std::fmt::Display;
/// Some of the fields are renamed to make more clear what it is
#[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(rename = "time")]
pub ingestion_time: u64,
#[serde(rename = "creationDate")]
pub creation_time: u64,
pub dose: Option<f64>,
#[serde(rename = "units")]
pub unit: String,
#[serde(rename = "isDoseAnEstimate")]
pub is_estimate: bool,
#[serde(rename = "estimatedDoseStandardDeviation")]
pub estimate_standard_deviation: Option<f64>,
pub custom_unit_id: Option<i64>,
#[serde(rename = "administrationRoute")]
pub roa: AdministrationRoute,
pub consumer_name: Option<String>,
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(rename = "creationDate")]
pub creation_time: DateTime<Utc>,
#[serde(rename = "sortDate")]
pub modified_time: DateTime<Utc>,
pub ingestions: Vec<Ingestion>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SubstanceCompanion {
pub substance_name: String,
pub color: String,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CustomUnit {
pub id: i64,
pub substance_name: String,
pub name: String,
#[serde(rename = "creationDate")]
pub creation_time: DateTime<Utc>,
pub administration_route: AdministrationRoute,
pub dose: f64,
pub unit: String,
pub original_unit: String,
pub is_estimate: bool,
#[serde(rename = "estimatedDoseStandardDeviation")]
pub estimate_standard_deviation: Option<f64>,
pub is_archived: bool,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ExportData {
pub experiences: Vec<Experiences>,
pub substance_companions: Vec<SubstanceCompanion>,
pub custom_substances: Vec<CustomSubstance>,
pub custom_units: Vec<CustomUnits>,
}