From: Gustav Eek Date: Thu, 2 Feb 2023 07:17:28 +0000 (+0100) Subject: Src. Read skewness option from command line X-Git-Tag: v.0.3~3 X-Git-Url: https://git.g-eek.se/?a=commitdiff_plain;h=6372d0bc244ddf26fb01390f2b94e61d7bd0ffa6;p=ranknauto.git Src. Read skewness option from command line --- diff --git a/src/main.rs b/src/main.rs index a802abe..9ad1ea6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,12 +2,15 @@ //! //! SPDX-License-Identifier: GPL-3.0-or-later +// use std::env; // Replaced by clap::Parser stuff use std::io; // bring flush() into scope with `use std::io::Write` use std::io::prelude::*; // Bring `std::io::BufRead` in scope use statrs::distribution::{Exp, LogNormal, ContinuousCDF}; // Continuous needed for pdf // use statrs::statistics::Distribution; // use statrs::prec; +use clap::Parser; + const DEBUG: bool = false; fn input() -> Vec { @@ -91,8 +94,38 @@ fn lognormal(n: i32) -> Vec { normalize(prio) } +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] + +/// Rank N' Auto, automatic normalized ranking + +struct Args { + + /// Ranking distribution skewness + #[arg(short)] + skewness: Option, +} fn main() { + let args = Args::parse(); + + // let mut skew = 1.0; + + if DEBUG { eprintln!("Arguments: {:?}", args) } + + // Implement this with *match*, the non concise way, so that + // people understand. + + let skew = match args.skewness { + None => 1.0, + Some(a) => + if a == "light" {0.5} + else if a == "moderate" {1.0} + else if a == "heavy" {2.0} + else {1.0}, + }; + + if DEBUG { eprintln!("Finally a skewness: {}", skew) } let ranked: Vec = input(); let num = ranked.len() as i32;