fix: make fields that old files don't have optional
This commit is contained in:
parent
a616174f79
commit
120ed1502b
1 changed files with 21 additions and 15 deletions
36
src/main.rs
36
src/main.rs
|
@ -82,8 +82,8 @@ fn create_tables(conn: &mut Connection) -> rusqlite::Result<()> {
|
|||
BEGIN;
|
||||
CREATE TABLE mon (
|
||||
name STRING NOT NULL,
|
||||
usage REAL NOT NULL,
|
||||
viability_ceiling REAL NOT NULL
|
||||
usage REAL,
|
||||
viability_ceiling REAL
|
||||
);
|
||||
CREATE TABLE ability (
|
||||
mon STRING NOT NULL,
|
||||
|
@ -142,7 +142,11 @@ fn insert_stats(conn: &mut Connection, stats: &Stats) -> rusqlite::Result<()> {
|
|||
let mon_count: f32 = data.abilities.values().sum();
|
||||
tx.execute(
|
||||
"INSERT INTO mon VALUES (?1, ?2, ?3)",
|
||||
(mon, data.usage, data.viability_ceiling[1]),
|
||||
(
|
||||
mon,
|
||||
data.usage,
|
||||
data.viability_ceiling.as_ref().map(|x| x[1]),
|
||||
),
|
||||
)?;
|
||||
|
||||
for (ability, count) in &data.abilities {
|
||||
|
@ -166,15 +170,17 @@ fn insert_stats(conn: &mut Connection, stats: &Stats) -> rusqlite::Result<()> {
|
|||
)?;
|
||||
}
|
||||
|
||||
for (tera, count) in &data.tera {
|
||||
tx.execute(
|
||||
"INSERT INTO tera VALUES (?1, ?2, ?3)",
|
||||
(
|
||||
mon,
|
||||
format!("{tera:?}").to_ascii_lowercase(),
|
||||
count / mon_count,
|
||||
),
|
||||
)?;
|
||||
if let Some(tera) = &data.tera {
|
||||
for (tera, count) in tera {
|
||||
tx.execute(
|
||||
"INSERT INTO tera VALUES (?1, ?2, ?3)",
|
||||
(
|
||||
mon,
|
||||
format!("{tera:?}").to_ascii_lowercase(),
|
||||
count / mon_count,
|
||||
),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
for (mate, count) in &data.teammates {
|
||||
|
@ -242,16 +248,16 @@ type Counts = HashMap<Box<str>, f32>;
|
|||
#[serde(rename_all = "PascalCase")]
|
||||
struct Data {
|
||||
#[serde(rename = "Viability Ceiling")]
|
||||
viability_ceiling: Box<[u32]>,
|
||||
viability_ceiling: Option<Box<[u32]>>,
|
||||
abilities: Counts,
|
||||
items: Counts,
|
||||
moves: Counts,
|
||||
#[serde(rename = "Tera Types")]
|
||||
tera: HashMap<Type, f32>,
|
||||
tera: Option<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,
|
||||
usage: Option<f32>,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue