mirror of
https://codeberg.org/icewind/log-normalizer.git
synced 2026-06-03 13:54:11 +02:00
handle null teams in events
This commit is contained in:
parent
5778c6164b
commit
648d443847
3 changed files with 56 additions and 46 deletions
|
|
@ -52,6 +52,7 @@ 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 } => {
|
||||||
|
if let Some(team) = team {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO events_point_cap(round_id, time, team, point)\
|
"INSERT INTO events_point_cap(round_id, time, team, point)\
|
||||||
VALUES($1, $2, $3, $4)",
|
VALUES($1, $2, $3, $4)",
|
||||||
|
|
@ -63,7 +64,9 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
|
||||||
.execute(&mut tx)
|
.execute(&mut tx)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Event::RoundWin { time, team } => {
|
Event::RoundWin { time, team } => {
|
||||||
|
if let Some(team) = team {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO events_round_win(round_id, time, team)\
|
"INSERT INTO events_round_win(round_id, time, team)\
|
||||||
VALUES($1, $2, $3)",
|
VALUES($1, $2, $3)",
|
||||||
|
|
@ -74,12 +77,14 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
|
||||||
.execute(&mut tx)
|
.execute(&mut tx)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Event::MedicDeath {
|
Event::MedicDeath {
|
||||||
time,
|
time,
|
||||||
team,
|
team,
|
||||||
steamid,
|
steamid,
|
||||||
killer,
|
killer,
|
||||||
} => {
|
} => {
|
||||||
|
if let Some(team) = team {
|
||||||
sqlx::query!(
|
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)",
|
||||||
|
|
@ -92,11 +97,13 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
|
||||||
.execute(&mut tx)
|
.execute(&mut tx)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Event::Drop {
|
Event::Drop {
|
||||||
time,
|
time,
|
||||||
steamid,
|
steamid,
|
||||||
team,
|
team,
|
||||||
} => {
|
} => {
|
||||||
|
if let Some(team) = team {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO events_drop(round_id, time, team, steam_id)\
|
"INSERT INTO events_drop(round_id, time, team, steam_id)\
|
||||||
VALUES($1, $2, $3, $4)",
|
VALUES($1, $2, $3, $4)",
|
||||||
|
|
@ -108,12 +115,14 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
|
||||||
.execute(&mut tx)
|
.execute(&mut tx)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Event::Charge {
|
Event::Charge {
|
||||||
medigun,
|
medigun,
|
||||||
time,
|
time,
|
||||||
steamid,
|
steamid,
|
||||||
team,
|
team,
|
||||||
} => {
|
} => {
|
||||||
|
if let Some(team) = team {
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"INSERT INTO events_charge(round_id, time, team, medigun, steam_id)\
|
"INSERT INTO events_charge(round_id, time, team, medigun, steam_id)\
|
||||||
VALUES($1, $2, $3, $4, $5)",
|
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)
|
.execute(&mut tx)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
10
src/raw.rs
10
src/raw.rs
|
|
@ -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,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue