update
This commit is contained in:
parent
12b76f3a90
commit
aa8e5e0266
|
@ -1,8 +1,7 @@
|
||||||
use chrono::{DateTime, TimeZone, Utc};
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
use crate::types::{
|
use crate::types::{
|
||||||
Consumer, CustomUnit, Dose, Estimation, Experience, ExportFormat, Ingestion, StandardDeviation,
|
CustomUnit, Experience, ExportFormat, Ingestion,
|
||||||
Unit,
|
Unit,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
use std::ops::{Add, Mul};
|
use std::ops::{Add, Mul};
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||||
|
#[derive(Default)]
|
||||||
pub enum Estimation {
|
pub enum Estimation {
|
||||||
Precise,
|
#[default]
|
||||||
|
Precise,
|
||||||
Estimate,
|
Estimate,
|
||||||
StandardDeviation(StandardDeviation),
|
StandardDeviation(StandardDeviation),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Estimation {
|
|
||||||
fn default() -> Self {
|
|
||||||
Estimation::Precise
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(PartialEq, Default, Debug, Copy, Clone)]
|
#[derive(PartialEq, Default, Debug, Copy, Clone)]
|
||||||
pub struct StandardDeviation {
|
pub struct StandardDeviation {
|
||||||
|
@ -46,7 +43,7 @@ impl Add<&Estimation> for Estimation {
|
||||||
Estimation::StandardDeviation(deviation)
|
Estimation::StandardDeviation(deviation)
|
||||||
}
|
}
|
||||||
(_, Estimation::StandardDeviation(deviation)) => {
|
(_, Estimation::StandardDeviation(deviation)) => {
|
||||||
Estimation::StandardDeviation(deviation.clone())
|
Estimation::StandardDeviation(*deviation)
|
||||||
}
|
}
|
||||||
(Estimation::Estimate, _) | (_, Estimation::Estimate) => Estimation::Estimate,
|
(Estimation::Estimate, _) | (_, Estimation::Estimate) => Estimation::Estimate,
|
||||||
(Estimation::Precise, Estimation::Precise) => Estimation::Precise,
|
(Estimation::Precise, Estimation::Precise) => Estimation::Precise,
|
||||||
|
@ -83,7 +80,7 @@ impl Mul<&Estimation> for Estimation {
|
||||||
Estimation::StandardDeviation(deviation)
|
Estimation::StandardDeviation(deviation)
|
||||||
}
|
}
|
||||||
(_, Estimation::StandardDeviation(deviation)) => {
|
(_, Estimation::StandardDeviation(deviation)) => {
|
||||||
Estimation::StandardDeviation(deviation.clone())
|
Estimation::StandardDeviation(*deviation)
|
||||||
}
|
}
|
||||||
(Estimation::Estimate, _) | (_, Estimation::Estimate) => Estimation::Estimate,
|
(Estimation::Estimate, _) | (_, Estimation::Estimate) => Estimation::Estimate,
|
||||||
(Estimation::Precise, Estimation::Precise) => Estimation::Precise,
|
(Estimation::Precise, Estimation::Precise) => Estimation::Precise,
|
||||||
|
@ -99,17 +96,17 @@ mod tests {
|
||||||
fn is() {
|
fn is() {
|
||||||
let deviation = StandardDeviation(Deviation::default());
|
let deviation = StandardDeviation(Deviation::default());
|
||||||
|
|
||||||
assert_eq!(Precise.is_precise(), true);
|
assert!(Precise.is_precise());
|
||||||
assert_eq!(Precise.is_estimate(), false);
|
assert!(!Precise.is_estimate());
|
||||||
assert_eq!(Precise.is_standard_deviation(), false);
|
assert!(!Precise.is_standard_deviation());
|
||||||
|
|
||||||
assert_eq!(Estimate.is_precise(), false);
|
assert!(!Estimate.is_precise());
|
||||||
assert_eq!(Estimate.is_estimate(), true);
|
assert!(Estimate.is_estimate());
|
||||||
assert_eq!(Estimate.is_standard_deviation(), false);
|
assert!(!Estimate.is_standard_deviation());
|
||||||
|
|
||||||
assert_eq!(deviation.is_precise(), false);
|
assert!(!deviation.is_precise());
|
||||||
assert_eq!(deviation.is_estimate(), true);
|
assert!(deviation.is_estimate());
|
||||||
assert_eq!(deviation.is_standard_deviation(), true);
|
assert!(deviation.is_standard_deviation());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -26,7 +26,7 @@ pub fn parse_consumer_filter(consumer_filter: Option<Vec<String>>) -> Option<Vec
|
||||||
consumer = "default".to_string();
|
consumer = "default".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
consumers.push(Consumer::from(consumer));
|
consumers.push(Consumer::from(consumer.as_str()));
|
||||||
}
|
}
|
||||||
Some(consumers)
|
Some(consumers)
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ pub fn format_ingestion_dose(dose: Option<&Dose>, unit: &Unit) -> String {
|
||||||
|
|
||||||
let dose_per_unit = format_ingestion_dose(unit.dose.as_ref(), &ingestion_unit);
|
let dose_per_unit = format_ingestion_dose(unit.dose.as_ref(), &ingestion_unit);
|
||||||
|
|
||||||
let custom_unit_dose = format_ingestion_dose(Some(&dose), &unit_unit);
|
let custom_unit_dose = format_ingestion_dose(Some(dose), &unit_unit);
|
||||||
|
|
||||||
format!("{ingestion_dose} ({dose_per_unit} * {custom_unit_dose})")
|
format!("{ingestion_dose} ({dose_per_unit} * {custom_unit_dose})")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue