51 lines
1.5 KiB
Rust
51 lines
1.5 KiB
Rust
use crate::args::Args;
|
|
use crate::utils::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)]
|
|
pub struct PrintExperienceArgs {
|
|
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");
|
|
|
|
let experience = export_data
|
|
.experiences
|
|
.get_by_title(&args.experience_title)
|
|
.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),
|
|
)
|
|
}
|
|
|
|
Ok(())
|
|
} |