diff --git a/.run_status.toml b/.run_status.toml index d94ea54..d6c2a0d 100644 --- a/.run_status.toml +++ b/.run_status.toml @@ -1,8 +1,8 @@ [last_run_clean] run_status = "Success" -lines_parsed = 133 -coverage = 23.38 +lines_parsed = 134 +coverage = 22.47 [last_run_clean.run_duration] -secs = 66 -nanos = 917039211 +secs = 70 +nanos = 324790325 diff --git a/badges/coverage.svg b/badges/coverage.svg index b1210c9..6f62b2a 100644 --- a/badges/coverage.svg +++ b/badges/coverage.svg @@ -1 +1 @@ -test-coverage: 23%test-coverage23% +test-coverage: 22%test-coverage22% diff --git a/cli_parser/src/lib.rs b/cli_parser/src/lib.rs index 1a04de7..d5e56d2 100644 --- a/cli_parser/src/lib.rs +++ b/cli_parser/src/lib.rs @@ -4,6 +4,7 @@ use clap::{Args, Parser, Subcommand}; use config::{ + analysis::AnalysisConfig, graph::GraphConfig, make::{ HELP_BLOCK_SELECTION, HELP_BUILD_TARGET_LIST, HELP_VERBOSITY_LEVEL, MakeTargets, @@ -42,8 +43,8 @@ pub enum Commands { Make(MakeConfig), /// Make all graphs Graphs(GraphConfig), - // /// Generate analysis data - // Analysis(AnalysisConfig) + /// Generate analysis data + Analysis(AnalysisConfig), } #[derive(Debug, Args)] @@ -64,6 +65,8 @@ pub struct ConfigArgs { #[derive(Deserialize)] /// The config struct, holding all runtime information pub struct Config { + /// Config specific for data generation + pub data_generation: Datagen, /// Config specific for the classes table generation pub classes: Classes, /// Config for all the tables @@ -83,6 +86,13 @@ pub struct Classes { pub end: String, } +#[derive(Deserialize)] +/// The data generation configuration +pub struct Datagen { + /// Where to find the data generation database + pub database: String, +} + // The make structs #[derive(Args, Debug, Clone)] diff --git a/config/src/analysis.rs b/config/src/analysis.rs new file mode 100644 index 0000000..8e5ca1f --- /dev/null +++ b/config/src/analysis.rs @@ -0,0 +1,54 @@ +// Workspace: config +// File: config/src/graph.rs +//! The inner config for the analysis module +//! + +use clap::{Parser, ValueEnum}; + +#[derive(Parser, Debug)] +/// Basic analisys CLI +pub struct AnalysisConfig { + #[arg(help = format!("The target to perform an analysis on [{:?}]", AnalysisTarget::value_variants()))] + /// The analysis target + pub target: AnalysisTarget, + + /// The path to save to. + pub path: Option, + /// Wether to generate shapes + #[arg(short('S'), long, default_value_t)] + pub no_shapes: bool, + /// Wether to generate materials + #[arg(short, long)] + pub materials: Option, + /// Wether to generate all natures + #[arg(short('N'), long)] + pub no_natures: bool, + /// Wether to generate all finishing + #[arg(short, long, default_value_t = false)] + pub finishing: bool, + #[arg(long, default_value_t = String::from("safe"))] + /// What function to sort by + pub sort: String, + // An html export path -h or -o + // A csv export path -c or --csv + // A presort --sort + // A prefilter with some filters ? + // - weapons + // - shields + // - armors + // - damage + // Data manipulation ?? + // - decimate + // - average per category +} + +#[derive(ValueEnum, Clone, Debug)] +/// The type of analysis to perform +pub enum AnalysisTarget { + /// Analysis over weapons + Weapon, + /// Analysis over armors + Armors, + /// Analysis over shields + Shields, +} diff --git a/config/src/lib.rs b/config/src/lib.rs index 94b3c35..a09949f 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -7,6 +7,7 @@ #![warn(missing_docs, clippy::missing_docs_in_private_items)] // Internal Modules +pub mod analysis; pub mod graph; pub mod make; pub mod statsolver; diff --git a/helper_config.toml b/helper_config.toml index 305c592..d77bfaf 100644 --- a/helper_config.toml +++ b/helper_config.toml @@ -1,3 +1,8 @@ +[data_generation] +# This value should be overwriten by a relative path +database = "../ravenous-tools/weaponry/databases/weapons.db" + + [classes] header = '''\begin{}[ presep = 0pt, postsep = 0pt, diff --git a/ravenous-tools/Cargo.toml b/ravenous-tools/Cargo.toml index b2609e0..0494e55 100644 --- a/ravenous-tools/Cargo.toml +++ b/ravenous-tools/Cargo.toml @@ -11,6 +11,7 @@ cli_parser = {path = "../cli_parser"} # config = {path = "../config"} stats = {path = "../stats"} make = {path = "../make"} +weaponry = {path = "../weaponry"} anyhow = "1.0.95" clap = { version = "4.5.28", features = ["derive"] } diff --git a/ravenous-tools/src/main.rs b/ravenous-tools/src/main.rs index 6ec40bf..b2d5faa 100644 --- a/ravenous-tools/src/main.rs +++ b/ravenous-tools/src/main.rs @@ -10,6 +10,7 @@ use graphs::make_graphs; use make::make_pdf; use stats::stat_solver; use tablegen::table_gen; +use weaponry::analysis::launch_analysis; // External imports use anyhow::{Context, Result}; @@ -31,6 +32,7 @@ fn main() -> Result<()> { Commands::Stats(args) => stat_solver(&args, &config), Commands::Make(args) => make_pdf(&args, &config), Commands::Graphs(args) => make_graphs(&args, &config), + Commands::Analysis(args) => Ok(launch_analysis(&args, &config)?), // Not using anyhow but a custom error } } diff --git a/weaponry/Cargo.toml b/weaponry/Cargo.toml index 43e3a6f..3a99bfc 100644 --- a/weaponry/Cargo.toml +++ b/weaponry/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.0" edition = "2024" [dependencies] +config = {path = "../config"} +cli_parser = {path = "../cli_parser"} more_fields = {path ="../more_fields"} comfy-table = "7.1.4" csv = "1.3.1" diff --git a/weaponry/src/analysis.rs b/weaponry/src/analysis.rs new file mode 100644 index 0000000..9a6d6f8 --- /dev/null +++ b/weaponry/src/analysis.rs @@ -0,0 +1,160 @@ +// Workspace: weaponry +// File: weaponry/src/analysis.rs +//! The one stop shop for analysis + +use std::{cmp::Ordering, path::Path}; + +use cli_parser::Config; +use config::analysis::AnalysisConfig; + +use crate::{ + error::FatalEquipementError, + interfaces::{Reportable, Scenario, ToAnalysis, ToCSV, ToTex}, + weaponry_structs::{ + CrossRecipeScenario, RefinedEquipement, RefinedEquipementList, + equipement_scenario::ConfigEquipementScenario, + }, +}; + +/// Launch the analysis of the selected data and export it to html for human processing +pub fn launch_analysis(args: &AnalysisConfig, config: &Config) -> Result<(), FatalEquipementError> { + match args.target { + config::analysis::AnalysisTarget::Weapon => create_graphs( + args, + config, + Box::new(|e: &RefinedEquipement| { + e.inner.category_base.as_ref().is_some_and(|v| { + !matches!(v, crate::weaponry_structs::WeaponBaseShape::Shields) + && !matches!(v, crate::weaponry_structs::WeaponBaseShape::Armors) + }) + }), + ), + config::analysis::AnalysisTarget::Armors => create_graphs( + args, + config, + Box::new(|e: &RefinedEquipement| { + e.inner + .category_base + .as_ref() + .is_some_and(|v| matches!(v, crate::weaponry_structs::WeaponBaseShape::Armors)) + }), + ), + config::analysis::AnalysisTarget::Shields => create_graphs( + args, + config, + Box::new(|e: &RefinedEquipement| { + e.inner + .category_base + .as_ref() + .is_some_and(|v| matches!(v, crate::weaponry_structs::WeaponBaseShape::Shields)) + }), + ), + } + Ok(()) +} + +/// Create all graphs with +fn create_graphs(args: &AnalysisConfig, config: &Config, filter: DynamicFilterType) { + let save_path = args.path.clone().unwrap_or("data/first_data".into()); + let scenarios = CrossRecipeScenario::new_with_config(ConfigEquipementScenario { + table_name: "Equipements".into(), + db_path: config.data_generation.database.clone(), + shape: (!args.no_shapes).then_some(()), + materials: args.materials, + nature: (!args.no_natures).then_some(()), + finishing: args.finishing.then_some(()), + }) + .unwrap(); + + let mut refined_list = scenarios + .generate_refined_recipes() + .unwrap() + // .inner_filter(|e| (e.advanced.max_damage_per_attack > 0.)) + .inner_filter(filter); + + match cmd_to_filter(&args.sort) { + Ok(cmd) => { + refined_list.inner_sort(cmd); + } + Err(FatalEquipementError::CLIParseError(a)) => { + println!("Argument incorrect '{a}'. Ignoring the sort.") + } + Err(e) => panic!("{e}"), + } + // if args.html_export{} + refined_list.write_html(&save_path).unwrap(); + + // if args.csv_export{} + // export_as_csv(&refined_list, &save_path); + + // if args.tex_export{} + export_as_tex(&refined_list, &save_path); +} + +#[allow(dead_code)] +/// Export as a csv a refine equipement list +/// +/// Rarely used and likely on it's way to deprecation +fn export_as_csv(refined_list: &RefinedEquipementList, save_path: &str) { + println!("{}", refined_list.get_report(Some("Refined List"))); + println!( + "Saved initial data as {}.html: {:?}", + save_path, + refined_list.write_csv(Path::new(&format!("{save_path}.csv"))) + ); +} +/// Export as a tex file in the given directory +/// +/// Generic function dispatching any specific demand to different functions +fn export_as_tex(refined_list: &RefinedEquipementList, save_path: &str) { + println!("{}", refined_list.to_tex()); // TexType + // println!( + // "Saved initial data as {}.html: {:?}", + // save_path, + // refined_list.write_csv(Path::new(&format!("{save_path}.csv"))) + // ); +} + +/// A dynamic filtertype, as a boxed function over two equipement references +// #[allow(dead_code)] +type DynamicSortType = Box Ordering>; + +/// A dynamic filter type +type DynamicFilterType = Box bool>; + +/// Create a filter from a user typed filter +/// +/// This informal implementation function as a mini language, +/// without any form of formalism, consistency or fixed API +fn cmd_to_filter(og_entry: &str) -> Result { + let (category, entry) = if og_entry.starts_with("cat+") { + (true, og_entry.split_at(4).1) + } else { + (false, og_entry) + }; + + macro_rules! return_if_starts_with { + ($iden:ident) => { + if stringify!($iden).starts_with(entry) { + return match category { + true => Ok(Box::new(crate::sort_by_cat_then!($iden))), + false => Ok(Box::new(crate::sort_by!($iden))), + }; + }; + }; + } + return_if_starts_with!(max_damage_per_attack); + return_if_starts_with!(armor_break_per_attack); + return_if_starts_with!(expected_armor_break_per_attack); + return_if_starts_with!(avg_damage_2a_safe); + return_if_starts_with!(avg_damage_2a_huge_hit); + return_if_starts_with!(speed); + return_if_starts_with!(scenario_damage); + return_if_starts_with!(defensive); + return_if_starts_with!(earlygame_sustained_damage_per_turn); + return_if_starts_with!(midgame_sustained_damage_per_turn); + return_if_starts_with!(endgame_sustained_damage_per_turn); + return_if_starts_with!(variance); + return_if_starts_with!(variance_pct); + Err(FatalEquipementError::CLIParseError(og_entry.to_string())) +} diff --git a/weaponry/src/lib.rs b/weaponry/src/lib.rs index 840bc6c..d21aa92 100644 --- a/weaponry/src/lib.rs +++ b/weaponry/src/lib.rs @@ -7,10 +7,12 @@ #![warn(missing_docs, clippy::missing_docs_in_private_items)] #![feature(iter_intersperse, generic_arg_infer)] +pub mod analysis; mod database; pub mod error; pub mod export; pub mod interfaces; +#[macro_use] pub mod weaponry_structs; /// Signals the function running is unfinished diff --git a/weaponry/src/weaponry_structs/equipement_advanced_repr.rs b/weaponry/src/weaponry_structs/equipement_advanced_repr.rs index 87e6575..0c6ed8c 100644 --- a/weaponry/src/weaponry_structs/equipement_advanced_repr.rs +++ b/weaponry/src/weaponry_structs/equipement_advanced_repr.rs @@ -18,7 +18,7 @@ use crate::{ add_field_to_chart, error::FatalEquipementError, export::{initial_chart, initial_plot_chart}, - interfaces::{RecipeCollection, RefinedList, ToAnalysis, ToTex}, + interfaces::{RecipeCollection, RefinedList, ToAnalysis}, weaponry_structs::{ Equipement, InitialEquipementList, equipement_structs::InnerEquipementStats, @@ -60,13 +60,6 @@ impl Deref for RefinedEquipementList { // Just a checkmark impl RefinedList for RefinedEquipementList {} -impl ToTex for RefinedEquipementList { - fn to_tex(&self) -> String { - // TODO[!] : Export everything to one tsv - // : This export is only supposed to be the final export of a pseudo recipes book - todo!() - } -} impl ToAnalysis for RefinedEquipementList { type InnerData = RefinedEquipement; diff --git a/weaponry/src/weaponry_structs/equipement_impl_io.rs b/weaponry/src/weaponry_structs/equipement_impl_io.rs index 4db5645..acafc60 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_io.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_io.rs @@ -3,7 +3,7 @@ //! All implementation IO specific (mainly export and serde) use super::equipement_advanced_repr::RefinedEquipementList; -use crate::interfaces::ToCSV; +use crate::interfaces::{ToCSV, ToTex}; use std::path::Path; impl ToCSV for RefinedEquipementList { @@ -16,7 +16,13 @@ impl ToCSV for RefinedEquipementList { } } -// impl To +impl ToTex for RefinedEquipementList { + // Nom & \rotbx{Rareté} & \rotbx{Dégâts} & + & \rotbx{R.Max} & \rotbx{Armr.B} & \rotbx{Protbx} & \rotbx{Int.} & \rotbx{Deux M} & \rotbx{Une M} & \rotbx{Esq.} & \rotbx{Parr.} & \rotbx{Vitesse} & \rotbx{Discr.} & \rotbx{Catégorie} & \rotbx{Modes} & \rotbx{Spécial} \\ + fn to_tex(&self) -> String { + self.inner.iter().for_each(|m| println!("{:?}", m.inner)); + todo!() + } +} #[cfg(test)] mod test { diff --git a/weaponry/src/weaponry_structs/mod.rs b/weaponry/src/weaponry_structs/mod.rs index c35a0a7..21051c9 100644 --- a/weaponry/src/weaponry_structs/mod.rs +++ b/weaponry/src/weaponry_structs/mod.rs @@ -15,6 +15,7 @@ // #[global_allocator] // static GLOBAL: Jemalloc = Jemalloc; +#[macro_use] mod equipement_advanced_repr; mod equipement_advanced_tools; mod equipement_fields;