journal/journal_cli/src/display.rs

44 lines
1.1 KiB
Rust
Raw Normal View History

2024-11-21 13:58:29 +00:00
use journal::{
journal::JournalType,
types::{Consumer, Experience},
};
2024-11-20 19:15:07 +00:00
use crate::formatting::{format_ingestion_dose, format_ingestion_roa, format_ingestion_time};
pub fn print_ingestion_log(
2024-11-21 13:58:29 +00:00
journal: &JournalType,
2024-11-20 19:15:07 +00:00
experience: &Experience,
substance_filter: Option<&Vec<String>>,
consumer_filter: Option<&Vec<Consumer>>,
) {
2024-11-21 13:58:29 +00:00
for ingestion in journal
.get_experience_ingestions(experience.id)
.expect("could not find ingestions for experience")
.iter()
{
2024-11-20 19:15:07 +00:00
if let Some(substance_filter) = substance_filter {
if !substance_filter.contains(&ingestion.substance_name) {
continue;
}
}
if let Some(consumer_filter) = consumer_filter {
if !consumer_filter.contains(&ingestion.consumer) {
continue;
}
}
2024-11-21 07:20:46 +00:00
let custom_unit = journal.maybe_custom_unit(ingestion);
2024-11-21 13:58:29 +00:00
// println!("{:#?} {:#?}", &ingestion, &custom_unit);
2024-11-20 19:15:07 +00:00
println!(
"{}|{}|{}|{}|{}",
ingestion.substance_name,
2024-11-21 13:58:29 +00:00
format_ingestion_dose(&ingestion.dose, custom_unit.map(|f| &f.dose)),
format_ingestion_roa(ingestion, custom_unit),
2024-11-20 19:15:07 +00:00
ingestion.consumer,
format_ingestion_time(ingestion)
)
}
}