-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
db-ingest: Add Active Matches Ingest
- Loading branch information
Showing
14 changed files
with
372 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
CREATE TABLE IF NOT EXISTS active_matches | ||
( | ||
match_id UInt32, | ||
scraped_at DateTime64, | ||
start_time DATETIME, | ||
winning_team UInt8, | ||
players Nested ( | ||
account_id UInt64, | ||
team Enum8 ( | ||
'Team0' = 0, | ||
'Team1' = 1, | ||
'Spectator' = 16, | ||
), | ||
abandoned bool, | ||
hero_id UInt32 | ||
), | ||
lobby_id UInt64, | ||
net_worth_team_0 UInt32, | ||
net_worth_team_1 UInt32, | ||
duration_s UInt32, | ||
spectators UInt32, | ||
open_spectator_slots UInt32, | ||
objectives_mask_team0 UInt16, | ||
objectives_mask_team1 UInt16, | ||
match_mode Enum8 ( | ||
'Invalid' = 0, | ||
'Unranked' = 1, | ||
'PrivateLobby' = 2, | ||
'CoopBot' = 3, | ||
'Ranked' = 4, | ||
'ServerTest' = 5, | ||
'Tutorial' = 6 | ||
), | ||
game_mode Enum8 ( | ||
'Invalid' = 0, 'Normal' = 1, 'OneVsOneTest' = 2, 'Sandbox' = 3 | ||
), | ||
match_score UInt32, | ||
region_mode Enum8 ( | ||
'Row' = 0, | ||
'Europe' = 1, | ||
'SEAsia' = 2, | ||
'SAmerica' = 3, | ||
'Russia' = 4, | ||
'Oceania' = 5 | ||
) | ||
) ENGINE = ReplacingMergeTree() ORDER BY (match_id, scraped_at); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Deserialize, Serialize, Clone)] | ||
pub struct ActiveMatch { | ||
pub match_id: u32, | ||
pub scraped_at: i64, | ||
pub winning_team: u8, | ||
pub start_time: u32, | ||
pub players: Vec<ActiveMatchPlayer>, | ||
pub lobby_id: u64, | ||
pub duration_s: u32, | ||
pub spectators: u32, | ||
pub open_spectator_slots: u32, | ||
pub objectives_mask_team0: u16, | ||
pub objectives_mask_team1: u16, | ||
pub net_worth_team_0: u32, | ||
pub net_worth_team_1: u32, | ||
pub match_mode: u8, | ||
pub game_mode: u8, | ||
pub match_score: u32, | ||
pub region_mode: u8, | ||
} | ||
|
||
#[derive(Debug, Deserialize, Serialize, Clone)] | ||
pub struct ActiveMatchPlayer { | ||
pub account_id: u64, | ||
pub team: u8, | ||
pub abandoned: bool, | ||
pub hero_id: u32, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::models::active_match::ActiveMatch; | ||
use crate::models::enums::{GameMode, MatchMode, RegionMode, Team}; | ||
use clickhouse::Row; | ||
use serde::Serialize; | ||
|
||
#[derive(Row, Serialize, Debug)] | ||
pub struct ClickHouseActiveMatch { | ||
pub match_id: u32, | ||
pub scraped_at: i64, | ||
pub start_time: u32, | ||
pub winning_team: u8, | ||
#[serde(rename = "players.account_id")] | ||
pub players_account_id: Vec<u64>, | ||
#[serde(rename = "players.team")] | ||
pub players_team: Vec<Team>, | ||
#[serde(rename = "players.abandoned")] | ||
pub players_abandoned: Vec<bool>, | ||
#[serde(rename = "players.hero_id")] | ||
pub players_hero_id: Vec<u32>, | ||
pub lobby_id: u64, | ||
pub net_worth_team_0: u32, | ||
pub net_worth_team_1: u32, | ||
pub duration_s: u32, | ||
pub spectators: u32, | ||
pub open_spectator_slots: u32, | ||
pub objectives_mask_team0: u16, | ||
pub objectives_mask_team1: u16, | ||
pub match_mode: MatchMode, | ||
pub game_mode: GameMode, | ||
pub match_score: u32, | ||
pub region_mode: RegionMode, | ||
} | ||
|
||
impl From<ActiveMatch> for ClickHouseActiveMatch { | ||
fn from(am: ActiveMatch) -> Self { | ||
Self { | ||
start_time: am.start_time, | ||
winning_team: am.winning_team, | ||
match_id: am.match_id, | ||
scraped_at: am.scraped_at, | ||
players_account_id: am.players.iter().map(|p| p.account_id).collect(), | ||
players_team: am.players.iter().map(|p| p.team).map(Team::from).collect(), | ||
players_abandoned: am.players.iter().map(|p| p.abandoned).collect(), | ||
players_hero_id: am.players.iter().map(|p| p.hero_id).collect(), | ||
lobby_id: am.lobby_id, | ||
net_worth_team_0: am.net_worth_team_0, | ||
net_worth_team_1: am.net_worth_team_1, | ||
duration_s: am.duration_s, | ||
spectators: am.spectators, | ||
open_spectator_slots: am.open_spectator_slots, | ||
objectives_mask_team0: am.objectives_mask_team0, | ||
objectives_mask_team1: am.objectives_mask_team1, | ||
match_mode: MatchMode::from(am.match_mode), | ||
game_mode: GameMode::from(am.game_mode), | ||
match_score: am.match_score, | ||
region_mode: RegionMode::from(am.region_mode), | ||
} | ||
} | ||
} |
Oops, something went wrong.