Compare commits
6 commits
Author | SHA1 | Date | |
---|---|---|---|
e87753361d | |||
d8976638d3 | |||
8dc524aa38 | |||
f5445636a0 | |||
049aa6f2b1 | |||
9337e57e0b |
4 changed files with 8 additions and 10 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -507,7 +507,7 @@ checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd"
|
|||
|
||||
[[package]]
|
||||
name = "smogon-stats"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"env_logger",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "smogon-stats"
|
||||
version = "0.1.0"
|
||||
version = "0.1.2"
|
||||
edition = "2024"
|
||||
authors = ["mehbark <terezi@pyrope.net>"]
|
||||
description = "turn https://smogon.com/stats/ chaos json files into https://sqlite.org databases"
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# smogon stats
|
||||
turn <https://smogon.com/stats/> chaos json files into [SQLite](https://sqlite.org) databases
|
||||
|
||||
you can find pre-generated dbs at <https://pyrope.net/mon/stats> (currently only 2025-02), and you can [fiddle](https://sqlite.org/fiddle) with them in your browser or on your own computer.
|
||||
you can find pre-generated dbs at <https://pyrope.net/mon/stats>, and you can [fiddle](https://sqlite.org/fiddle) with them in your browser or on your own computer.
|
||||
|
||||
## examples
|
||||
## examples (2025-02)
|
||||
```sh
|
||||
smogon-stats gen9ou-1500.json -o gen9ou-1500.sqlite
|
||||
sqlite3 gen9ou-1500.sqlite -markdown "SELECT name, format('%.2f%%', usage * 100) as usage FROM mon WHERE mon.usage > 0.04 ORDER BY mon.usage DESC LIMIT 10"
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -1,5 +1,3 @@
|
|||
// https://www.smogon.com/stats/2025-02/chaos/
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs::{self, File},
|
||||
|
@ -54,10 +52,11 @@ fn run(
|
|||
}
|
||||
|
||||
#[derive(clap::Parser)]
|
||||
#[command(about)]
|
||||
#[command(version, about)]
|
||||
struct Config {
|
||||
#[arg()]
|
||||
input_file: PathBuf,
|
||||
// TODO: non-utf-8 (the problem is saving the database)
|
||||
#[arg(short, long = "output")]
|
||||
output_file: PathBuf,
|
||||
}
|
||||
|
@ -125,12 +124,12 @@ fn insert_stats(conn: &mut Connection, stats: &Stats) -> rusqlite::Result<()> {
|
|||
let mon_count = stats.data.len();
|
||||
let mon_count_digits = mon_count.to_string().len();
|
||||
|
||||
let tx = conn.transaction()?;
|
||||
for (i, (mon, data)) in stats.data.iter().enumerate() {
|
||||
log::debug!(
|
||||
"Processing mon {:mon_count_digits$}/{mon_count} ({mon})",
|
||||
i + 1
|
||||
);
|
||||
let tx = conn.transaction()?;
|
||||
|
||||
// normalizing with mon_count gives us data that is much easier to work
|
||||
// with. for example, if pikachu has 10k count (weighted) and thunderbolt
|
||||
|
@ -196,9 +195,8 @@ fn insert_stats(conn: &mut Connection, stats: &Stats) -> rusqlite::Result<()> {
|
|||
(mon, opp, percentage, stddev),
|
||||
)?;
|
||||
}
|
||||
|
||||
tx.commit()?;
|
||||
}
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue