Compare commits

...

6 commits
v0.1.1 ... main

Author SHA1 Message Date
e87753361d fix: update readme 2025-04-01 12:42:11 -04:00
d8976638d3 fix: add version to output 2025-03-27 02:47:54 -04:00
8dc524aa38 v0.1.2 2025-03-27 02:45:32 -04:00
f5445636a0 fix: just write to the dang file :P 2025-03-27 02:41:12 -04:00
049aa6f2b1 feat: one transaction, build in memory and vacuum out 2025-03-27 02:36:22 -04:00
9337e57e0b v0.1.1 2025-03-27 00:37:10 -04:00
4 changed files with 8 additions and 10 deletions

2
Cargo.lock generated
View file

@ -507,7 +507,7 @@ checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd"
[[package]]
name = "smogon-stats"
version = "0.1.0"
version = "0.1.2"
dependencies = [
"clap",
"env_logger",

View file

@ -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"

View file

@ -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"

View file

@ -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(())
}