From 6372d0bc244ddf26fb01390f2b94e61d7bd0ffa6 Mon Sep 17 00:00:00 2001 From: Gustav Eek Date: Thu, 2 Feb 2023 08:17:28 +0100 Subject: [PATCH] Src. Read skewness option from command line --- src/main.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) 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; -- 2.39.2