Loads data from tables with load #73
|
|
@ -2,9 +2,9 @@
|
|||
// File: config/src/graph.rs
|
||||
//! The inner config for graph module
|
||||
//!
|
||||
use clap::{Args, builder::ValueParserFactory};
|
||||
use clap::Args;
|
||||
use phf::phf_map;
|
||||
use serde::Deserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{ops::Add, sync::LazyLock};
|
||||
|
||||
#[derive(Args, Debug, Clone)]
|
||||
|
|
@ -74,18 +74,43 @@ impl From<&str> for GraphTargetType {
|
|||
}
|
||||
}
|
||||
}
|
||||
/// A named categories
|
||||
#[derive(Debug)]
|
||||
pub struct ClassValues {
|
||||
/// The named categories to save on file
|
||||
#[derive(Default, Debug, Deserialize, Serialize)]
|
||||
pub struct FinalClassRadar {
|
||||
/// A name to identify the categories
|
||||
#[serde(rename = "Classe")]
|
||||
pub name: String,
|
||||
/// The values of the different radar categories
|
||||
pub categories: Categories,
|
||||
/// The ability to survive.
|
||||
#[serde(rename = "Survivabilité")]
|
||||
pub survivability: f64,
|
||||
/// The ability to deal damage.
|
||||
#[serde(rename = "Dégats")]
|
||||
pub damage: f64,
|
||||
/// The ability to move.
|
||||
#[serde(rename = "Mobilité")]
|
||||
pub mobility: f64,
|
||||
/// The ability to inflict state alterations.
|
||||
#[serde(rename = "Altérations")]
|
||||
pub alterations: f64,
|
||||
/// The ability to provide support.
|
||||
#[serde(rename = "Support")]
|
||||
pub support: f64,
|
||||
/// The ability to inflict crowd control.
|
||||
#[serde(rename = "C.C")]
|
||||
pub cc: f64,
|
||||
/// The ability to improve quality of life.
|
||||
#[serde(rename = "QoL")]
|
||||
pub qol: f64,
|
||||
/// The armor break of the class
|
||||
#[serde(rename = "Brise-Armure")]
|
||||
pub armorbreak: f64,
|
||||
// / The class complexity
|
||||
}
|
||||
|
||||
/// All the categories to load from the tables
|
||||
#[derive(Default, Debug)]
|
||||
pub struct Categories {
|
||||
#[derive(Default, Debug, Deserialize, Serialize)]
|
||||
pub struct LoadedClassRadar {
|
||||
/// The ability to survive.
|
||||
pub survivability: f64,
|
||||
/// The ability to deal damage.
|
||||
|
|
@ -100,6 +125,8 @@ pub struct Categories {
|
|||
pub cc: f64,
|
||||
/// The ability to improve quality of life.
|
||||
pub qol: f64,
|
||||
/// The ability to break armor.
|
||||
pub armorbreak: f64,
|
||||
}
|
||||
|
||||
/// All the categories to load from the tables
|
||||
|
|
@ -119,8 +146,6 @@ pub struct RawRow {
|
|||
pub effet: String,
|
||||
/// A indicative column for notes
|
||||
pub indicative: String,
|
||||
/// The name of the class.
|
||||
pub classe: String,
|
||||
/// The ability to survive.
|
||||
pub survivability: String,
|
||||
/// The ability to deal damage.
|
||||
|
|
@ -135,9 +160,11 @@ pub struct RawRow {
|
|||
pub cc: String,
|
||||
/// The ability to improve quality of life.
|
||||
pub qol: String,
|
||||
/// The ability to break armor.
|
||||
pub armorbreak: String,
|
||||
}
|
||||
|
||||
impl From<RawRow> for Categories {
|
||||
impl From<RawRow> for LoadedClassRadar {
|
||||
fn from(value: RawRow) -> Self {
|
||||
Self {
|
||||
survivability: value.survivability.parse().unwrap_or(0.0),
|
||||
|
|
@ -147,11 +174,12 @@ impl From<RawRow> for Categories {
|
|||
support: value.support.parse().unwrap_or(0.0),
|
||||
cc: value.cc.parse().unwrap_or(0.0),
|
||||
qol: value.qol.parse().unwrap_or(0.0),
|
||||
armorbreak: value.armorbreak.parse().unwrap_or(0.0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for Categories {
|
||||
impl Add for LoadedClassRadar {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
|
|
@ -163,6 +191,47 @@ impl Add for Categories {
|
|||
support: self.support + rhs.support,
|
||||
cc: self.cc + rhs.cc,
|
||||
qol: self.qol + rhs.qol,
|
||||
armorbreak: self.armorbreak + rhs.armorbreak,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FinalClassRadar {
|
||||
/// A very wastful (but simple) way to only add the max value
|
||||
pub fn find_max(self, rhs: &Self) -> Self {
|
||||
Self {
|
||||
survivability: self.survivability.max(rhs.survivability),
|
||||
damage: self.damage.max(rhs.damage),
|
||||
mobility: self.mobility.max(rhs.mobility),
|
||||
alterations: self.alterations.max(rhs.alterations),
|
||||
support: self.support.max(rhs.support),
|
||||
cc: self.cc.max(rhs.cc),
|
||||
qol: self.qol.max(rhs.qol),
|
||||
armorbreak: self.armorbreak.max(rhs.armorbreak),
|
||||
name: self.name,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a class from a loaded categories
|
||||
pub fn from_radar_with_name(name: String, categorie: LoadedClassRadar) -> Self {
|
||||
Self {
|
||||
name,
|
||||
survivability: categorie.survivability,
|
||||
damage: categorie.damage,
|
||||
mobility: categorie.mobility,
|
||||
alterations: categorie.alterations,
|
||||
support: categorie.support,
|
||||
cc: categorie.cc,
|
||||
qol: categorie.qol,
|
||||
armorbreak: categorie.armorbreak,
|
||||
}
|
||||
}
|
||||
|
||||
/// A default value for accumulation
|
||||
pub fn default_for_acc() -> FinalClassRadar {
|
||||
Self {
|
||||
name: "Max".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ edition = "2024"
|
|||
config = {path = "../config"}
|
||||
cli_parser = {path = "../cli_parser"}
|
||||
anyhow = "1.0.95"
|
||||
charts-rs = "0.3.19"
|
||||
charts-rs = "0.4.2"
|
||||
glob = "0.3.2"
|
||||
serde = { version = "1.0.217", features = ["derive", "alloc"] }
|
||||
csv = "1.3.1"
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@
|
|||
|
||||
use charts_rs::{Box, Color, RadarChart, RadarIndicator, Series, get_or_try_init_fonts};
|
||||
use cli_parser::Config;
|
||||
use config::graph::{Categories, ClassValues, GraphConfig, GraphTargetType, RawRow};
|
||||
use config::graph::{FinalClassRadar, GraphConfig, GraphTargetType, LoadedClassRadar, RawRow};
|
||||
use glob::glob;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
fs::File,
|
||||
io::{Read, Write},
|
||||
iter,
|
||||
|
|
@ -86,7 +85,8 @@ fn del_graphs(args: &GraphConfig) -> Result<()> {
|
|||
/// Load graph data from classes
|
||||
fn load_graph(args: &GraphConfig) -> Result<()> {
|
||||
let _ = args;
|
||||
load_categories_from_tsv("./test.csv")?;
|
||||
// load_categories_from_tsv("./test.csv")?;
|
||||
generate_csv()?;
|
||||
Ok(())
|
||||
}
|
||||
///Generate the graph and save it
|
||||
|
|
@ -144,30 +144,51 @@ fn import_csv(args: &GraphConfig) -> Result<GraphValues> {
|
|||
fn generate_csv() -> Result<()> {
|
||||
// Acquire the data from all classes
|
||||
let list_class = list_dir("Tables/??? - *.tsv");
|
||||
let mut final_class = Vec::new();
|
||||
let mut final_class_list = Vec::with_capacity(list_class.len() + 1);
|
||||
// Very ugly space reservation for the last operation, need to check if no way of skipping an element is possible
|
||||
final_class_list.push(FinalClassRadar::default());
|
||||
|
||||
for single_class in list_class {
|
||||
let class_name = &single_class
|
||||
.file_name()
|
||||
.context("Extracting old name")?
|
||||
.to_str()
|
||||
.context("Generating new name")?[12..];
|
||||
.context("Generating new name")?[12..]
|
||||
.strip_suffix(".tsv")
|
||||
.context("Stripping extention")?;
|
||||
let categories =
|
||||
load_categories_from_tsv(single_class.clone()).context("Loading from csv")?;
|
||||
final_class.push(ClassValues {
|
||||
name: class_name.to_string(),
|
||||
// final_class_list.push(ClassValues {
|
||||
// name: class_name.to_string(),
|
||||
// categories,
|
||||
// });
|
||||
final_class_list.push(FinalClassRadar::from_radar_with_name(
|
||||
class_name.to_string(),
|
||||
categories,
|
||||
});
|
||||
))
|
||||
}
|
||||
// Calculate all the max values
|
||||
// ajust all values to fit a 0..5 range
|
||||
// print data if verbose
|
||||
// convert it to a graphvalues
|
||||
final_class_list[0] = final_class_list
|
||||
.iter()
|
||||
.fold(FinalClassRadar::default_for_acc(), |a, b| a.find_max(b));
|
||||
|
||||
let mut wtr = csv::WriterBuilder::new()
|
||||
.has_headers(true)
|
||||
.from_path("Images/Radar/radar.csv")
|
||||
.context("Creating CSV output file")?;
|
||||
|
||||
// println!("{:?}", final_class_list);
|
||||
for cv in &final_class_list {
|
||||
wtr.serialize(cv).context("Writing CSV record")?;
|
||||
}
|
||||
|
||||
wtr.flush().context("Flushing CSV writer")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Reads a TSV file that either has the header line shown above or
|
||||
/// just raw data rows, and returns a `Vec<Categories>`.
|
||||
pub fn load_categories_from_tsv<P: AsRef<Path>>(path: P) -> Result<Categories> {
|
||||
pub fn load_categories_from_tsv<P: AsRef<Path>>(path: P) -> Result<LoadedClassRadar> {
|
||||
// `has_headers(false)` tells the csv crate to *not* treat the first row as a header.
|
||||
// We’ll do the header check ourselves.
|
||||
let file = File::open(path)?;
|
||||
|
|
@ -180,7 +201,7 @@ pub fn load_categories_from_tsv<P: AsRef<Path>>(path: P) -> Result<Categories> {
|
|||
.comment(Some(b'#'))
|
||||
.from_reader(file);
|
||||
|
||||
let mut sum = Categories::default();
|
||||
let mut sum = LoadedClassRadar::default();
|
||||
for result in rdr.deserialize() {
|
||||
let result: RawRow = result?;
|
||||
if result.technique.starts_with("Tier ") {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# cargo-features = ["codegen-backend"]
|
||||
[package]
|
||||
name = "ravenous-tools"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
|
|
|||
Loading…
Reference in New Issue