Adds more to the graph

This commit is contained in:
Dandaedre 2025-02-22 05:45:42 +01:00
parent 04bc4d57ec
commit 5b3972a906
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
7 changed files with 145 additions and 62 deletions

View File

@ -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"

Binary file not shown.

View File

@ -1 +1 @@
max_width = 278
# max_width = 278

View File

@ -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<String>,
}
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

View File

@ -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,
}
}
}

View File

@ -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<EqShape> for Equipement {
@ -31,7 +34,7 @@ impl From<EqMaterial> 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<EqNature> 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()),
}
}
}

View File

@ -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<T> FilterFunction<T> {
/// Generate a new filter
// TODO: This static lifetime is basically telling us that an owned value is needed