(slow) parsing
This commit is contained in:
commit
e3ddd88271
3 changed files with 180 additions and 0 deletions
96
Cargo.lock
generated
Normal file
96
Cargo.lock
generated
Normal file
|
@ -0,0 +1,96 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.94"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.219"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.219"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.140"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smogon-stats"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "smogon-stats"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
serde_json = "1.0.140"
|
76
src/main.rs
Normal file
76
src/main.rs
Normal file
|
@ -0,0 +1,76 @@
|
|||
// https://www.smogon.com/stats/2025-02/chaos/gen9ou-0.json
|
||||
|
||||
use std::{collections::HashMap, env, error::Error, fs::File};
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let path = env::args_os().nth(1).ok_or("i NEED a path")?;
|
||||
let file = File::open(path)?;
|
||||
let data: Stats = serde_json::from_reader(file)?;
|
||||
println!("{data:#?}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, PartialEq, Eq, Hash, Clone, Copy)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
enum Type {
|
||||
Normal,
|
||||
Fire,
|
||||
Water,
|
||||
Electric,
|
||||
Grass,
|
||||
Ice,
|
||||
Fighting,
|
||||
Poison,
|
||||
Ground,
|
||||
Flying,
|
||||
Psychic,
|
||||
Bug,
|
||||
Rock,
|
||||
Ghost,
|
||||
Dragon,
|
||||
Dark,
|
||||
Steel,
|
||||
Fairy,
|
||||
Stellar,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Stats {
|
||||
info: Info,
|
||||
data: HashMap<Box<str>, Data>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Info {
|
||||
metagame: Box<str>,
|
||||
cutoff: f64,
|
||||
#[serde(rename = "cutoff deviation")]
|
||||
cutoff_deviation: i64,
|
||||
#[serde(rename = "number of battles")]
|
||||
battle_count: i64,
|
||||
}
|
||||
|
||||
type Counts = HashMap<Box<str>, f32>;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
struct Data {
|
||||
#[serde(rename = "Raw count")]
|
||||
count: f32,
|
||||
#[serde(rename = "Viability Ceiling")]
|
||||
viability_ceiling: Box<[u32]>,
|
||||
abilities: Counts,
|
||||
items: Counts,
|
||||
spreads: Counts,
|
||||
moves: Counts,
|
||||
#[serde(rename = "Tera Types")]
|
||||
tera: HashMap<Type, f32>,
|
||||
// i'm just not going to include happiness sorry
|
||||
teammates: Counts,
|
||||
#[serde(rename = "Checks and Counters")]
|
||||
checks_and_counters: HashMap<Box<str>, (f32, f32, f32)>,
|
||||
#[serde(rename = "usage")]
|
||||
usage: f32,
|
||||
}
|
Loading…
Reference in a new issue