From 5b3972a906fad2a3a015bf2c7d0545603dc63eb1 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sat, 22 Feb 2025 05:45:42 +0100 Subject: [PATCH] Adds more to the graph --- weaponry/Cargo.toml | 4 +- weaponry/databases/weapons.db | Bin 28672 -> 28672 bytes weaponry/examples/.rustfmt.toml | 2 +- weaponry/examples/usage_scenario.rs | 108 +++++++++++++++--- .../equipement_advanced_repr.rs | 32 +++--- .../equipement_impl_basics.rs | 30 +---- .../weaponry_structs/equipement_structs.rs | 31 ++++- 7 files changed, 145 insertions(+), 62 deletions(-) diff --git a/weaponry/Cargo.toml b/weaponry/Cargo.toml index 291e2c0..d7f70a4 100644 --- a/weaponry/Cargo.toml +++ b/weaponry/Cargo.toml @@ -17,15 +17,13 @@ strum = { version = "0.27.0", features = ["derive"] } thiserror = "2.0.11" regex = "1.11.1" charming = { version = "0.4.0", features = [] } -# chrono = "0.4.39" -# leptos = { version = "0.7.7", features = ["csr"] } -# leptos-use = "0.15" [dev-dependencies] criterion = { version = "0.5" } regex = "1.11.1" pretty_assertions = "^1.4" logos = "^0.15" +clap = { version = "4.5.30", features = ["derive"] } [[bench]] name = "iter_creation" diff --git a/weaponry/databases/weapons.db b/weaponry/databases/weapons.db index 1ad235a301c6a91c31f9aefb22ec8b527a47bebb..2dd403301c8450cdaeccac0c60f736c15d055347 100644 GIT binary patch delta 221 zcmZp8z}WDBae_2s^F$eE#^#L)3+;J1|1xMZN74%Id=Mgr$+iocSelC9@*aai&rx4aRGX)r1xtS2@3BOq^^bA~kuQlgH%gA{v|byL@C}0b1%cd5fppW_PchssOK{ BKu`bx delta 181 zcmZp8z}WDBae_2s<3t%}#>R~a3+;KCDj2jGG8y=n@tg4-oy;d-rO4FG;>-M>xt}4E z=^2w6<4wkPMjeKO4EaC^0h1M-BQ^^-ZfE3Xc3|LE*X7_~*NWptef4vcB%pZU1KzS diff --git a/weaponry/examples/.rustfmt.toml b/weaponry/examples/.rustfmt.toml index 98b9e7f..9a9035c 100644 --- a/weaponry/examples/.rustfmt.toml +++ b/weaponry/examples/.rustfmt.toml @@ -1 +1 @@ -max_width = 278 +# max_width = 278 diff --git a/weaponry/examples/usage_scenario.rs b/weaponry/examples/usage_scenario.rs index f5f6174..4ccdb25 100644 --- a/weaponry/examples/usage_scenario.rs +++ b/weaponry/examples/usage_scenario.rs @@ -3,11 +3,24 @@ //! Test use case of a scenario //! //! +use charming::component::Legend; +use charming::element::Orient; +use clap::Parser; + +#[derive(Parser, Debug)] +/// Basic cli +pub struct ParserCLIArgs { + /// The path to save to. + pub path: Option, +} use charming::HtmlRenderer; use charming::{ Chart, - component::{Axis, DataZoom, DataZoomType, Feature, Grid, Restore, SaveAsImage, Title, Toolbox, ToolboxDataZoom, VisualMap, VisualMapType}, + component::{ + Axis, DataZoom, DataZoomType, Feature, Grid, Restore, SaveAsImage, Title, Toolbox, + ToolboxDataZoom, + }, element::{AxisType, Tooltip, Trigger}, series::Line, }; @@ -34,39 +47,100 @@ fn main() { #[allow(dead_code)] 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")))); + println!( + "Saved initial data as {}.html: {:?}", + save_path, + refined_list.write_csv(Path::new(&format!("{save_path}.csv"))) + ); } pub fn make_chart(data: &mut RefinedEquipementList) -> Chart { - data.inner.sort_by(|a, b| a.advanced.dps_safe.total_cmp(&b.advanced.dps_safe)); - let raw_data = data.inner.iter().map(|refeq| (refeq.inner.name.join(" "), refeq.advanced.dps_safe)); + data.inner + .sort_by(|a, b| a.advanced.dps_safe.total_cmp(&b.advanced.dps_safe)); + let raw_data = data.inner.iter().map(|refeq| { + ( + &refeq.advanced.display_name, + refeq.advanced.dps_safe, + refeq.advanced.max_damage_per_action, + refeq.advanced.armor_break_per_turn, + ) + }); let mut data_list = vec![]; - let mut value_list = vec![]; + let mut dps_safe = vec![]; + let mut max_damage_per_action = vec![]; + let mut armor_break_per_turn = vec![]; - raw_data.into_iter().for_each(|(date, value)| { - data_list.push(date); - value_list.push(value); + raw_data.into_iter().for_each(|(index, dps_s, dpa, abpt)| { + data_list.push(index); + dps_safe.push(dps_s); + max_damage_per_action.push(dpa); + armor_break_per_turn.push(abpt); }); Chart::new() - .title(Title::new().text("Gradient along the y axis").left("center")) + .title( + Title::new() + .text("Damage for all cross-gen products") + .left("center"), + ) + .legend( + Legend::new() + .left(10) + .top("middle") + .orient(Orient::Vertical) + .data(vec![ + "dps_safe", + "max_damage_per_action", + "armor_break_per_turn", + ]), + ) .tooltip(Tooltip::new().trigger(Trigger::Axis)) - .visual_map(VisualMap::new().show(false).type_(VisualMapType::Continuous).series_index(0).min(0).max(400)) - .x_axis(Axis::new().data(data_list.to_vec()).type_(AxisType::Category).boundary_gap(false)) + .x_axis( + Axis::new() + .data(data_list.to_vec()) + .type_(AxisType::Category), + ) .y_axis(Axis::new()) - .grid(Grid::new()) - .series(Line::new().show_symbol(false).data(value_list.clone())) - .data_zoom(DataZoom::new().type_(DataZoomType::Inside).start(0).end(100)) + .grid(Grid::new().contain_label(true)) + .series( + Line::new().data(dps_safe).name("dps_safe"), // .line_style(LineStyle::new().color("paleblue")), + ) + .series( + Line::new() + .data(max_damage_per_action) + .name("max_damage_per_action"), + ) + .series( + Line::new() + .data(armor_break_per_turn) + .name("armor_break_per_turn"), + ) + .data_zoom( + DataZoom::new() + .type_(DataZoomType::Inside) + .start(0) + .end(100), + ) .data_zoom(DataZoom::new().start(0).end(100)) - .toolbox(Toolbox::new().feature(Feature::new().data_zoom(ToolboxDataZoom::new().y_axis_index("none")).restore(Restore::new()).save_as_image(SaveAsImage::new()))) + .toolbox( + Toolbox::new().feature( + Feature::new() + .data_zoom(ToolboxDataZoom::new().y_axis_index("none")) + .restore(Restore::new()) + .save_as_image(SaveAsImage::new()), // .brush(Brush::new().type_(vec![BrushType::LineX, BrushType::Clear])), + ), + ) .tooltip(Tooltip::new().trigger(Trigger::Axis)) } fn render_data(data: &mut RefinedEquipementList, save_path: &str) { - let mut renderer = HtmlRenderer::new("MOOO", 1920, 1080).theme(charming::theme::Theme::Dark); + let mut renderer = + HtmlRenderer::new("Ravenous Balancing", 4000, 2000).theme(charming::theme::Theme::Dark); // Save the chart as HTML file. println!("Saving to {save_path}.html"); - renderer.save(&make_chart(data), format!("{save_path}.html")).unwrap(); + renderer + .save(&make_chart(data), format!("{save_path}.html")) + .unwrap(); } // // Load DB diff --git a/weaponry/src/weaponry_structs/equipement_advanced_repr.rs b/weaponry/src/weaponry_structs/equipement_advanced_repr.rs index 0e79e09..5221e02 100644 --- a/weaponry/src/weaponry_structs/equipement_advanced_repr.rs +++ b/weaponry/src/weaponry_structs/equipement_advanced_repr.rs @@ -97,7 +97,7 @@ pub struct AdvancedStats { pub display_name: String, pub damage_per_attack: f64, pub damage_per_turn: f64, - pub damage_per_action: f64, + pub max_damage_per_action: f64, pub armor_break_per_attack: f64, pub armor_break_per_turn: f64, pub armor_break_per_action: f64, @@ -107,8 +107,8 @@ pub struct AdvancedStats { pub expected_armor_break_per_turn: f64, /// Dps with two actions and 5 dices pub dps_safe: f64, - /// Dps with four actions and 11 dices - pub dps_unsafe: f64, + // /// Dps with four actions and 11 dices + // pub dps_unsafe: f64, // All other criterias are already in the inner as raw criterias } impl From<&InnerEquipementStats> for AdvancedStats { @@ -122,7 +122,7 @@ impl From<&InnerEquipementStats> for AdvancedStats { display_name: value.name.join(" "), damage_per_attack, damage_per_turn: damage_per_attack * 2., - damage_per_action: damage_per_attack / (value.action_cost as f64), + max_damage_per_action: damage_per_attack / (value.action_cost as f64), armor_break_per_attack, armor_break_per_turn: armor_break_per_attack * 2., armor_break_per_action: armor_break_per_attack / value.action_cost as f64, @@ -131,7 +131,7 @@ impl From<&InnerEquipementStats> for AdvancedStats { expected_armor_break_per_turn: (damage_per_attack + 6. - 8.) .min(armor_break_per_attack), dps_safe: damage_matrix.get_safe_dmg(value.action_cost), - dps_unsafe: damage_matrix.get_unsafe_dmg(value.action_cost), + // dps_unsafe: damage_matrix.get_unsafe_dmg(value.action_cost), damage_matrix, } } @@ -155,19 +155,21 @@ impl DamageMatrix { // TODO: This safe damage actually uses 5 dices * 2 instead of doing max(5 * 1 , 2 * 1 + 3 * 1) pub fn get_safe_dmg(&self, attack_cost: i8) -> f64 { let _ = attack_cost; - (self.damage_matrix[0] + self.damage_matrix[1] + self.damage_matrix[2]) / 3. + (self.get_damage(Precision::Low, DiceNumber::Few) + + self.get_damage(Precision::Medium, DiceNumber::Few) + + self.get_damage(Precision::High, DiceNumber::Few)) + / 3. } /// The "unsage" damage, as in, full dice, 2 attacks // TODO: This damages does max(Max dices * 1, 5 dices * 2), which might not be optimal pub fn get_unsafe_dmg(&self, attack_cost: i8) -> f64 { - match attack_cost { - 1 => f64::max( - self.get_safe_dmg(attack_cost) * 2., - (self.damage_matrix[0] + self.damage_matrix[1] + self.damage_matrix[2]) / 3., - ), - 2 => (self.damage_matrix[0] + self.damage_matrix[1] + self.damage_matrix[2]) / 3., - _ => 0., - } + f64::max( + self.get_safe_dmg(attack_cost) * 2., + (self.get_damage(Precision::Low, DiceNumber::Many) + + self.get_damage(Precision::Medium, DiceNumber::Many) + + self.get_damage(Precision::High, DiceNumber::Many)) + / 3., + ) } } impl Serialize for DamageMatrix { @@ -267,7 +269,7 @@ impl Precision { match self { Precision::High => 9, Precision::Medium => 6, - Precision::Low => 3, + Precision::Low => 4, } } } diff --git a/weaponry/src/weaponry_structs/equipement_impl_basics.rs b/weaponry/src/weaponry_structs/equipement_impl_basics.rs index 4e199f4..dc7870d 100644 --- a/weaponry/src/weaponry_structs/equipement_impl_basics.rs +++ b/weaponry/src/weaponry_structs/equipement_impl_basics.rs @@ -16,7 +16,10 @@ use crate::interfaces::{FilterFunction, Reportable}; use super::{ Equipement, InitialEquipementList, equipement_advanced_repr::RefinedEquipementList, - equipement_structs::{EqFinishing, EqMaterial, EqNature, EqShape, InnerEquipementStats}, + equipement_structs::{ + EqFinishing, EqMaterial, EqNature, EqShape, InnerEquipementStats, + filter_id_unique_and_right_category, + }, }; impl From for Equipement { @@ -31,7 +34,7 @@ impl From for Equipement { fn from(val: EqMaterial) -> Self { Self { stats: val.stats, - ..Default::default() + filter_function: FilterFunction::new(filter_id_unique_and_right_category()), } } } @@ -44,28 +47,7 @@ impl From for Equipement { // TODO : Checks that this is exactly desired behavious // :Also check for Cross Weapon/Armor contamination // Checks that the nature is compatible with the previous iteration - filter_function: FilterFunction::new(&|sel, lhs| { - // println!( - // "Trying to match {:?} with {:?}. {:?} {:?}", - // sel.name, lhs.name, sel.target, lhs.macro_category - // ); - - match (&sel.target, &lhs.macro_category) { - // There is a specific target and the part about to be added has a category - (Some(a), Some(b)) => { - // println!("{} {}", a, b); - a == b - } - // There is no target and the part about to be added is generic - // TODO: Unsound to have a generic nature, this should be caught at serialisation - (None, _) => panic!("The EqNature about to be added cannot be generic"), - // There is a specific target but the part about to be added is generic - // TODO: Impossible - (Some(_), None) => panic!("The part about to be added unto cannot be generic"), - // // There is restriction on the target and the recipient - // (None, Some(_)) => true, - } - }), + filter_function: FilterFunction::new(filter_id_unique_and_right_category()), } } } diff --git a/weaponry/src/weaponry_structs/equipement_structs.rs b/weaponry/src/weaponry_structs/equipement_structs.rs index 3fc66ce..15ceb05 100644 --- a/weaponry/src/weaponry_structs/equipement_structs.rs +++ b/weaponry/src/weaponry_structs/equipement_structs.rs @@ -33,18 +33,45 @@ pub struct Equipement { impl Default for Equipement { fn default() -> Self { Self { - filter_function: FilterFunction::new(default_filter()), + filter_function: FilterFunction::new(filter_id_unique()), stats: InnerEquipementStats::random_new(), } } } /// The default filter to use, usefull to implement a new filter function that also uses the default filter -pub(crate) fn default_filter() +pub(crate) fn filter_id_unique() -> &'static impl Fn(&InnerEquipementStats, &InnerEquipementStats) -> bool { &|self_, lhs| lhs.id.iter().all(|a| *a != self_.id[0]) } +/// Create a new filter function mandating the object be of the right category +pub(crate) fn filter_id_unique_and_right_category() +-> &'static impl Fn(&InnerEquipementStats, &InnerEquipementStats) -> bool { + &|sel, lhs| { + // println!( + // "Trying to match {:?} with {:?}. {:?} {:?}", + // sel.name, lhs.name, sel.target, lhs.macro_category + // ); + lhs.id.iter().all(|a| *a != sel.id[0]) + & match (&sel.target, &lhs.macro_category) { + // There is a specific target and the part about to be added has a category + (Some(a), Some(b)) => { + // println!("{} {}", a, b); + a == b + } + // There is no target and the part about to be added is generic + // TODO: Unsound to have a generic nature, this should be caught at serialisation + // TODO: Testing a generic anyway + (None, _) => true, // panic!("The EqNature about to be added cannot be generic"), + // There is a specific target but the part about to be added is generic + // TODO: Impossible + (Some(_), None) => panic!("The part about to be added unto cannot be generic"), + // // There is restriction on the target and the recipient + // (None, Some(_)) => true, + } + } +} impl FilterFunction { /// Generate a new filter // TODO: This static lifetime is basically telling us that an owned value is needed