Skip to content

Commit

Permalink
fixing bug in pidgtm compile (#54)
Browse files Browse the repository at this point in the history
* fixing bug in pidgtm compile

Signed-off-by: danbugs <[email protected]>

* improve

Signed-off-by: danbugs <[email protected]>

---------

Signed-off-by: danbugs <[email protected]>

fixing bug in pidgtm compile (#55)

* fixing bug in pidgtm compile

Signed-off-by: danbugs <[email protected]>

* fix && fmt

Signed-off-by: danbugs <[email protected]>

---------

Signed-off-by: danbugs <[email protected]>

fix pidgtm compile bug

Signed-off-by: danbugs <[email protected]>

fix && fmt

Signed-off-by: danbugs <[email protected]>

fix pidgtm compile bug

Signed-off-by: danbugs <[email protected]>

fix && fmt

Signed-off-by: danbugs <[email protected]>

fix pidgtm compile bug

Signed-off-by: danbugs <[email protected]>

fix && fmt

Signed-off-by: danbugs <[email protected]>

fix pidgtm compile bug

Signed-off-by: danbugs <[email protected]>

fix && fmt

Signed-off-by: danbugs <[email protected]>

fix pidgtm compile bug

Signed-off-by: danbugs <[email protected]>
  • Loading branch information
danbugs committed Dec 28, 2023
1 parent 8d6d161 commit 8549f5e
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 89 deletions.
25 changes: 1 addition & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions database/migrations/2023-12-27-224952_migration4/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Revert primary key change in player_games
ALTER TABLE player_games
DROP CONSTRAINT player_games_pkey;

ALTER TABLE player_games
ADD PRIMARY KEY (game_id, requester_id);

-- Remove the set_id column from player_games
ALTER TABLE player_games
DROP COLUMN set_id;

-- Add the game_ids column back to player_sets
ALTER TABLE player_sets
ADD COLUMN game_ids INTEGER ARRAY;
14 changes: 14 additions & 0 deletions database/migrations/2023-12-27-224952_migration4/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Drop the game_ids column from player_sets
ALTER TABLE player_sets
DROP COLUMN game_ids;

-- Add the set_id column to player_games
ALTER TABLE player_games
ADD COLUMN set_id INTEGER;

-- Update the primary key of player_games
ALTER TABLE player_games
DROP CONSTRAINT player_games_pkey;

ALTER TABLE player_games
ADD PRIMARY KEY (game_id, requester_id, set_id);
4 changes: 4 additions & 0 deletions database/src/db_models/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ pub struct Game {
requester_char_played: Option<String>,
opponent_char_played: Option<String>,
stage: Option<String>,
set_id: i32,
}

impl Game {
#[allow(clippy::too_many_arguments)]
pub fn new(
gid: i32,
rid: i32,
Expand All @@ -25,6 +27,7 @@ impl Game {
rcp_num_o: Option<i32>,
ocp_num_o: Option<i32>,
s: Option<String>,
sid: i32,
) -> Self {
Self {
game_id: gid,
Expand All @@ -34,6 +37,7 @@ impl Game {
requester_char_played: rcp_num_o.map(get_character_from_id),
opponent_char_played: ocp_num_o.map(get_character_from_id),
stage: s,
set_id: sid,
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions database/src/db_models/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Player {
pub gender_pronouns: Option<String>,
pub birthday: Option<String>,
pub bio: Option<String>,
pub rankings: Option<Vec<String>>,
pub rankings: Option<Vec<Option<String>>>,
}

impl From<startgg::Player> for Player {
Expand Down Expand Up @@ -70,8 +70,8 @@ impl From<startgg::Player> for Player {
bio: u.bio,
rankings: p.rankings.map(|r| {
r.iter()
.map(|pr| format!("#{} @ {}", pr.rank, pr.title))
.collect::<Vec<String>>()
.map(|pr| Some(format!("#{} @ {}", pr.rank, pr.title)))
.collect::<Vec<Option<String>>>()
}),
}
}
Expand Down
6 changes: 0 additions & 6 deletions database/src/db_models/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use serde::Serialize;
// — an auto fix for this exists only in Diesel v2.
use crate::schema::player_sets;

use crate::db_models::game::Game;

#[derive(Debug, Serialize, Insertable, Queryable, QueryableByName)]
#[table_name = "player_sets"]
pub struct Set {
Expand All @@ -20,7 +18,6 @@ pub struct Set {
opponent_score: i32,
opponent_seed: i32,
result_type: i32,
game_ids: Option<Vec<i32>>,
event_id: i32,
tournament_id: i32,
is_event_online: bool,
Expand All @@ -35,7 +32,6 @@ impl Set {
is_on: bool,
e_id: i32,
t_id: i32,
maybe_games: Option<Vec<Game>>,
rtag: &str,
rscore: i32,
rseed: i32,
Expand All @@ -59,8 +55,6 @@ impl Set {
is_event_online: is_on,
event_id: e_id,
tournament_id: t_id,
game_ids: maybe_games
.map(|games| games.iter().map(|g| g.game_id).collect::<Vec<i32>>()),
}
}
}
Expand Down
22 changes: 12 additions & 10 deletions database/src/schema.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
table! {
// @generated automatically by Diesel CLI.

diesel::table! {
empty_player_ids (player_id) {
player_id -> Int4,
}
}

table! {
diesel::table! {
last_checked_player_id (player_id) {
player_id -> Int4,
}
}

table! {
player_games (game_id, requester_id) {
diesel::table! {
player_games (game_id, requester_id, set_id) {
game_id -> Int4,
requester_id -> Int4,
requester_win -> Nullable<Bool>,
order_num -> Int4,
requester_char_played -> Nullable<Varchar>,
opponent_char_played -> Nullable<Varchar>,
stage -> Nullable<Varchar>,
set_id -> Int4,
}
}

table! {
diesel::table! {
player_sets (id, requester_id) {
id -> Int4,
completed_at -> Int8,
Expand All @@ -34,14 +37,13 @@ table! {
opponent_score -> Int4,
opponent_seed -> Int4,
result_type -> Int4,
game_ids -> Nullable<Array<Int4>>,
event_id -> Int4,
tournament_id -> Int4,
is_event_online -> Bool,
}
}

table! {
diesel::table! {
player_tournaments (tournament_id, event_id, requester_id) {
tournament_id -> Int4,
event_id -> Int4,
Expand All @@ -56,7 +58,7 @@ table! {
}
}

table! {
diesel::table! {
players (player_id) {
player_id -> Int4,
user_slug -> Varchar,
Expand All @@ -71,11 +73,11 @@ table! {
gender_pronouns -> Nullable<Varchar>,
birthday -> Nullable<Varchar>,
bio -> Nullable<Varchar>,
rankings -> Nullable<Array<Text>>,
rankings -> Nullable<Array<Nullable<Text>>>,
}
}

allow_tables_to_appear_in_same_query!(
diesel::allow_tables_to_appear_in_same_query!(
empty_player_ids,
last_checked_player_id,
player_games,
Expand Down
2 changes: 1 addition & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ test = false
[dependencies]
anyhow = "1"
tracing = "0.1"
tracing-subscriber = "0.3"
diesel = { version = "1.4", features = ["postgres"] }
smithe_database = { path = "../database" }
startgg = { path = "../startgg_api" }
ctrlc = "3.2"
as-any = "0.3"
tokio = { version = "1.1", features = [ "rt", "macros" ] }
tracing-test = "0.2"
chrono = "0.4"
32 changes: 27 additions & 5 deletions lib/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![allow(unused)]

use anyhow::Result;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;

use std::{
future::Future,
Expand All @@ -13,6 +15,16 @@ use std::{
time::{Duration, Instant},
};

pub fn init_logger() -> Result<()> {
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::INFO)
.finish();

tracing::subscriber::set_global_default(subscriber)?;

Ok(())
}

use startgg::{GQLData, GQLVars};

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -47,15 +59,15 @@ where

let mut curr_page = start;
let mut now = Instant::now();
loop {
'outer: loop {
let result;
loop {
'inner: loop {
tracing::info!("🍥 querying StartGG API...");
match get_pages(curr_page, gql_vars.clone()).await {
Ok(data) => {
tracing::info!("🍥 got data for page {}", &curr_page);
result = data;
break;
break 'inner;
}
Err(e) => {
if e.to_string().contains("429")
Expand Down Expand Up @@ -83,10 +95,20 @@ where
now = Instant::now();
}
} else {
tracing::info!(
tracing::error!(
"🙃 an oddity happened, skipping for now ({:#?})...",
e.to_string()
);

// weird error, skip this iteration
if e.to_string()
.contains("Look at json field for more details")
{
curr_page = increment(curr_page)?;
continue 'outer;
}

// else, if set getter, we prob. want to panic
let mut gql_vars_lock = gql_vars.lock().unwrap();
*gql_vars_lock = gql_vars_lock.update();
}
Expand All @@ -95,7 +117,7 @@ where
}

if execute(curr_page, result)? {
break;
break 'outer;
} else {
curr_page = increment(curr_page)?;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub fn maybe_get_games_from_set(
player_id: i32,
requester_entrant_id: i32,
s: &SGGSet,
sid: i32,
) -> Option<Vec<Game>> {
s.clone().games.map(|gs| {
gs.iter()
Expand Down Expand Up @@ -33,6 +34,7 @@ pub fn maybe_get_games_from_set(
rcp_num,
ocp_num,
g.stage.as_ref().map(|se| se.name.clone()),
sid,
)
})
.collect::<Vec<Game>>()
Expand Down
Loading

0 comments on commit 8549f5e

Please sign in to comment.