handle null teams in events

This commit is contained in:
Robin Appelman 2020-06-21 15:51:46 +02:00
commit 648d443847
3 changed files with 56 additions and 46 deletions

View file

@ -52,27 +52,31 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
for event in &round.events { for event in &round.events {
match event { match event {
Event::PointCap { time, team, point } => { Event::PointCap { time, team, point } => {
sqlx::query!( if let Some(team) = team {
"INSERT INTO events_point_cap(round_id, time, team, point)\ sqlx::query!(
"INSERT INTO events_point_cap(round_id, time, team, point)\
VALUES($1, $2, $3, $4)", VALUES($1, $2, $3, $4)",
round_id, round_id,
*time as i32, *time as i32,
*team as TeamId, *team as TeamId,
*point as i32, *point as i32,
) )
.execute(&mut tx) .execute(&mut tx)
.await?; .await?;
}
} }
Event::RoundWin { time, team } => { Event::RoundWin { time, team } => {
sqlx::query!( if let Some(team) = team {
"INSERT INTO events_round_win(round_id, time, team)\ sqlx::query!(
"INSERT INTO events_round_win(round_id, time, team)\
VALUES($1, $2, $3)", VALUES($1, $2, $3)",
round_id, round_id,
*time as i32, *time as i32,
team.unwrap_or_default() as TeamId, team.unwrap_or_default() as TeamId,
) )
.execute(&mut tx) .execute(&mut tx)
.await?; .await?;
}
} }
Event::MedicDeath { Event::MedicDeath {
time, time,
@ -80,7 +84,8 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
steamid, steamid,
killer, killer,
} => { } => {
sqlx::query!( if let Some(team) = team {
sqlx::query!(
"INSERT INTO events_medic_death(round_id, time, team, steam_id, killer)\ "INSERT INTO events_medic_death(round_id, time, team, steam_id, killer)\
VALUES($1, $2, $3, $4, $5)", VALUES($1, $2, $3, $4, $5)",
round_id, round_id,
@ -89,24 +94,27 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
u64::from(*steamid) as i64, u64::from(*steamid) as i64,
u64::from(*killer) as i64, u64::from(*killer) as i64,
) )
.execute(&mut tx) .execute(&mut tx)
.await?; .await?;
}
} }
Event::Drop { Event::Drop {
time, time,
steamid, steamid,
team, team,
} => { } => {
sqlx::query!( if let Some(team) = team {
"INSERT INTO events_drop(round_id, time, team, steam_id)\ sqlx::query!(
"INSERT INTO events_drop(round_id, time, team, steam_id)\
VALUES($1, $2, $3, $4)", VALUES($1, $2, $3, $4)",
round_id, round_id,
*time as i32, *time as i32,
*team as TeamId, *team as TeamId,
u64::from(*steamid) as i64, u64::from(*steamid) as i64,
) )
.execute(&mut tx) .execute(&mut tx)
.await?; .await?;
}
} }
Event::Charge { Event::Charge {
medigun, medigun,
@ -114,17 +122,19 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
steamid, steamid,
team, team,
} => { } => {
sqlx::query!( if let Some(team) = team {
"INSERT INTO events_charge(round_id, time, team, medigun, steam_id)\ sqlx::query!(
"INSERT INTO events_charge(round_id, time, team, medigun, steam_id)\
VALUES($1, $2, $3, $4, $5)", VALUES($1, $2, $3, $4, $5)",
round_id, round_id,
*time as i32, *time as i32,
*team as TeamId, *team as TeamId,
*medigun as Medigun, *medigun as Medigun,
u64::from(*steamid) as i64, u64::from(*steamid) as i64,
) )
.execute(&mut tx) .execute(&mut tx)
.await?; .await?;
}
} }
_ => {} _ => {}
} }

View file

@ -166,7 +166,7 @@ impl From<crate::raw::Round> for Round {
.first_cap .first_cap
.or_else(|| { .or_else(|| {
raw.events.iter().find_map(|event| match event { raw.events.iter().find_map(|event| match event {
Event::PointCap { team, .. } => Some(*team), Event::PointCap { team, .. } => *team,
_ => None, _ => None,
}) })
}) })
@ -231,7 +231,7 @@ fn normalize_stopwatch_events(log: &mut NormalizedLog) {
let last_event = log.rounds[1].events.pop(); let last_event = log.rounds[1].events.pop();
log.rounds[1].events.push(Event::PointCap { log.rounds[1].events.push(Event::PointCap {
time: second_half_end_time, time: second_half_end_time,
team: TeamId::Blue, team: Some(TeamId::Blue),
point: first_half_rounds, point: first_half_rounds,
}); });
if let Some(last_event) = last_event { if let Some(last_event) = last_event {

View file

@ -196,28 +196,28 @@ pub enum Event {
medigun: Medigun, medigun: Medigun,
time: u32, time: u32,
steamid: SteamID, steamid: SteamID,
team: TeamId, team: Option<TeamId>,
}, },
#[serde(rename = "pointcap")] #[serde(rename = "pointcap")]
PointCap { PointCap {
time: u32, time: u32,
team: TeamId, team: Option<TeamId>,
point: u8, point: u8,
}, },
MedicDeath { MedicDeath {
time: u32, time: u32,
team: TeamId, team: Option<TeamId>,
steamid: SteamID, steamid: SteamID,
killer: SteamID, killer: SteamID,
}, },
RoundWin { RoundWin {
time: u32, time: u32,
team: Option<TeamId>, team: Option<Option<TeamId>>,
}, },
Drop { Drop {
time: u32, time: u32,
steamid: SteamID, steamid: SteamID,
team: TeamId, team: Option<TeamId>,
}, },
#[serde(other)] #[serde(other)]
Other, Other,