159 lines
5.3 KiB
Rust
159 lines
5.3 KiB
Rust
// Workspace: weaponry
|
|
// File: examples/usage_scenario.rs
|
|
//! 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,
|
|
},
|
|
element::{AxisType, Tooltip, Trigger},
|
|
series::Line,
|
|
};
|
|
use std::path::Path;
|
|
|
|
// TODO : All of these should likely be in the prelude if used like this
|
|
use weaponry::weaponry_structs::CrossRecipeScenario;
|
|
use weaponry::weaponry_structs::equipement_scenario::ConfigMock;
|
|
use weaponry::{
|
|
interfaces::{Reportable, Scenario, ToCSV},
|
|
weaponry_structs::RefinedEquipementList,
|
|
};
|
|
// use weaponry::interfaces::
|
|
fn main() {
|
|
let save_path = "data/first_data";
|
|
let scenarios = CrossRecipeScenario::new_with_config(ConfigMock {}).unwrap();
|
|
let mut refined_list = scenarios.generate_refined_recipes().unwrap();
|
|
// Render as html
|
|
render_data(&mut refined_list, save_path);
|
|
// // Export as csv
|
|
// export_as_csv(&refined_list, save_path);
|
|
}
|
|
|
|
#[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")))
|
|
);
|
|
}
|
|
|
|
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.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 dps_safe = vec![];
|
|
let mut max_damage_per_action = vec![];
|
|
let mut armor_break_per_turn = vec![];
|
|
|
|
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("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))
|
|
.x_axis(
|
|
Axis::new()
|
|
.data(data_list.to_vec())
|
|
.type_(AxisType::Category),
|
|
)
|
|
.y_axis(Axis::new())
|
|
.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()), // .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("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();
|
|
}
|
|
|
|
// // Load DB
|
|
// let db = EquipementDatabase::new("./databases/weapons.db").unwrap();
|
|
// // Do a first deserialisation
|
|
// let initial_deserialisation = db.serialize_vec_from_table::<DatabaseEquipementStats>("Equipements", None).unwrap();
|
|
// // Follow up by parsing this deserialisation by a transformation into the right intermediate representation
|
|
// let intermediate_deserialisation = initial_deserialisation.into_iter().map(InnerEquipementStats::try_from).collect::<Vec<_>>();
|
|
|
|
// // // Inspect the sucesses/filures
|
|
// // let f = intermediate_deserialisation.iter().fold((0, 0), |val, res| (val.0 + res.is_ok() as usize, val.1 + 1_usize));
|
|
// // println!("Succeded in parsing {}/{}", f.0, f.1);
|
|
|
|
// // println!("Final data {:#?}", intermediate_deserialisation);
|
|
// // println!("Failed to parse: {:#?}", intermediate_deserialisation.into_iter().filter_map(|v| v.err()).collect::<Vec<_>>());
|