save matchplayer had_errors in database
This commit is contained in:
parent
2278ecd258
commit
eb2cbb15fb
5 changed files with 32 additions and 4 deletions
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE match_players DROP COLUMN had_errors;
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE match_players ADD COLUMN had_errors boolean;
|
|
@ -55,6 +55,7 @@ pub struct MatchPlayer {
|
||||||
pub match_id: i32,
|
pub match_id: i32,
|
||||||
pub player_id: i32,
|
pub player_id: i32,
|
||||||
pub code_bundle_id: Option<i32>,
|
pub code_bundle_id: Option<i32>,
|
||||||
|
pub had_errors: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MatchPlayerData {
|
pub struct MatchPlayerData {
|
||||||
|
@ -190,7 +191,7 @@ pub fn list_bot_matches(
|
||||||
amount,
|
amount,
|
||||||
};
|
};
|
||||||
|
|
||||||
let matches = lbm.get_results::<MatchBase>(conn)?;
|
let matches = lbm.get_results(conn)?;
|
||||||
fetch_full_match_data(matches, conn)
|
fetch_full_match_data(matches, conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,6 +295,24 @@ pub fn save_match_result(id: i32, result: MatchResult, conn: &mut PgConnection)
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_player_had_errors(
|
||||||
|
match_id: i32,
|
||||||
|
player_id: i32,
|
||||||
|
had_errors: bool,
|
||||||
|
conn: &mut PgConnection,
|
||||||
|
) -> QueryResult<()> {
|
||||||
|
let num_modified = diesel::update(match_players::table)
|
||||||
|
.filter(match_players::match_id.eq(match_id))
|
||||||
|
.filter(match_players::player_id.eq(player_id))
|
||||||
|
.set(match_players::had_errors.eq(had_errors))
|
||||||
|
.execute(conn)?;
|
||||||
|
if num_modified == 0 {
|
||||||
|
Err(diesel::result::Error::NotFound)
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(QueryableByName)]
|
#[derive(QueryableByName)]
|
||||||
pub struct BotStatsRecord {
|
pub struct BotStatsRecord {
|
||||||
#[diesel(sql_type = Text)]
|
#[diesel(sql_type = Text)]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use diesel::{PgConnection, QueryResult};
|
use diesel::{Connection, PgConnection, QueryResult};
|
||||||
use planetwars_matchrunner::{self as runner, docker_runner::DockerBotSpec, BotSpec, MatchConfig};
|
use planetwars_matchrunner::{self as runner, docker_runner::DockerBotSpec, BotSpec, MatchConfig};
|
||||||
use runner::MatchOutcome;
|
use runner::MatchOutcome;
|
||||||
use std::{path::PathBuf, sync::Arc};
|
use std::{path::PathBuf, sync::Arc};
|
||||||
|
@ -176,7 +176,13 @@ async fn run_match_task(
|
||||||
winner: outcome.winner.map(|w| (w - 1) as i32), // player numbers in matchrunner start at 1
|
winner: outcome.winner.map(|w| (w - 1) as i32), // player numbers in matchrunner start at 1
|
||||||
};
|
};
|
||||||
|
|
||||||
db::matches::save_match_result(match_id, result, &mut conn)
|
conn.transaction(|conn| {
|
||||||
|
for (player_id, player_outcome) in outcome.player_outcomes.iter().enumerate() {
|
||||||
|
let had_errors = player_outcome.had_errors || player_outcome.crashed;
|
||||||
|
db::matches::set_player_had_errors(match_id, player_id as i32, had_errors, conn)?;
|
||||||
|
}
|
||||||
|
db::matches::save_match_result(match_id, result, conn)
|
||||||
|
})
|
||||||
.expect("could not save match result");
|
.expect("could not save match result");
|
||||||
|
|
||||||
outcome
|
outcome
|
||||||
|
|
|
@ -53,6 +53,7 @@ diesel::table! {
|
||||||
match_id -> Int4,
|
match_id -> Int4,
|
||||||
player_id -> Int4,
|
player_id -> Int4,
|
||||||
bot_version_id -> Nullable<Int4>,
|
bot_version_id -> Nullable<Int4>,
|
||||||
|
had_errors -> Nullable<Bool>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue