-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathboil_off.rs
59 lines (52 loc) · 2.17 KB
/
boil_off.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use rustybeer::calculators::diluting::{calculate_new_gravity, calculate_new_volume};
use rustybeer::conversions::{RelativeDensity, RelativeDensityParser, ToMap, VolumeParser};
use rustybeer::measurements::Volume;
use structopt::{clap::ArgGroup, StructOpt};
#[derive(Debug, StructOpt)]
#[structopt(name = "boil_off", group = ArgGroup::with_name("desired").required(true))]
/// Calculates how much you need to dilute or boil down your wort volume to hit a certain gravity
pub struct BoilOffOptions {
#[structopt(short, long, parse(try_from_str = VolumeParser::parse))]
/// Wort Volume
wort_volume: Volume,
#[structopt(short, long, parse(try_from_str = RelativeDensityParser::parse))]
/// Current Gravity
current_gravity: RelativeDensity,
#[structopt(short, long, group = "desired", parse(try_from_str = RelativeDensityParser::parse))]
/// Desired Gravity
desired_gravity: Option<RelativeDensity>,
#[structopt(short, long, group = "desired", parse(try_from_str = VolumeParser::parse))]
/// Target Volume
target_volume: Option<Volume>,
}
pub fn calculate_and_print(boil_off_options: BoilOffOptions) {
println!("Wort Volume: {:#?}", boil_off_options.wort_volume.to_map());
println!(
"Current Gravity: {:#?}",
boil_off_options.current_gravity.to_map()
);
if let Some(desired_gravity) = boil_off_options.desired_gravity {
let new_volume = calculate_new_volume(
&boil_off_options.current_gravity,
&boil_off_options.wort_volume,
&desired_gravity,
);
println!("New Volume: {:#?}", new_volume.to_map());
println!(
"Difference: {:#?}",
(new_volume - boil_off_options.wort_volume).to_map()
);
}
if let Some(target_volume) = boil_off_options.target_volume {
let new_gravity = calculate_new_gravity(
&boil_off_options.current_gravity,
&boil_off_options.wort_volume,
&target_volume,
);
println!("New Gravity: {:#?}", new_gravity.to_map());
println!(
"Difference: {:#?}",
(new_gravity - boil_off_options.current_gravity).to_map()
);
}
}