rustybeans/src/config.rs

62 lines
1.3 KiB
Rust

use serde::Deserialize;
use std::collections::HashMap;
use std::fs;
#[derive(Deserialize, Debug, Default)]
pub struct Shot {
pub filename: Option<String>,
pub json: Option<String>,
pub title: String,
pub cutoff: Option<f64>,
pub disable: Option<bool>,
}
#[derive(Deserialize, Debug, Default)]
pub struct Chart {
pub title: String,
pub shots: Vec<u64>,
pub max_time: u64,
pub max_weight: u64,
pub max_flow: u64,
}
#[derive(Deserialize, Debug, Default)]
pub struct Config {
pub shots: HashMap<String, Shot>,
pub charts: HashMap<String, Chart>,
pub shot_dir: String,
pub brew_dir: String,
pub data_dir: String,
pub output_dir: String,
pub main_json: String,
pub width: u32,
pub height: u32,
}
pub const WGHT_SHEET: usize = 0;
pub const FLOW_SHEET: usize = 1;
pub const TIME_COL: usize = 0;
pub const WGHT_COL: usize = 5;
pub const FLOW_COL: usize = 2;
pub struct Data {
pub weight: Vec<(f64, f64)>,
pub flowrate: Vec<(f64, f64)>,
}
impl Config {
pub fn from_file(path: &str) -> Self {
let config_file = fs::read_to_string(&path).expect("Can't read config.toml");
toml::from_str(&config_file).expect("Can't deserialize config.toml")
}
pub fn from_default() -> Self {
Self::from_file("config.toml")
}
}