add support for quanity
This commit is contained in:
+66
-27
@@ -1,3 +1,5 @@
|
|||||||
|
pub mod pdf;
|
||||||
|
|
||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
use colored::*;
|
use colored::*;
|
||||||
|
|
||||||
@@ -45,6 +47,10 @@ struct Args {
|
|||||||
/// Control terminal color output
|
/// Control terminal color output
|
||||||
#[arg(long, default_value = "auto")]
|
#[arg(long, default_value = "auto")]
|
||||||
color: ColorChoice,
|
color: ColorChoice,
|
||||||
|
|
||||||
|
/// Number of casts to make simultaneously
|
||||||
|
#[arg(short = 'n', long, default_value_t = 1)]
|
||||||
|
quantity: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@@ -57,7 +63,7 @@ fn main() {
|
|||||||
ColorChoice::Auto => {} // Respects standard stream capabilities (default)
|
ColorChoice::Auto => {} // Respects standard stream capabilities (default)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine density and target wet weight
|
// Determine density and target wet weight for a SINGLE cast
|
||||||
let density = args.density.or_else(|| {
|
let density = args.density.or_else(|| {
|
||||||
if (args.concentration - DEFAULT_CONCENTRATION).abs() < f64::EPSILON {
|
if (args.concentration - DEFAULT_CONCENTRATION).abs() < f64::EPSILON {
|
||||||
Some(DEFAULT_DENSITY)
|
Some(DEFAULT_DENSITY)
|
||||||
@@ -65,9 +71,11 @@ fn main() {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let target_wet_weight = density.map(|d| (args.volume / 1000.0) * d);
|
|
||||||
|
|
||||||
let (plaster_nominal, water_nominal) = match target_wet_weight {
|
let single_wet_weight = density.map(|d| (args.volume / 1000.0) * d);
|
||||||
|
let total_wet_weight = single_wet_weight.map(|w| w * args.quantity as f64);
|
||||||
|
|
||||||
|
let (plaster_total, water_total) = match total_wet_weight {
|
||||||
Some(wet_weight) => {
|
Some(wet_weight) => {
|
||||||
let plaster = wet_weight / (1.0 + (args.concentration / PERCENT));
|
let plaster = wet_weight / (1.0 + (args.concentration / PERCENT));
|
||||||
let water = plaster * (args.concentration / PERCENT);
|
let water = plaster * (args.concentration / PERCENT);
|
||||||
@@ -79,37 +87,56 @@ fn main() {
|
|||||||
// Output Header
|
// Output Header
|
||||||
println!("--- Plaster Calculation Parameters ---");
|
println!("--- Plaster Calculation Parameters ---");
|
||||||
println!(
|
println!(
|
||||||
"Volume: {}ml",
|
"Volume (per cast): {}ml",
|
||||||
format!("{}", args.volume).color(COLOR_PARAM).bold()
|
format!("{}", args.volume).color(COLOR_PARAM).bold()
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
"Concentration: {}g water per 100g plaster",
|
"Quantity: {}",
|
||||||
|
format!("{}", args.quantity).color(COLOR_PARAM).bold()
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"Concentration: {}g water per 100g plaster",
|
||||||
format!("{}", args.concentration).color(COLOR_PARAM).bold()
|
format!("{}", args.concentration).color(COLOR_PARAM).bold()
|
||||||
);
|
);
|
||||||
|
|
||||||
let density_str = density.map_or("Not provided/calculated".to_string(), |d| {
|
let density_str = density.map_or("Not provided/calculated".to_string(), |d| {
|
||||||
format!("{}g/L", format!("{}", d).color(COLOR_PARAM).bold())
|
format!("{}g/L", format!("{}", d).color(COLOR_PARAM).bold())
|
||||||
});
|
});
|
||||||
println!("Density: {}", density_str);
|
println!("Density: {}", density_str);
|
||||||
println!("--------------------------------------");
|
println!("--------------------------------------");
|
||||||
|
|
||||||
// Output Mixing Amounts and Target Weights
|
// Output Mixing Amounts and Target Weights
|
||||||
if let (Some(p_nom), Some(w_nom)) = (plaster_nominal, water_nominal) {
|
if let (Some(p_tot), Some(w_tot)) = (plaster_total, water_total) {
|
||||||
let p_slack = p_nom * (1.0 + SLACK);
|
let p_slack = p_tot * (1.0 + SLACK);
|
||||||
let w_slack = w_nom * (1.0 + SLACK);
|
let w_slack = w_tot * (1.0 + SLACK);
|
||||||
let dry_weight = p_nom * DRY_WEIGHT_MULTIPLIER;
|
|
||||||
|
let single_plaster = p_tot / args.quantity as f64;
|
||||||
|
let single_dry_weight = single_plaster * DRY_WEIGHT_MULTIPLIER;
|
||||||
|
let total_dry_weight = single_dry_weight * args.quantity as f64;
|
||||||
|
|
||||||
|
if args.quantity > 1 {
|
||||||
|
println!("Combined Mixing Amounts (for {} casts):", args.quantity);
|
||||||
|
println!(" Nominal Total:");
|
||||||
|
} else {
|
||||||
|
println!("Mixing Amounts:");
|
||||||
|
println!(" Nominal:");
|
||||||
|
}
|
||||||
|
|
||||||
println!("Mixing Amounts:");
|
|
||||||
println!(" Nominal:");
|
|
||||||
println!(
|
println!(
|
||||||
" Plaster: {}g",
|
" Plaster: {}g",
|
||||||
format!("{:.1}", p_nom).color(COLOR_PLASTER)
|
format!("{:.1}", p_tot).color(COLOR_PLASTER)
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
" Water: {}g",
|
" Water: {}g",
|
||||||
format!("{:.1}", w_nom).color(COLOR_WATER)
|
format!("{:.1}", w_tot).color(COLOR_WATER)
|
||||||
);
|
);
|
||||||
println!(" {:2}% Slack:", SLACK * PERCENT);
|
|
||||||
|
if args.quantity > 1 {
|
||||||
|
println!(" {:2}% Slack Total:", SLACK * PERCENT);
|
||||||
|
} else {
|
||||||
|
println!(" {:2}% Slack:", SLACK * PERCENT);
|
||||||
|
}
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
" Plaster: {}g",
|
" Plaster: {}g",
|
||||||
format!("{:.1}", p_slack).color(COLOR_PLASTER).bold()
|
format!("{:.1}", p_slack).color(COLOR_PLASTER).bold()
|
||||||
@@ -120,19 +147,31 @@ fn main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
println!("\nTarget Weights:");
|
println!("\nTarget Weights:");
|
||||||
println!(
|
if args.quantity > 1 {
|
||||||
" Wet Cast: {}g",
|
println!(" Individual Cast:");
|
||||||
format!("{:.1}", target_wet_weight.unwrap())
|
}
|
||||||
.color(COLOR_TARGET)
|
println!(
|
||||||
.bold()
|
" Wet Cast: {}g",
|
||||||
);
|
format!("{:.1}", single_wet_weight.unwrap()).color(COLOR_TARGET).bold()
|
||||||
println!(
|
);
|
||||||
" Dry Cast: {}g",
|
println!(
|
||||||
format!("{:.1}", dry_weight).color(COLOR_TARGET).bold()
|
" Dry Cast: {}g",
|
||||||
);
|
format!("{:.1}", single_dry_weight).color(COLOR_TARGET).bold()
|
||||||
|
);
|
||||||
|
if args.quantity > 1 {
|
||||||
|
println!(" Total Batch:");
|
||||||
|
println!(
|
||||||
|
" Wet Cast: {}g",
|
||||||
|
format!("{:.1}", total_wet_weight.unwrap()).color(COLOR_TARGET)
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
" Dry Cast: {}g",
|
||||||
|
format!("{:.1}", total_dry_weight).color(COLOR_TARGET)
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("{}",
|
println!("{}",
|
||||||
"Target weights and mixing amounts cannot be calculated. Please specify a density with `-d` for any non-70 concentration.".red()
|
"Target weights and mixing amounts cannot be calculated. Please specify a density with `-d` for any non-70 concentration.".red()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user