From 6526d164514899346f409e44ba452736a275306f Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Wed, 26 Feb 2025 05:26:12 +0100 Subject: [PATCH] Adds sub plots ? --- weaponry/benches/iter_creation.rs | 58 --------- weaponry/src/export.rs | 110 ++++++++++++------ .../equipement_advanced_repr.rs | 85 +++++++++++++- .../equipement_advanced_tools.rs | 13 +-- 4 files changed, 163 insertions(+), 103 deletions(-) diff --git a/weaponry/benches/iter_creation.rs b/weaponry/benches/iter_creation.rs index 7ca9b5b..801cb45 100644 --- a/weaponry/benches/iter_creation.rs +++ b/weaponry/benches/iter_creation.rs @@ -50,61 +50,3 @@ criterion_group! { targets= criterion_benchmark } criterion_main!(benches); - -// TODO: Add to a How to add new Lists - -// #[derive(Clone)] -// struct Equipo { -// stats: InnerStats, -// } - -// impl Equipo { -// fn newish(i: u8) -> Self { -// let mut stats = InnerStats::default(); -// stats.id = i; -// Equipo { stats } -// } -// } - -// struct ListStatic { -// inner: Vec, -// } -// struct ListParIter { -// inner: Vec, -// } - -// impl RecipeCollection for ListStatic { -// type Recipes = Equipo; - -// fn combine_all(&mut self, other: G) -// where -// G: RecipeCollection, -// { -// todo!() -// } - -// fn inner(&self) -> Vec { -// self.inner.clone() -// } - -// fn from_vectored(list: Vec) -> Self { -// Self { inner: list } -// } -// } - -// impl Combineable for Equipo { -// type Inner = InnerStats; - -// fn clone_combinable_part(&self) -> Self::Inner { -// self.stats.clone() -// } - -// fn add_to_self(&self, rhs: T) -> Self -// where -// T: Combineable, -// { -// Equipo { -// stats: self.clone_combinable_part() + rhs.clone_combinable_part(), -// } -// } -// } diff --git a/weaponry/src/export.rs b/weaponry/src/export.rs index 1bb8a72..6b87b9f 100644 --- a/weaponry/src/export.rs +++ b/weaponry/src/export.rs @@ -4,6 +4,12 @@ //! //! Mostly graphs and csv auto conversion +use charming::{ + Chart, + component::{self, Axis, Grid, Title}, + element::{Tooltip, Trigger}, +}; + /// A very complex macro created to add criterias to the graph /// without repeating self explanatory parameter names in strings /// @@ -85,57 +91,93 @@ macro_rules! add_field_to_chart { } /// Generate a generic graph, ready to be filled with data -pub fn initial_chart(chart_name: &str) -> charming::Chart { - charming::Chart::new() - .title( - charming::component::Title::new() - .text(chart_name) - .left("center"), - ) +pub fn initial_chart(chart_name: &str) -> Chart { + Chart::new() + .title(component::Title::new().text(chart_name).left("center")) .tooltip(charming::element::Tooltip::new().trigger(charming::element::Trigger::Axis)) .data_zoom( - charming::component::DataZoom::new() - .type_(charming::component::DataZoomType::Inside) + component::DataZoom::new() + .type_(component::DataZoomType::Inside) .start(0) .end(100), ) - .data_zoom(charming::component::DataZoom::new().start(0).end(100)) + .data_zoom(component::DataZoom::new().start(0).end(100)) .toolbox( - charming::component::Toolbox::new().feature( - charming::component::Feature::new() - .data_zoom(charming::component::ToolboxDataZoom::new().y_axis_index("none")) - .restore(charming::component::Restore::new()) - .save_as_image(charming::component::SaveAsImage::new()), // .brush(Brush::new().type_(vec![BrushType::LineX, BrushType::Clear])), + component::Toolbox::new().feature( + component::Feature::new() + .data_zoom(component::ToolboxDataZoom::new().y_axis_index("none")) + .restore(component::Restore::new()) + .save_as_image(component::SaveAsImage::new()), // .brush(Brush::new().type_(vec![BrushType::LineX, BrushType::Clear])), ), ) .tooltip(charming::element::Tooltip::new().trigger(charming::element::Trigger::Axis)) - .y_axis(charming::component::Axis::new()) - .grid(charming::component::Grid::new().contain_label(true)) + .y_axis(component::Axis::new()) + .grid(component::Grid::new().contain_label(true)) } /// Generate a new plot chart -pub fn initial_plot_chart(chart_name: &str) -> charming::Chart { - charming::Chart::new() - .title( - charming::component::Title::new() - .text(chart_name) - .left("center"), - ) - .tooltip(charming::element::Tooltip::new().trigger(charming::element::Trigger::Axis)) +pub fn initial_plot_chart(chart_name: &str, sub_charts: &[&str]) -> Chart { + // charming::Chart::new() + Chart::new() + .title(Title::new().text(chart_name).left("center")) + .title(Title::new().text(sub_charts[0]).left("17%").top("5%")) + .title(Title::new().text(sub_charts[1]).left("17%").top("52%")) + .title(Title::new().text(sub_charts[2]).right("12%").top("5%")) + .title(Title::new().text(sub_charts[3]).right("12%").top("52%")) + .tooltip(Tooltip::new().trigger(Trigger::Axis)) .data_zoom( - charming::component::DataZoom::new() - .type_(charming::component::DataZoomType::Inside) + component::DataZoom::new() + .type_(component::DataZoomType::Inside) .start(0) .end(100), ) - .data_zoom(charming::component::DataZoom::new().start(0).end(100)) + .tooltip(charming::element::Tooltip::new().trigger(charming::element::Trigger::Axis)) .toolbox( - charming::component::Toolbox::new().feature( - charming::component::Feature::new() - .data_zoom(charming::component::ToolboxDataZoom::new().y_axis_index("none")) - .restore(charming::component::Restore::new()) - .save_as_image(charming::component::SaveAsImage::new()), // .brush(Brush::new().type_(vec![BrushType::LineX, BrushType::Clear])), + component::Toolbox::new().feature( + component::Feature::new() + .data_zoom(component::ToolboxDataZoom::new().y_axis_index("none")) + .restore(component::Restore::new()) + .save_as_image(component::SaveAsImage::new()), // .brush(Brush::new().type_(vec![BrushType::LineX, BrushType::Clear])), ), ) - .tooltip(charming::element::Tooltip::new().trigger(charming::element::Trigger::Axis)) + .grid( + Grid::new() + .left("7%") + .top("7%") + .width("38%") + .height("38%") + .contain_label(true), + ) + .grid( + Grid::new() + .right("7%") + .top("7%") + .width("38%") + .height("38%") + .contain_label(true), + ) + .grid( + Grid::new() + .left("7%") + .bottom("7%") + .width("38%") + .height("38%") + .contain_label(true), + ) + .grid( + Grid::new() + .right("7%") + .bottom("7%") + .width("38%") + .height("38%") + .contain_label(true), + ) + .x_axis(Axis::new().grid_index(0).min(1)) + .x_axis(Axis::new().grid_index(1).min(1)) + .x_axis(Axis::new().grid_index(2).min(1)) + .x_axis(Axis::new().grid_index(3).min(1)) + .y_axis(Axis::new().grid_index(0).min(0)) + .y_axis(Axis::new().grid_index(1).min(0)) + .y_axis(Axis::new().grid_index(2).min(0)) + .y_axis(Axis::new().grid_index(3).min(0)) } diff --git a/weaponry/src/weaponry_structs/equipement_advanced_repr.rs b/weaponry/src/weaponry_structs/equipement_advanced_repr.rs index 915d039..b9cfcf5 100644 --- a/weaponry/src/weaponry_structs/equipement_advanced_repr.rs +++ b/weaponry/src/weaponry_structs/equipement_advanced_repr.rs @@ -17,7 +17,7 @@ use super::{ use crate::{ add_field_to_chart, error::FatalEquipementError, - export::initial_chart, + export::{initial_chart, initial_plot_chart}, interfaces::{RecipeCollection, RefinedList, ToAnalysis, ToTex}, weaponry_structs::{ Equipement, InitialEquipementList, @@ -25,7 +25,7 @@ use crate::{ equipement_thin_types::{Dices, Precision}, }, }; -use charming::Chart; +use charming::{Chart, component::LegendSelectedMode}; use core::f64; use serde::Serialize; use std::cmp::Ordering; @@ -85,6 +85,49 @@ impl ToAnalysis for RefinedEquipementList { let mut renderer = charming::HtmlRenderer::new("Ravenous Balancing", 4000, 2000) .theme(charming::theme::Theme::Dark); + let initial_chart = self.make_regular_graph(); + renderer.save(&initial_chart, format!("{save_path}.html"))?; + + let plot_chart = self.make_cross_plots_graph(); + renderer.save(&plot_chart, format!("{save_path}_plots.html"))?; + Ok(()) + } +} + +impl RefinedEquipementList { + /// Make the cross graphs + fn make_cross_plots_graph(&self) -> Chart { + let mut plot_chart = initial_plot_chart( + "Damage Gradients Dice/Precision", + &["Damage 4+2A", "Damage 5+2A", "Damage 5+3A", "Damage 6+3A"], + ); + let mut names = Vec::with_capacity(self.inner.len()); + + for wpn in self.inner.iter() { + let data_4_a2: Vec> = custom_scenario(&wpn.inner, Actions(4), Attacks(2)); + let data_5_a2: Vec> = custom_scenario(&wpn.inner, Actions(5), Attacks(2)); + let data_5_a3: Vec> = custom_scenario(&wpn.inner, Actions(5), Attacks(3)); + let data_6_a3: Vec> = custom_scenario(&wpn.inner, Actions(6), Attacks(3)); + plot_chart = add_serie(plot_chart, 0, wpn, data_4_a2); + plot_chart = add_serie(plot_chart, 1, wpn, data_5_a2); + plot_chart = add_serie(plot_chart, 2, wpn, data_5_a3); + plot_chart = add_serie(plot_chart, 3, wpn, data_6_a3); + names.push(wpn.advanced.display_name.as_str()); + } + + plot_chart = plot_chart.legend( + charming::component::Legend::new() + .left(10) + .top("middle") + .orient(charming::element::Orient::Vertical) + .data(names) + .selected_mode(LegendSelectedMode::Multiple), + ); + plot_chart + } + + /// Max the regular balancing plots + fn make_regular_graph(&self) -> Chart { let initial_chart: Chart = initial_chart(&format!( "Damage for all cross-gen products ({} Elements)", self.inner.len() @@ -133,11 +176,45 @@ impl ToAnalysis for RefinedEquipementList { ) } ); - renderer.save(&initial_chart, format!("{save_path}.html"))?; - Ok(()) + initial_chart } } +/// Inner function to add a serie to a plot +fn add_serie(plot_chart: Chart, id: u8, wpn: &RefinedEquipement, serie: Vec>) -> Chart { + plot_chart.series( + charming::series::Line::new() + .x_axis_index(id) + .y_axis_index(id) + .data(serie) + .name(&wpn.advanced.display_name), + ) +} + +/// Custom scenario for creating scatter plot +fn custom_scenario( + equipement_stats: &InnerEquipementStats, + actions: Actions, + attacks: Attacks, +) -> Vec> { + (1..11) + .map(|dice| { + vec![ + dice as f64, + BestDamageScenarios::from_action_constraints_it( + equipement_stats, + actions, + attacks, + Dices(dice), + Precision(9), + ) + .unwrap_or_default() + .damage_done, + ] + }) + .collect() +} + /// The list of advanced stats infered from an Equipement #[derive(Serialize)] pub struct AdvancedStats { diff --git a/weaponry/src/weaponry_structs/equipement_advanced_tools.rs b/weaponry/src/weaponry_structs/equipement_advanced_tools.rs index 5a33f5f..ef81d9c 100644 --- a/weaponry/src/weaponry_structs/equipement_advanced_tools.rs +++ b/weaponry/src/weaponry_structs/equipement_advanced_tools.rs @@ -171,17 +171,17 @@ fn damage_over_turns(value: &InnerEquipementStats, turn_info: &[TurnInfo]) -> f6 } /// The best resulting attack pattern of a virtual scenrio where some conditions are given -#[derive(Debug)] -#[cfg_attr(test, derive(Default, Clone))] +#[derive(Debug, Default)] +#[cfg_attr(test, derive(Clone))] pub struct BestDamageScenarios { /// How many actions were used by the best attack - actions_used: Actions, + pub actions_used: Actions, /// Attacks actions used by the scenario - attacks_used: Attacks, + pub attacks_used: Attacks, /// Resulting damage - damage_done: f64, + pub damage_done: f64, /// Remaining actions that need to be used to finish reload - reload_remaining: Actions, + pub reload_remaining: Actions, } impl Add for BestDamageScenarios { @@ -204,7 +204,6 @@ impl Deref for BestDamageScenarios { } } -// TODO[!!]: Add a lot of testing impl BestDamageScenarios { /// Calculate the best alternative with a set of contraints ///