From 120ed1502b488a1852edd9d3e44ebf4bf18a3b95 Mon Sep 17 00:00:00 2001 From: mehbark <terezi@pyrope.net> Date: Wed, 26 Mar 2025 15:51:46 -0400 Subject: [PATCH] fix: make fields that old files don't have optional --- src/main.rs | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index f9f03e4..0e90462 100644 --- a/src/main.rs +++ b/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>, }