diff --git a/Cargo.toml b/Cargo.toml index f7428fd..df4ba34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,12 +13,23 @@ sycamore = { version = "0.8.2", features = [ ] } serde = { version = "1", features = ["derive"] } serde_json = "1" -env_logger = "0.10.0" +env_logger = "0.11.3" log = "0.4.20" once_cell = "1.18.0" web-sys = "0.3.64" cfg-if = "1.0.0" -chrono = { version = "0.4.31", features = ["serde"] } +chrono = { version = "0.4.38", features = ["serde"] } +strum = "0.26.2" +strum_macros = "0.26.2" +polars = { version = "0.39.2", default-features = false, features = [ + "fmt_no_tty", + "rows", + "lazy", + "concat_str", + "strings", + "csv", + "json", +] } [target.'cfg(engine)'.dev-dependencies] fantoccini = "0.19" diff --git a/README.md b/README.md index 4266666..27fff76 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,19 @@ To build CSS run: To build the project for testing, run `perseus serve --verbose` +For server logging: + +Windows: +`$Env:RUST_LOG = "info"` + +Linux: +`export RUST_LOG=info` + +For printing polars tables: + +See https://docs.rs/polars/latest/polars/#config-with-env-vars + + # Deploying the project First run diff --git a/card_downloader/download_images.py b/card_downloader/download_images.py index 463ff80..af29c95 100644 --- a/card_downloader/download_images.py +++ b/card_downloader/download_images.py @@ -22,6 +22,7 @@ if not os.path.exists("cards"): # Download all cards that don't have art FULL_DL_ENDPOINT = "https://images.ygoprodeck.com/images/cards/{}.jpg" SMALL_DL_ENDPOINT = "https://images.ygoprodeck.com/images/cards_small/{}.jpg" +INNER_ART_ENDPOINT = "https://images.ygoprodeck.com/images/cards_cropped/{}.jpg" for card_json in card_data["data"]: print(f"Downloading {card_json['name']}") @@ -38,10 +39,13 @@ for card_json in card_data["data"]: try: full_img = requests.get(FULL_DL_ENDPOINT.format(image_to_download)).content smol_img = requests.get(SMALL_DL_ENDPOINT.format(image_to_download)).content + inner_img = requests.get(INNER_ART_ENDPOINT.format(image_to_download)).content with open(f"cards/{image_to_download}/full.jpg", "wb") as file: file.write(full_img) with open(f"cards/{image_to_download}/small.jpg", "wb") as file: file.write(smol_img) + with open(f"cards/{image_to_download}/inner.jpg", "wb") as file: + file.write(inner_img) except Exception as e: shutil.rmtree('cards/{image_to_download}', ignore_errors=True) print(f"ERROR: Failed to download {image_to_download}. {str(e)}") diff --git a/package.json b/package.json index 0d3cb3d..ea79e79 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,6 @@ "author": "", "license": "ISC", "devDependencies": { - "tailwindcss": "^3.3.3" + "tailwindcss": "^3.4.1" } } diff --git a/src/components/layout.rs b/src/components/layout.rs index ece5323..d3413f3 100644 --- a/src/components/layout.rs +++ b/src/components/layout.rs @@ -27,6 +27,9 @@ pub fn Layout<'a, G: Html>( a(href = "inventory", class = "mt-3 text-gray-600 hover:underline sm:mx-3 sm:mt-0" ) { "Inventory" } + a(href = "tournaments", + class = "mt-3 text-gray-600 hover:underline sm:mx-3 sm:mt-0" + ) { "Tournaments" } } } } diff --git a/src/data/card.rs b/src/data/card.rs new file mode 100644 index 0000000..3276afe --- /dev/null +++ b/src/data/card.rs @@ -0,0 +1,102 @@ +use once_cell::sync::Lazy; +use polars::prelude::*; +use serde::{Deserialize, Serialize}; +use std::io::Cursor; +use std::{collections::HashMap, hash::Hash}; + +#[cfg(engine)] +use std::fs; +#[cfg(engine)] +use std::path::Path; + +enum CartType { + NormalMonster, + EffectMonster, + SpellCard, + TrapCard, + Unknown { name: String }, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct CardSet { + pub id: String, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct ArchetypeInfo { + pub name: String, + pub num_cards: u32, + pub cards: Vec, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct CardInfo { + pub id: u32, + pub name: String, + pub card_sets: Vec, + pub archetype: Option, +} + +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct CardInstance { + card_id: u32, + set_id: String, +} + +pub struct CardTable { + pub cards: HashMap, + pub sets: HashMap, + pub archetypes: HashMap, + pub df: DataFrame, +} + +impl CardTable { + #[cfg(engine)] + pub fn new_from_server_json(path: &Path) -> Self { + // First load json into initial dataframe + // TODO list all required files + let raw_df = JsonReader::new(std::fs::File::open("./data/cardinfo.json").unwrap()) + .finish() + .unwrap(); + let raw_df = raw_df + .lazy() + .select(&[col("data")]) + .explode(vec!["data"]) + .unnest(vec!["data"]) + .collect() + .unwrap(); + log::info!("{:?}", &raw_df); + + let id_col = UInt32Chunked::new("id_row", &[1]).into_series(); + + let cards = HashMap::new(); + let sets = HashMap::new(); + let archetypes = HashMap::new(); + + let df = DataFrame::new(vec![id_col]).unwrap(); + + Self { + cards, + sets, + archetypes, + df, + } + } + + #[cfg(client)] + pub fn new_from_client_json() -> Self { + let id_col = UInt32Chunked::new("id_row", &[1]).into_series(); + + let cards = HashMap::new(); + let sets = HashMap::new(); + let archetypes = HashMap::new(); + let df = DataFrame::new(vec![id_col]).unwrap(); + + Self { + cards, + sets, + archetypes, + df, + } + } +} diff --git a/src/data/mod.rs b/src/data/mod.rs index 95ef5e7..078999f 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -1,4 +1,5 @@ pub mod user; +pub mod card; #[cfg(engine)] pub mod store; diff --git a/src/main.rs b/src/main.rs index 51dca82..806d3dc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,9 +6,16 @@ mod error_views; mod server; mod templates; +use std::path::Path; + +use data::card::CardTable; use perseus::prelude::*; use sycamore::prelude::view; +extern crate strum; +#[macro_use] +extern crate strum_macros; + cfg_if::cfg_if! { if #[cfg(engine)] { use std::net::SocketAddr; @@ -35,6 +42,9 @@ pub async fn dflt_server GlobalStateCreator { GlobalStateCreator::new() diff --git a/style/tailwind.css b/style/tailwind.css index 0574349..b5c61c9 100644 --- a/style/tailwind.css +++ b/style/tailwind.css @@ -1,3 +1,3 @@ @tailwind base; @tailwind components; -@tailwind variants; +@tailwind utilities;