Adds a basic loading capability to the radar plugin
This commit is contained in:
parent
dbb44dffb4
commit
16844dba07
|
|
@ -2,9 +2,10 @@
|
|||
// File: config/src/graph.rs
|
||||
//! The inner config for graph module
|
||||
//!
|
||||
use clap::Args;
|
||||
use clap::{Args, builder::ValueParserFactory};
|
||||
use phf::phf_map;
|
||||
use std::sync::LazyLock;
|
||||
use serde::Deserialize;
|
||||
use std::{ops::Add, sync::LazyLock};
|
||||
|
||||
#[derive(Args, Debug, Clone)]
|
||||
/// The configuration struct for the Graph
|
||||
|
|
@ -32,6 +33,7 @@ pub struct GraphConfig {
|
|||
|
||||
/// Link from user str input to the action to perform
|
||||
static STR_TO_GRAPH_TARGET_TYPE: phf::Map<&'static str, GraphTargetType> = phf_map! {
|
||||
"load" => GraphTargetType::Load,
|
||||
"generate" => GraphTargetType::Generate,
|
||||
"gen" => GraphTargetType::Generate,
|
||||
"remove" => GraphTargetType::Remove,
|
||||
|
|
@ -51,6 +53,8 @@ static HELP_STR_TO_GRAPH: LazyLock<String> = LazyLock::new(|| {
|
|||
#[derive(Debug, Clone)]
|
||||
/// All target type
|
||||
pub enum GraphTargetType {
|
||||
/// Load graph data from the classes
|
||||
Load,
|
||||
/// Make all graphs
|
||||
Generate,
|
||||
/// Clean all graphs
|
||||
|
|
@ -70,3 +74,95 @@ impl From<&str> for GraphTargetType {
|
|||
}
|
||||
}
|
||||
}
|
||||
/// A named categories
|
||||
#[derive(Debug)]
|
||||
pub struct ClassValues {
|
||||
/// A name to identify the categories
|
||||
pub name: String,
|
||||
/// The values of the different radar categories
|
||||
pub categories: Categories,
|
||||
}
|
||||
|
||||
/// All the categories to load from the tables
|
||||
#[derive(Default, Debug)]
|
||||
pub struct Categories {
|
||||
/// The ability to survive.
|
||||
pub survivability: f64,
|
||||
/// The ability to deal damage.
|
||||
pub damage: f64,
|
||||
/// The ability to move.
|
||||
pub mobility: f64,
|
||||
/// The ability to inflict state alterations.
|
||||
pub alterations: f64,
|
||||
/// The ability to provide support.
|
||||
pub support: f64,
|
||||
/// The ability to inflict crowd control.
|
||||
pub cc: f64,
|
||||
/// The ability to improve quality of life.
|
||||
pub qol: f64,
|
||||
}
|
||||
|
||||
/// All the categories to load from the tables
|
||||
#[derive(Deserialize, Clone, Debug)]
|
||||
pub struct RawRow {
|
||||
/// The name of a technique.
|
||||
pub technique: String,
|
||||
/// The level or rank of a technique
|
||||
pub niveau: String,
|
||||
/// The type of technique, such as Actif or Exclusif.
|
||||
pub technique_type: String,
|
||||
/// The blood cost for this technique.
|
||||
pub cout_blood: String,
|
||||
/// The gauge cost for this technique.
|
||||
pub cout_jauge: String,
|
||||
/// A brief description of the effect or outcome of using this technique.
|
||||
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.
|
||||
pub damage: String,
|
||||
/// The ability to move.
|
||||
pub mobility: String,
|
||||
/// The ability to inflict state alterations.
|
||||
pub alterations: String,
|
||||
/// The ability to provide support.
|
||||
pub support: String,
|
||||
/// The ability to inflict crowd control.
|
||||
pub cc: String,
|
||||
/// The ability to improve quality of life.
|
||||
pub qol: String,
|
||||
}
|
||||
|
||||
impl From<RawRow> for Categories {
|
||||
fn from(value: RawRow) -> Self {
|
||||
Self {
|
||||
survivability: value.survivability.parse().unwrap_or(0.0),
|
||||
damage: value.damage.parse().unwrap_or(0.0),
|
||||
mobility: value.mobility.parse().unwrap_or(0.0),
|
||||
alterations: value.alterations.parse().unwrap_or(0.0),
|
||||
support: value.support.parse().unwrap_or(0.0),
|
||||
cc: value.cc.parse().unwrap_or(0.0),
|
||||
qol: value.qol.parse().unwrap_or(0.0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for Categories {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self {
|
||||
survivability: self.survivability + rhs.survivability,
|
||||
damage: self.damage + rhs.damage,
|
||||
mobility: self.mobility + rhs.mobility,
|
||||
alterations: self.alterations + rhs.alterations,
|
||||
support: self.support + rhs.support,
|
||||
cc: self.cc + rhs.cc,
|
||||
qol: self.qol + rhs.qol,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,15 @@
|
|||
|
||||
use charts_rs::{Box, Color, RadarChart, RadarIndicator, Series, get_or_try_init_fonts};
|
||||
use cli_parser::Config;
|
||||
use config::graph::{GraphConfig, GraphTargetType};
|
||||
use config::graph::{Categories, ClassValues, GraphConfig, GraphTargetType, RawRow};
|
||||
use glob::glob;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
fs::File,
|
||||
io::{Read, Write},
|
||||
iter,
|
||||
path::{Path, PathBuf},
|
||||
process::Command,
|
||||
};
|
||||
|
||||
|
|
@ -22,6 +24,7 @@ use anyhow::{Context, Result};
|
|||
pub fn make_graphs(args: &GraphConfig, _config: &Config) -> Result<()> {
|
||||
// Choose action to do
|
||||
match args.target {
|
||||
GraphTargetType::Load => load_graph(args),
|
||||
GraphTargetType::Generate => gen_graph(args),
|
||||
GraphTargetType::Remove => del_graphs(args),
|
||||
GraphTargetType::Init => init_graph_config(args),
|
||||
|
|
@ -80,7 +83,13 @@ fn del_graphs(args: &GraphConfig) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Generate the graph and save it
|
||||
/// Load graph data from classes
|
||||
fn load_graph(args: &GraphConfig) -> Result<()> {
|
||||
let _ = args;
|
||||
load_categories_from_tsv("./test.csv")?;
|
||||
Ok(())
|
||||
}
|
||||
///Generate the graph and save it
|
||||
fn gen_graph(args: &GraphConfig) -> Result<()> {
|
||||
// Import CSV
|
||||
let data = include_bytes!("../../../data/lmroman8-regular.ttf") as &[u8];
|
||||
|
|
@ -131,6 +140,60 @@ fn import_csv(args: &GraphConfig) -> Result<GraphValues> {
|
|||
cleanup_csv(rdr)
|
||||
}
|
||||
|
||||
/// Generate the csv from all the classes
|
||||
fn generate_csv() -> Result<()> {
|
||||
// Acquire the data from all classes
|
||||
let list_class = list_dir("Tables/??? - *.tsv");
|
||||
let mut final_class = Vec::new();
|
||||
for single_class in list_class {
|
||||
let class_name = &single_class
|
||||
.file_name()
|
||||
.context("Extracting old name")?
|
||||
.to_str()
|
||||
.context("Generating new name")?[12..];
|
||||
let categories =
|
||||
load_categories_from_tsv(single_class.clone()).context("Loading from csv")?;
|
||||
final_class.push(ClassValues {
|
||||
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
|
||||
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> {
|
||||
// `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)?;
|
||||
let mut rdr = csv::ReaderBuilder::new()
|
||||
.has_headers(false)
|
||||
.delimiter(b'\t')
|
||||
.double_quote(false)
|
||||
.escape(Some(b'\\'))
|
||||
.flexible(true)
|
||||
.comment(Some(b'#'))
|
||||
.from_reader(file);
|
||||
|
||||
let mut sum = Categories::default();
|
||||
for result in rdr.deserialize() {
|
||||
let result: RawRow = result?;
|
||||
if result.technique.starts_with("Tier ") {
|
||||
// Getto way of knowing we have a new tier, that we ignore
|
||||
} else if (result.technique == "Technique") | result.technique.is_empty() {
|
||||
// Skip this entry
|
||||
} else {
|
||||
sum = sum + result.into();
|
||||
}
|
||||
}
|
||||
Ok(sum)
|
||||
}
|
||||
|
||||
/// The data for all graphs
|
||||
struct GraphValues {
|
||||
/// The max values of a graph
|
||||
|
|
@ -301,3 +364,15 @@ pub struct MiniTheme {
|
|||
// pub table_body_colors: Vec<Color>,
|
||||
// pub table_border_color: Color,
|
||||
}
|
||||
|
||||
/// List all files matching a pattern in the given directory
|
||||
#[inline]
|
||||
fn list_dir(pattern: &str) -> Vec<PathBuf> {
|
||||
// println!("{}", pattern);
|
||||
// println!("{:?}", glob(pattern));
|
||||
|
||||
glob(pattern)
|
||||
.expect("Failed to read glob pattern")
|
||||
.flatten()
|
||||
.collect()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue