Adds a part of CLI & export
This commit is contained in:
parent
3b94b71782
commit
30057dd7cf
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="122" height="18" role="img" aria-label="test-coverage: 23%"><title>test-coverage: 23%</title><linearGradient id="bms-53a22d886a16ba1d" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-53a22d886a16ba1d"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-53a22d886a16ba1d)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#97ca00"/><rect width="122" height="18" fill="url(#bms-53a22d886a16ba1d)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="445" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="770">test-coverage</text><text x="445" y="130" transform="scale(.1)" fill="#fff" textLength="770">test-coverage</text><text aria-hidden="true" x="1035" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">23%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">23%</text></g></svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="122" height="18" role="img" aria-label="test-coverage: 22%"><title>test-coverage: 22%</title><linearGradient id="bms-a6f73baf2b37a671" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-a6f73baf2b37a671"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-a6f73baf2b37a671)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#97ca00"/><rect width="122" height="18" fill="url(#bms-a6f73baf2b37a671)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="445" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="770">test-coverage</text><text x="445" y="130" transform="scale(.1)" fill="#fff" textLength="770">test-coverage</text><text aria-hidden="true" x="1035" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">22%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">22%</text></g></svg>
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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<String>,
|
||||
/// 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<usize>,
|
||||
/// 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,
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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"] }
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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<dyn FnMut(&RefinedEquipement, &RefinedEquipement) -> Ordering>;
|
||||
|
||||
/// A dynamic filter type
|
||||
type DynamicFilterType = Box<dyn FnMut(&RefinedEquipement) -> 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<DynamicSortType, FatalEquipementError> {
|
||||
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()))
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
// #[global_allocator]
|
||||
// static GLOBAL: Jemalloc = Jemalloc;
|
||||
|
||||
#[macro_use]
|
||||
mod equipement_advanced_repr;
|
||||
mod equipement_advanced_tools;
|
||||
mod equipement_fields;
|
||||
|
|
|
|||
Loading…
Reference in New Issue