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,6 +52,7 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
for event in &round.events {
match event {
Event::PointCap { time, team, point } => {
if let Some(team) = team {
sqlx::query!(
"INSERT INTO events_point_cap(round_id, time, team, point)\
VALUES($1, $2, $3, $4)",
@ -63,7 +64,9 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
.execute(&mut tx)
.await?;
}
}
Event::RoundWin { time, team } => {
if let Some(team) = team {
sqlx::query!(
"INSERT INTO events_round_win(round_id, time, team)\
VALUES($1, $2, $3)",
@ -74,12 +77,14 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
.execute(&mut tx)
.await?;
}
}
Event::MedicDeath {
time,
team,
steamid,
killer,
} => {
if let Some(team) = team {
sqlx::query!(
"INSERT INTO events_medic_death(round_id, time, team, steam_id, killer)\
VALUES($1, $2, $3, $4, $5)",
@ -92,11 +97,13 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
.execute(&mut tx)
.await?;
}
}
Event::Drop {
time,
steamid,
team,
} => {
if let Some(team) = team {
sqlx::query!(
"INSERT INTO events_drop(round_id, time, team, steam_id)\
VALUES($1, $2, $3, $4)",
@ -108,12 +115,14 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
.execute(&mut tx)
.await?;
}
}
Event::Charge {
medigun,
time,
steamid,
team,
} => {
if let Some(team) = team {
sqlx::query!(
"INSERT INTO events_charge(round_id, time, team, medigun, steam_id)\
VALUES($1, $2, $3, $4, $5)",
@ -126,6 +135,7 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
.execute(&mut tx)
.await?;
}
}
_ => {}
}
}

View file

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

View file

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