Skip to content

Commit

Permalink
random stuff :(
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwaeseperlman committed Feb 12, 2024
1 parent f03cf4c commit 6c07447
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 35 deletions.
5 changes: 3 additions & 2 deletions deployment/lib/resources-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export class ResultsWorkerConstruct extends Construct {
NEW_GAMES_QUEUE_URL: new_games_sqs.queueUrl,
BUILD_LOGS_S3_BUCKET: build_logs_s3.bucketName,
GAME_LOGS_S3_BUCKET: game_logs_s3.bucketName,
RUST_LOG: "info",
},
secrets: {
DB_PASSWORD: ecs.Secret.fromSecretsManager(password),
Expand Down Expand Up @@ -373,7 +374,7 @@ export class ResourcesStack extends cdk.Stack {
zoneName: process.env.DOMAIN_NAME as string,
});*/
const cert = new certManager.Certificate(this, "cert", {
domainName: process.env.DOMAIN_NAME as string,
domainName: "upac.dev",
validation: certManager.CertificateValidation.fromDns(),
});
const vpc = new ec2.Vpc(this, "app-vpc", {
Expand Down Expand Up @@ -464,7 +465,7 @@ export class ResourcesStack extends cdk.Stack {
vpc,
dbPassword,
cert,
process.env.DOMAIN_NAME as string,
"upac.dev",
bot_s3,
bot_uploads_sqs,
new_games_sqs,
Expand Down
2 changes: 1 addition & 1 deletion shared/src/db/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub struct GameResult {
pub challenger_rating: f32,
}

#[derive(Deserialize, Debug, Selectable, Insertable, TS)]
#[derive(Deserialize, Debug, Selectable, Insertable, TS, AsChangeset)]
#[cfg_attr(feature = "ts-bindings", ts(export))]
#[diesel(table_name = game_results)]
pub struct NewGameResult {
Expand Down
10 changes: 5 additions & 5 deletions website/app/src/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function LogoText({ text }: { text: string }) {
<Typography
level="h1"
color="inherit"
sx={theme => ({
sx={(theme) => ({
fontSize: 100,
[theme.breakpoints.down("sm")]: {
fontSize: 88,
Expand All @@ -41,7 +41,7 @@ export function LogoText({ text }: { text: string }) {
transition: "text-shadow 0.2s ease",
},
"&:hover:before": {
textShadow: vals2
textShadow: vals2,
},
})}
>
Expand All @@ -61,7 +61,6 @@ export default function HomePage() {
flexDirection: "column",
justifyContent: "center",
display: "flex",
pb: 4,
}}
>
<Box
Expand All @@ -71,14 +70,15 @@ export default function HomePage() {
display: "flex",
maxWidth: "700px",
flexGrow: 1,
gap: 4,
gap: 2,
}}
>
<Box
sx={{
display: "flex",
flexDirection: "column",
flexDirection: "row",
alignItems: "left",
gap: 4,
}}
>
<LogoText text="UPAC" />
Expand Down
55 changes: 32 additions & 23 deletions workers/results/src/game_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use diesel::prelude::*;
use futures_lite::StreamExt;
use log::error;
use shared::{
poker::game::GameStateSQL,
db::{
self,
models::{self, Bot, Game, NewBot, Team},
Expand All @@ -13,6 +12,7 @@ use shared::{
teams,
},
},
poker::game::GameStateSQL,
GameError, GameStatus, GameStatusMessage, WhichBot,
};

Expand All @@ -26,6 +26,7 @@ pub fn sb_to_team(sb: WhichBot) -> [usize; 2] {
}

pub async fn save_game_details<T: AsRef<str>>(id: T) -> Result<(), ()> {
log::info!("Saving game details for {}", id.as_ref());
let id_str = id.as_ref();
let config = shared::aws_config().await;
let s3 = shared::s3_client(&config).await;
Expand Down Expand Up @@ -78,20 +79,20 @@ pub async fn handle_game_result(status: GameStatusMessage) -> Result<(), ()> {
Err(e) => match e {
GameError::InternalError => (starting_stack_size, starting_stack_size),
GameError::InvalidActionError(which_bot) => match which_bot {
shared::WhichBot::Defender => (-2*starting_stack_size, 2*starting_stack_size),
shared::WhichBot::Challenger => (2*starting_stack_size, -2*starting_stack_size),
shared::WhichBot::Defender => (-starting_stack_size, starting_stack_size),
shared::WhichBot::Challenger => (starting_stack_size, -starting_stack_size),
},
GameError::MemoryError(which_bot) => match which_bot {
shared::WhichBot::Defender => (-2*starting_stack_size, 2*starting_stack_size),
shared::WhichBot::Challenger => (2*starting_stack_size, -2*starting_stack_size),
shared::WhichBot::Defender => (-starting_stack_size, starting_stack_size),
shared::WhichBot::Challenger => (starting_stack_size, -starting_stack_size),
},
GameError::RunTimeError(which_bot) => match which_bot {
shared::WhichBot::Defender => (-2*starting_stack_size, 2*starting_stack_size),
shared::WhichBot::Challenger => (2*starting_stack_size, -2*starting_stack_size),
shared::WhichBot::Defender => (-starting_stack_size, starting_stack_size),
shared::WhichBot::Challenger => (starting_stack_size, -starting_stack_size),
},
GameError::TimeoutError(which_bot) => match which_bot {
shared::WhichBot::Defender => (-2*starting_stack_size, 2*starting_stack_size),
shared::WhichBot::Challenger => (2*starting_stack_size, -2*starting_stack_size),
shared::WhichBot::Defender => (-starting_stack_size, starting_stack_size),
shared::WhichBot::Challenger => (starting_stack_size, -starting_stack_size),
},
},
};
Expand All @@ -108,12 +109,14 @@ pub async fn handle_game_result(status: GameStatusMessage) -> Result<(), ()> {
e
})?;
// calculate the bots ratings
let score = (starting_stack_size as f32 + defender_score as f32) / (2.0f32*starting_stack_size as f32);
let score = (starting_stack_size as f32 + defender_score as f32)
/ (2.0f32 * starting_stack_size as f32);
log::info!(
"Score: {}, defender score {}, challenger score {}",
"Score: {}, defender score {}, challenger score {}, starting stack size {}",
score,
defender_score,
challenger_score
challenger_score,
starting_stack_size
);
// Don't rate games that had an internal error
(defender_rating_change, challenger_rating_change) = get_rating_change(
Expand Down Expand Up @@ -161,21 +164,27 @@ pub async fn handle_game_result(status: GameStatusMessage) -> Result<(), ()> {
challenger
);

diesel::insert_into(game_results::table)
.values(models::NewGameResult {
id: id.clone(),
challenger_rating_change,
defender_rating_change,
defender_score,
challenger_score,
error_type: error_type.clone(),
challenger_rating: challenger.rating,
defender_rating: defender.rating,
})
let new_result = models::NewGameResult {
id: id.clone(),
challenger_rating_change,
defender_rating_change,
defender_score,
challenger_score,
error_type: error_type.clone(),
challenger_rating: challenger.rating,
defender_rating: defender.rating,
};
diesel::insert_into(game_results::dsl::game_results)
.values(&new_result)
.on_conflict(game_results::dsl::id)
.do_update()
.set(&new_result)
.execute(db_conn)?;
log::debug!("Inserted game result for {}", id.clone());
diesel::update(games::table.find(id.clone()))
.set(games::dsl::running.eq(false))
.execute(db_conn)?;
log::debug!("Not running for {}", id.clone());
}
Ok(GameStatus::TestGameSucceeded) => {
// set the active bot for the team if they don't have one
Expand Down
9 changes: 5 additions & 4 deletions workers/results/src/matchmaking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ pub async fn matchmake(s3_client: &aws_sdk_s3::Client, sqs_client: &aws_sdk_sqs:
.parse::<u64>()
.unwrap_or(60000);
// give an average of 60 seconds per game, plus 10
tokio::time::sleep(std::time::Duration::from_secs(
1
) + std::time::Duration::from_millis(matchmaking_interval))
tokio::time::sleep(
std::time::Duration::from_secs(1)
+ std::time::Duration::from_millis(matchmaking_interval),
)
.await;
}
}
Expand Down Expand Up @@ -74,7 +75,7 @@ pub async fn matchmake_round(
Ok(_) => {
log::info!("Created game between {} and {}", this.name, other.name);
}
Err(_) => {
Err(err) => {
log::info!(
"Failed to create game between {} and {}",
this.name,
Expand Down

0 comments on commit 6c07447

Please sign in to comment.