69 lines
2.0 KiB
Rust
69 lines
2.0 KiB
Rust
//! A module to handle stats disparity between all origins
|
|
|
|
use crate::{
|
|
stat_algo::{find_all_fits, Mode},
|
|
stat_structs::StatWeightList,
|
|
};
|
|
|
|
use anyhow::Result;
|
|
use clap::Args;
|
|
|
|
use crate::{
|
|
stat_io::{load_stat_records, AffName, CharacCharMatrix},
|
|
Config,
|
|
};
|
|
|
|
#[derive(Args, Debug, Clone)]
|
|
/// The configuration struct for the StatSolver
|
|
pub(crate) struct StatConfig {
|
|
// #[arg(default_value_t: "data/Book1.csv")]
|
|
/// The path where the data to analyse is
|
|
pub(crate) config_path: String,
|
|
/// The verbosity level
|
|
#[arg(short, long, default_value_t = false)]
|
|
pub(crate) verbosity: bool,
|
|
}
|
|
|
|
/// Main solver function, in charge of selecting algorithms and handling all program flow
|
|
pub(crate) fn stat_solver(args: &StatConfig, config: &Config) -> Result<()> {
|
|
let _ = config;
|
|
let mut statmatrix = load_stat_records(&args.config_path, args.clone()).unwrap();
|
|
solution_from_empty(&mut statmatrix).unwrap();
|
|
if args.verbosity {
|
|
println!("{:?}", statmatrix.print_weights());
|
|
println!("{:?}", statmatrix.print_solutions());
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
/// Find a solution from an empty solution (algo1)
|
|
fn solution_from_empty(statmatrix: &mut CharacCharMatrix) -> Result<()> {
|
|
// while statmatrix.not_filled() {}
|
|
let stats_desired = vec![
|
|
(AffName::F, 4),
|
|
(AffName::Ag, 3),
|
|
(AffName::Per, 3),
|
|
(AffName::Psy, 3),
|
|
(AffName::Int, 1),
|
|
(AffName::Vol, 1),
|
|
];
|
|
let stats_undesirable = vec![
|
|
(AffName::Int, 3),
|
|
(AffName::Vol, 3),
|
|
(AffName::Chr, 2),
|
|
(AffName::Chn, 2),
|
|
(AffName::F, 1),
|
|
(AffName::Ag, 1),
|
|
(AffName::Per, 1),
|
|
(AffName::Psy, 1),
|
|
];
|
|
|
|
let sw = StatWeightList::from(stats_desired).iter_cycle();
|
|
let nsw = StatWeightList::from(stats_undesirable).iter_cycle();
|
|
find_all_fits(statmatrix, sw, Mode::Positive).unwrap();
|
|
find_all_fits(statmatrix, nsw, Mode::Negative).unwrap();
|
|
// find_all_negative_fits(statmatrix, nsw).unwrap();
|
|
|
|
Ok(())
|
|
}
|