sqlx update + clippy

This commit is contained in:
Robin Appelman 2024-02-10 18:52:54 +01:00
commit e1a4036b61
29 changed files with 1261 additions and 776 deletions

View file

@ -0,0 +1,27 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO events_round_win(round_id, time, team)VALUES($1, $2, $3)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4",
"Int4",
{
"Custom": {
"name": "team",
"kind": {
"Enum": [
"blue",
"red",
"other"
]
}
}
}
]
},
"nullable": []
},
"hash": "0000e8f1c60464bde61980810f4013b3ff71d318291de9d8cf595474f4ee8f32"
}

View file

@ -0,0 +1,72 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO players (log_id, steam_id, name, team, kills, deaths, assists,suicides, dmg, damage_taken, ubers, medigun_ubers,kritzkrieg_ubers, quickfix_ubers, vaccinator_ubers,drops, medkits, medkits_hp, backstabs, headshots,heal, heals_received,scout_kills, soldier_kills, pyro_kills, demoman_kills,heavy_kills, engineer_kills, medic_kills, sniper_kills, spy_kills,\n scout_deaths, soldier_deaths, pyro_deaths, demoman_deaths,heavy_deaths, engineer_deaths, medic_deaths, sniper_deaths, spy_deaths\n )VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,$11, $12, $13, $14, $15, $16, $17, $18, $19, $20,$21, $22, $23, $24, $25, $26, $27, $28, $29, $30,$31, $32, $33, $34, $35, $36, $37, $38, $39, $40)RETURNING id",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Int4",
"Int8",
"Text",
{
"Custom": {
"name": "team",
"kind": {
"Enum": [
"blue",
"red",
"other"
]
}
}
},
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4"
]
},
"nullable": [
false
]
},
"hash": "253ca64f81921ad7351335d8b47967a4b6831b16d8128a11b40daa63b31f5a4c"
}

View file

@ -0,0 +1,22 @@
{
"db_name": "PostgreSQL",
"query": "SELECT MIN(id) as \"id\" from logs WHERE version < $1",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int4"
}
],
"parameters": {
"Left": [
"Int2"
]
},
"nullable": [
null
]
},
"hash": "25a688892917d80b8746d77ebbcdfb4652c7047d722c530b4560d6008cdd2b97"
}

View file

@ -0,0 +1,51 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO logs(id, red_score, blue_score, length, game_mode, map, type, date, version)VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4",
"Int4",
"Int4",
"Int4",
{
"Custom": {
"name": "game_mode",
"kind": {
"Enum": [
"ultiduo",
"4v4",
"6v6",
"7v7",
"9v9",
"other"
]
}
}
},
"Text",
{
"Custom": {
"name": "map_type",
"kind": {
"Enum": [
"stopwatch",
"cp",
"koth",
"ctf",
"ultiduo",
"bball",
"other"
]
}
}
},
"Timestamp",
"Int2"
]
},
"nullable": []
},
"hash": "417cfaecb2cb45d16c9da2dc2f8e6d1a37280842a5fc9ffb85b5d1955a54670d"
}

View file

@ -0,0 +1,19 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO player_weapon_stats(class_stat_id, weapon, kills, shots, hits, dmg)VALUES($1, $2, $3, $4, $5, $6)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int8",
"Text",
"Int4",
"Int4",
"Int4",
"Int4"
]
},
"nullable": []
},
"hash": "425af9e4b088335acabe4bf74c3b11c0cab5f033b57197c992533889a4d1300d"
}

View file

@ -0,0 +1,41 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO events_charge(round_id, time, team, medigun, steam_id)VALUES($1, $2, $3, $4, $5)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4",
"Int4",
{
"Custom": {
"name": "team",
"kind": {
"Enum": [
"blue",
"red",
"other"
]
}
}
},
{
"Custom": {
"name": "medigun",
"kind": {
"Enum": [
"medigun",
"kritzkrieg",
"quickfix",
"vaccinator"
]
}
}
},
"Int8"
]
},
"nullable": []
},
"hash": "4dcd86f5ef23f46b5c6cd391522791a609e04e068009678ba95b81cb385b9e89"
}

View file

@ -0,0 +1,17 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO kill_streaks(log_id, steam_id, time, streak)VALUES($1, $2, $3, $4)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4",
"Int8",
"Int4",
"Int4"
]
},
"nullable": []
},
"hash": "581b192c18e54b711d0e3b6d38490984c48320fe4607c7eacc7b9002daaf7771"
}

View file

@ -0,0 +1,29 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO events_medic_death(round_id, time, team, steam_id, killer)VALUES($1, $2, $3, $4, $5)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4",
"Int4",
{
"Custom": {
"name": "team",
"kind": {
"Enum": [
"blue",
"red",
"other"
]
}
}
},
"Int8",
"Int8"
]
},
"nullable": []
},
"hash": "7669da21c453d1d4e5d5e7aead5a0fbc4307aba66debd679159374c5647fd0fe"
}

View file

@ -0,0 +1,28 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO events_drop(round_id, time, team, steam_id)VALUES($1, $2, $3, $4)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4",
"Int4",
{
"Custom": {
"name": "team",
"kind": {
"Enum": [
"blue",
"red",
"other"
]
}
}
},
"Int8"
]
},
"nullable": []
},
"hash": "982bc615a035019855317b3b47a3ac10159d81318db323c2d076c9b4c04a4e02"
}

View file

@ -0,0 +1,15 @@
{
"db_name": "PostgreSQL",
"query": "UPDATE logs SET version = $1 WHERE id = $2",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int2",
"Int4"
]
},
"nullable": []
},
"hash": "c9f31bcb2cb8b76f7cd2e66284b70f79e462ac70f94cdab022bdce63929731b1"
}

View file

@ -0,0 +1,46 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO class_stats(player_id, type, time, kills, deaths, assists, dmg)VALUES($1, $2, $3, $4, $5, $6, $7)RETURNING id",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Int8",
{
"Custom": {
"name": "class_type",
"kind": {
"Enum": [
"scout",
"soldier",
"pyro",
"demoman",
"heavyweapons",
"engineer",
"medic",
"sniper",
"spy",
"unknown"
]
}
}
},
"Int4",
"Int4",
"Int4",
"Int4",
"Int4"
]
},
"nullable": [
false
]
},
"hash": "d4d72675d0a0792d14472c6bfc00454791dea1eae933818d168171f818bb7dc9"
}

View file

@ -0,0 +1,56 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO rounds(\n round, log_id, length, winner, first_cap, red_score, blue_score,\n red_kills, blue_kills, red_dmg, blue_dmg, red_ubers, blue_ubers\n )\n VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)\n RETURNING id",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int4"
}
],
"parameters": {
"Left": [
"Int4",
"Int4",
"Int4",
{
"Custom": {
"name": "team",
"kind": {
"Enum": [
"blue",
"red",
"other"
]
}
}
},
{
"Custom": {
"name": "team",
"kind": {
"Enum": [
"blue",
"red",
"other"
]
}
}
},
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4"
]
},
"nullable": [
false
]
},
"hash": "eab40a01c0df317cdfb97eb4f88884f6776897ec2c2ecb8cae05748c8d087711"
}

View file

@ -0,0 +1,20 @@
{
"db_name": "PostgreSQL",
"query": "SELECT MAX(id) as id from logs",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int4"
}
],
"parameters": {
"Left": []
},
"nullable": [
null
]
},
"hash": "f4daaeeaaf227491627c0bb54319a5f356028a591fdac2f41ba2dce1c5053d4a"
}

View file

@ -0,0 +1,28 @@
{
"db_name": "PostgreSQL",
"query": "INSERT INTO events_point_cap(round_id, time, team, point)VALUES($1, $2, $3, $4)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4",
"Int4",
{
"Custom": {
"name": "team",
"kind": {
"Enum": [
"blue",
"red",
"other"
]
}
}
},
"Int4"
]
},
"nullable": []
},
"hash": "f8be06a1f3b2b9755faf3ca32921528528240308ed036cd6cf320ca4d31438b9"
}

839
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -9,10 +9,10 @@ name = "log-normalizer"
path = "src/main.rs" path = "src/main.rs"
[dependencies] [dependencies]
sqlx = { version = "0.6.0", default_features = false, features = ["macros", "postgres", "json", "chrono", "runtime-tokio-rustls", "offline"] } sqlx = { version = "0.7.3", default_features = false, features = ["macros", "postgres", "json", "chrono", "runtime-tokio-rustls"] }
dotenv = "0.15.0" dotenv = "0.15.0"
main_error = "0.1.2" main_error = "0.1.2"
tokio = { version = "1.20.0", features = ["macros", "time"] } tokio = { version = "1.20.0", features = ["macros", "time", "rt-multi-thread"] }
serde = { version = "1.0.140", features = ["derive"] } serde = { version = "1.0.140", features = ["derive"] }
serde_with = "3.6.1" serde_with = "3.6.1"
serde_json = "1.0.82" serde_json = "1.0.82"

View file

@ -32,6 +32,7 @@
cargo-edit cargo-edit
cargo-outdated cargo-outdated
cargo-insta cargo-insta
sqlx-cli
]; ];
}; };
} }

View file

@ -4,7 +4,7 @@
lib, lib,
}: let }: let
inherit (lib.sources) sourceByRegex; inherit (lib.sources) sourceByRegex;
src = sourceByRegex ./. ["Cargo.*" "(src|tests|sqlx-data.json)(/.*)?"]; src = sourceByRegex ./. ["Cargo.*" "(src|tests|.sqlx)(/.*)?"];
in in
rustPlatform.buildRustPackage rec { rustPlatform.buildRustPackage rec {
pname = "log-normalizer"; pname = "log-normalizer";

View file

@ -1,446 +0,0 @@
{
"db": "PostgreSQL",
"0000e8f1c60464bde61980810f4013b3ff71d318291de9d8cf595474f4ee8f32": {
"query": "INSERT INTO events_round_win(round_id, time, team)VALUES($1, $2, $3)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4",
"Int4",
{
"Custom": {
"name": "team",
"kind": {
"Enum": [
"blue",
"red",
"other"
]
}
}
}
]
},
"nullable": []
}
},
"253ca64f81921ad7351335d8b47967a4b6831b16d8128a11b40daa63b31f5a4c": {
"query": "INSERT INTO players (log_id, steam_id, name, team, kills, deaths, assists,suicides, dmg, damage_taken, ubers, medigun_ubers,kritzkrieg_ubers, quickfix_ubers, vaccinator_ubers,drops, medkits, medkits_hp, backstabs, headshots,heal, heals_received,scout_kills, soldier_kills, pyro_kills, demoman_kills,heavy_kills, engineer_kills, medic_kills, sniper_kills, spy_kills,\n scout_deaths, soldier_deaths, pyro_deaths, demoman_deaths,heavy_deaths, engineer_deaths, medic_deaths, sniper_deaths, spy_deaths\n )VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,$11, $12, $13, $14, $15, $16, $17, $18, $19, $20,$21, $22, $23, $24, $25, $26, $27, $28, $29, $30,$31, $32, $33, $34, $35, $36, $37, $38, $39, $40)RETURNING id",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Int4",
"Int8",
"Text",
{
"Custom": {
"name": "team",
"kind": {
"Enum": [
"blue",
"red",
"other"
]
}
}
},
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4"
]
},
"nullable": [
false
]
}
},
"25a688892917d80b8746d77ebbcdfb4652c7047d722c530b4560d6008cdd2b97": {
"query": "SELECT MIN(id) as \"id\" from logs WHERE version < $1",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int4"
}
],
"parameters": {
"Left": [
"Int2"
]
},
"nullable": [
null
]
}
},
"417cfaecb2cb45d16c9da2dc2f8e6d1a37280842a5fc9ffb85b5d1955a54670d": {
"query": "INSERT INTO logs(id, red_score, blue_score, length, game_mode, map, type, date, version)VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4",
"Int4",
"Int4",
"Int4",
{
"Custom": {
"name": "game_mode",
"kind": {
"Enum": [
"ultiduo",
"4v4",
"6v6",
"7v7",
"9v9",
"other"
]
}
}
},
"Text",
{
"Custom": {
"name": "map_type",
"kind": {
"Enum": [
"stopwatch",
"cp",
"koth",
"ctf",
"ultiduo",
"bball",
"other"
]
}
}
},
"Timestamp",
"Int2"
]
},
"nullable": []
}
},
"425af9e4b088335acabe4bf74c3b11c0cab5f033b57197c992533889a4d1300d": {
"query": "INSERT INTO player_weapon_stats(class_stat_id, weapon, kills, shots, hits, dmg)VALUES($1, $2, $3, $4, $5, $6)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int8",
"Text",
"Int4",
"Int4",
"Int4",
"Int4"
]
},
"nullable": []
}
},
"4dcd86f5ef23f46b5c6cd391522791a609e04e068009678ba95b81cb385b9e89": {
"query": "INSERT INTO events_charge(round_id, time, team, medigun, steam_id)VALUES($1, $2, $3, $4, $5)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4",
"Int4",
{
"Custom": {
"name": "team",
"kind": {
"Enum": [
"blue",
"red",
"other"
]
}
}
},
{
"Custom": {
"name": "medigun",
"kind": {
"Enum": [
"medigun",
"kritzkrieg",
"quickfix",
"vaccinator"
]
}
}
},
"Int8"
]
},
"nullable": []
}
},
"581b192c18e54b711d0e3b6d38490984c48320fe4607c7eacc7b9002daaf7771": {
"query": "INSERT INTO kill_streaks(log_id, steam_id, time, streak)VALUES($1, $2, $3, $4)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4",
"Int8",
"Int4",
"Int4"
]
},
"nullable": []
}
},
"7669da21c453d1d4e5d5e7aead5a0fbc4307aba66debd679159374c5647fd0fe": {
"query": "INSERT INTO events_medic_death(round_id, time, team, steam_id, killer)VALUES($1, $2, $3, $4, $5)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4",
"Int4",
{
"Custom": {
"name": "team",
"kind": {
"Enum": [
"blue",
"red",
"other"
]
}
}
},
"Int8",
"Int8"
]
},
"nullable": []
}
},
"982bc615a035019855317b3b47a3ac10159d81318db323c2d076c9b4c04a4e02": {
"query": "INSERT INTO events_drop(round_id, time, team, steam_id)VALUES($1, $2, $3, $4)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4",
"Int4",
{
"Custom": {
"name": "team",
"kind": {
"Enum": [
"blue",
"red",
"other"
]
}
}
},
"Int8"
]
},
"nullable": []
}
},
"c9f31bcb2cb8b76f7cd2e66284b70f79e462ac70f94cdab022bdce63929731b1": {
"query": "UPDATE logs SET version = $1 WHERE id = $2",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int2",
"Int4"
]
},
"nullable": []
}
},
"d4d72675d0a0792d14472c6bfc00454791dea1eae933818d168171f818bb7dc9": {
"query": "INSERT INTO class_stats(player_id, type, time, kills, deaths, assists, dmg)VALUES($1, $2, $3, $4, $5, $6, $7)RETURNING id",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int8"
}
],
"parameters": {
"Left": [
"Int8",
{
"Custom": {
"name": "class_type",
"kind": {
"Enum": [
"scout",
"soldier",
"pyro",
"demoman",
"heavyweapons",
"engineer",
"medic",
"sniper",
"spy",
"unknown"
]
}
}
},
"Int4",
"Int4",
"Int4",
"Int4",
"Int4"
]
},
"nullable": [
false
]
}
},
"eab40a01c0df317cdfb97eb4f88884f6776897ec2c2ecb8cae05748c8d087711": {
"query": "INSERT INTO rounds(\n round, log_id, length, winner, first_cap, red_score, blue_score,\n red_kills, blue_kills, red_dmg, blue_dmg, red_ubers, blue_ubers\n )\n VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)\n RETURNING id",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int4"
}
],
"parameters": {
"Left": [
"Int4",
"Int4",
"Int4",
{
"Custom": {
"name": "team",
"kind": {
"Enum": [
"blue",
"red",
"other"
]
}
}
},
{
"Custom": {
"name": "team",
"kind": {
"Enum": [
"blue",
"red",
"other"
]
}
}
},
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4",
"Int4"
]
},
"nullable": [
false
]
}
},
"f4daaeeaaf227491627c0bb54319a5f356028a591fdac2f41ba2dce1c5053d4a": {
"query": "SELECT MAX(id) as id from logs",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Int4"
}
],
"parameters": {
"Left": []
},
"nullable": [
null
]
}
},
"f8be06a1f3b2b9755faf3ca32921528528240308ed036cd6cf320ca4d31438b9": {
"query": "INSERT INTO events_point_cap(round_id, time, team, point)VALUES($1, $2, $3, $4)",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int4",
"Int4",
{
"Custom": {
"name": "team",
"kind": {
"Enum": [
"blue",
"red",
"other"
]
}
}
},
"Int4"
]
},
"nullable": []
}
}
}

View file

@ -1,21 +1,16 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, sqlx::Type, Deserialize, Serialize, Eq, PartialEq)] #[derive(Debug, Clone, Copy, sqlx::Type, Deserialize, Serialize, Eq, PartialEq, Default)]
#[sqlx(type_name = "team")] #[sqlx(type_name = "team")]
#[sqlx(rename_all = "lowercase")] #[sqlx(rename_all = "lowercase")]
pub enum TeamId { pub enum TeamId {
Blue, Blue,
Red, Red,
#[serde(other)] #[serde(other)]
#[default]
Other, Other,
} }
impl Default for TeamId {
fn default() -> Self {
TeamId::Other
}
}
#[derive(Debug, Clone, Copy, sqlx::Type, Deserialize, Serialize, Eq, PartialEq)] #[derive(Debug, Clone, Copy, sqlx::Type, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")] #[serde(rename_all = "lowercase")]
#[sqlx(rename_all = "lowercase")] #[sqlx(rename_all = "lowercase")]
@ -61,7 +56,7 @@ pub enum EventType {
Other, Other,
} }
#[derive(Debug, Clone, Copy, sqlx::Type, Deserialize, Serialize, Hash, Eq, PartialEq)] #[derive(Debug, Clone, Copy, sqlx::Type, Deserialize, Serialize, Hash, Eq, PartialEq, Default)]
#[serde(rename_all = "lowercase")] #[serde(rename_all = "lowercase")]
#[sqlx(rename_all = "lowercase")] #[sqlx(rename_all = "lowercase")]
pub enum Medigun { pub enum Medigun {
@ -69,30 +64,20 @@ pub enum Medigun {
QuickFix, QuickFix,
Vaccinator, Vaccinator,
#[serde(other)] #[serde(other)]
#[default]
Medigun, Medigun,
} }
impl Default for Medigun { #[derive(Debug, Clone, Copy, sqlx::Type, Eq, PartialEq, Default)]
fn default() -> Self {
Medigun::Medigun
}
}
#[derive(Debug, Clone, Copy, sqlx::Type, Eq, PartialEq)]
#[sqlx(rename_all = "lowercase")] #[sqlx(rename_all = "lowercase")]
#[sqlx(type_name = "map_type")] #[sqlx(type_name = "map_type")]
pub enum MapType { pub enum MapType {
Stopwatch, Stopwatch,
Cp, Cp,
KOTH, Koth,
CTF, Ctf,
UltiDuo, UltiDuo,
BBall, BBall,
#[default]
Other, Other,
} }
impl Default for MapType {
fn default() -> Self {
MapType::Other
}
}

View file

@ -23,7 +23,7 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
log.info.date() as DateTime<Utc>, log.info.date() as DateTime<Utc>,
2 2
) )
.execute(&mut tx) .execute(&mut *tx)
.await?; .await?;
for (num, round) in log.rounds.iter().enumerate() { for (num, round) in log.rounds.iter().enumerate() {
@ -48,14 +48,17 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
round.team.red.charges as i32, round.team.red.charges as i32,
round.team.blue.charges as i32, round.team.blue.charges as i32,
) )
.fetch_one(&mut tx) .fetch_one(&mut *tx)
.await? .await?
.id; .id;
for event in &round.events { for event in &round.events {
match event { match event {
Event::PointCap { time, team, point } => { Event::PointCap {
if let Some(team) = team { time,
team: Some(team),
point,
} => {
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)",
@ -64,30 +67,29 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
*team as TeamId, *team as TeamId,
*point as i32, *point as i32,
) )
.execute(&mut tx) .execute(&mut *tx)
.await?; .await?;
} }
} Event::RoundWin {
Event::RoundWin { time, team } => { time,
if let Some(team) = team { team: Some(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)",
round_id, round_id,
*time as i32, *time as i32,
team.unwrap_or_default() as TeamId, *team as TeamId,
) )
.execute(&mut tx) .execute(&mut *tx)
.await?; .await?;
} }
}
Event::MedicDeath { Event::MedicDeath {
time, time,
team, team: Some(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)",
@ -97,16 +99,14 @@ 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: Some(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)",
@ -115,17 +115,15 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
*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,
time, time,
steamid, steamid,
team, team: Some(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)",
@ -135,10 +133,9 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
*medigun as Medigun, *medigun as Medigun,
u64::from(*steamid) as i64, u64::from(*steamid) as i64,
) )
.execute(&mut tx) .execute(&mut *tx)
.await?; .await?;
} }
}
_ => {} _ => {}
} }
} }
@ -234,7 +231,7 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
deaths.sniper as i32, deaths.sniper as i32,
deaths.spy as i32, deaths.spy as i32,
) )
.fetch_one(&mut tx) .fetch_one(&mut *tx)
.await? .await?
.id; .id;
@ -252,7 +249,7 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
class.assists as i32, class.assists as i32,
class.dmg as i32, class.dmg as i32,
) )
.fetch_one(&mut tx) .fetch_one(&mut *tx)
.await? .await?
.id; .id;
@ -267,7 +264,7 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
stats.hits as i32, stats.hits as i32,
stats.dmg as i32, stats.dmg as i32,
) )
.execute(&mut tx) .execute(&mut *tx)
.await?; .await?;
} }
} }
@ -284,7 +281,7 @@ pub async fn store_log(pool: &PgPool, id: i32, log: &NormalizedLog) -> Result<()
kill_streak.time, kill_streak.time,
kill_streak.streak, kill_streak.streak,
) )
.execute(&mut tx) .execute(&mut *tx)
.await?; .await?;
} }
@ -313,13 +310,13 @@ pub async fn upgrade(
kill_streak.time, kill_streak.time,
kill_streak.streak, kill_streak.streak,
) )
.execute(&mut tx) .execute(&mut *tx)
.await?; .await?;
} }
} }
sqlx::query!("UPDATE logs SET version = $1 WHERE id = $2", to, id) sqlx::query!("UPDATE logs SET version = $1 WHERE id = $2", to, id)
.execute(&mut tx) .execute(&mut *tx)
.await?; .await?;
tx.commit().await?; tx.commit().await?;

View file

@ -136,7 +136,7 @@ fn is_valid(value: &serde_json::Value) -> bool {
if value.get("success").is_none() { if value.get("success").is_none() {
return false; return false;
} }
if value.get("success").unwrap().as_bool().unwrap_or_default() == false { if !value.get("success").unwrap().as_bool().unwrap_or_default() {
return false; return false;
} }

View file

@ -6,6 +6,7 @@ pub use crate::raw::{
}; };
use chrono::{DateTime, NaiveDateTime, Utc}; use chrono::{DateTime, NaiveDateTime, Utc};
use serde::Deserialize; use serde::Deserialize;
use std::cmp::Ordering;
use std::collections::HashMap; use std::collections::HashMap;
use steamid_ng::SteamID; use steamid_ng::SteamID;
@ -75,9 +76,9 @@ impl Info {
} else if self.map.starts_with("cp") { } else if self.map.starts_with("cp") {
MapType::Cp MapType::Cp
} else if self.map.starts_with("koth") { } else if self.map.starts_with("koth") {
MapType::KOTH MapType::Koth
} else if self.map.starts_with("ctf") { } else if self.map.starts_with("ctf") {
MapType::CTF MapType::Ctf
} else if self.map.starts_with("ultiduo") { } else if self.map.starts_with("ultiduo") {
MapType::UltiDuo MapType::UltiDuo
} else if self.map.starts_with("bball") { } else if self.map.starts_with("bball") {
@ -88,7 +89,9 @@ impl Info {
} }
pub fn date(&self) -> DateTime<Utc> { pub fn date(&self) -> DateTime<Utc> {
DateTime::from_utc(NaiveDateTime::from_timestamp(self.date as i64, 0), Utc) NaiveDateTime::from_timestamp_opt(self.date as i64, 0)
.unwrap()
.and_utc()
} }
} }
@ -133,7 +136,7 @@ impl From<RawLog> for NormalizedLog {
.or(raw.info.rounds) .or(raw.info.rounds)
.unwrap_or_default() .unwrap_or_default()
.into_iter() .into_iter()
.map(|raw| Round::from(raw)) .map(Round::from)
.collect(); .collect();
let teams = raw.teams.or(raw.info.teams).unwrap_or_default(); let teams = raw.teams.or(raw.info.teams).unwrap_or_default();
@ -188,33 +191,18 @@ impl From<crate::raw::Round> for Round {
} }
pub fn map_is_stopwatch(map: &str) -> bool { pub fn map_is_stopwatch(map: &str) -> bool {
if map.starts_with("pl_") { map.starts_with("pl_")
true || map.starts_with("cp_steel")
} else if map.starts_with("cp_steel") { || map.starts_with("cp_gravelpit")
true || map.starts_with("cp_dustbowl")
} else if map.starts_with("cp_gravelpit") { || map.starts_with("cp_egypt")
true || map.starts_with("cp_degrootkeep")
} else if map.starts_with("cp_dustbowl") { || map.starts_with("cp_gorge")
true || map.starts_with("cp_junction")
} else if map.starts_with("cp_egypt") { || map.starts_with("cp_mossrock")
true || map.starts_with("cp_manor")
} else if map.starts_with("cp_degrootkeep") { || map.starts_with("cp_snowplow")
true || map.starts_with("cp_alloy")
} else if map.starts_with("cp_gorge") {
true
} else if map.starts_with("cp_junction") {
true
} else if map.starts_with("cp_mossrock") {
true
} else if map.starts_with("cp_manor") {
true
} else if map.starts_with("cp_snowplow") {
true
} else if map.starts_with("cp_alloy") {
true
} else {
false
}
} }
/// Add missing round wins for 2nd round blue win /// Add missing round wins for 2nd round blue win
@ -273,7 +261,7 @@ fn get_first_event_time(round: &Round) -> u32 {
round round
.events .events
.iter() .iter()
.filter_map(|event| Some(event.time())) .map(|event| event.time())
.last() .last()
.unwrap_or_default() .unwrap_or_default()
} }
@ -327,13 +315,16 @@ fn normalize_stopwatch_score(log: &mut NormalizedLog) {
let second_half_capped = get_round_point_capped(&log.rounds[1]); let second_half_capped = get_round_point_capped(&log.rounds[1]);
// "blue" is the team that attacked first // "blue" is the team that attacked first
if first_half_capped > second_half_capped { match first_half_capped.cmp(&second_half_capped) {
Ordering::Greater => {
log.teams.blue.score = 1; log.teams.blue.score = 1;
log.teams.red.score = 0; log.teams.red.score = 0;
} else if second_half_capped > first_half_capped { }
Ordering::Less => {
log.teams.blue.score = 0; log.teams.blue.score = 0;
log.teams.red.score = 1; log.teams.red.score = 1;
} else { }
Ordering::Equal => {
let first_half_cap_time = get_last_cap_time(&log.rounds[0]); let first_half_cap_time = get_last_cap_time(&log.rounds[0]);
let second_half_cap_time = get_last_cap_time(&log.rounds[1]) let second_half_cap_time = get_last_cap_time(&log.rounds[1])
.saturating_sub(get_round_end_time(&log.rounds[0])); .saturating_sub(get_round_end_time(&log.rounds[0]));
@ -348,6 +339,7 @@ fn normalize_stopwatch_score(log: &mut NormalizedLog) {
} }
} }
} }
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View file

@ -268,7 +268,7 @@ pub enum Event {
}, },
RoundWin { RoundWin {
time: u32, time: u32,
team: Option<Option<TeamId>>, team: Option<TeamId>,
}, },
Drop { Drop {
time: u32, time: u32,

View file

@ -1167,7 +1167,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 754, time: 754,
team: Some(Some(Red)), team: Some(Red),
), ),
], ],
"firstcap": None, "firstcap": None,
@ -1286,7 +1286,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 168, time: 168,
team: Some(Some(Blue)), team: Some(Blue),
), ),
], ],
"firstcap": None, "firstcap": None,
@ -1415,7 +1415,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 173, time: 173,
team: Some(Some(Red)), team: Some(Red),
), ),
], ],
"firstcap": None, "firstcap": None,
@ -1554,7 +1554,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 127, time: 127,
team: Some(Some(Blue)), team: Some(Blue),
), ),
], ],
"firstcap": None, "firstcap": None,
@ -1676,7 +1676,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 108, time: 108,
team: Some(Some(Blue)), team: Some(Blue),
), ),
], ],
"firstcap": None, "firstcap": None,
@ -1884,7 +1884,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 520, time: 520,
team: Some(Some(Blue)), team: Some(Blue),
), ),
], ],
"firstcap": None, "firstcap": None,
@ -2068,7 +2068,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 235, time: 235,
team: Some(Some(Red)), team: Some(Red),
), ),
], ],
"firstcap": None, "firstcap": None,
@ -2174,7 +2174,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 88, time: 88,
team: Some(Some(Blue)), team: Some(Blue),
), ),
], ],
"firstcap": None, "firstcap": None,

View file

@ -1167,7 +1167,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 778, time: 778,
team: Some(Some(Blue)), team: Some(Blue),
), ),
], ],
"firstcap": Some(Blue), "firstcap": Some(Blue),
@ -1384,7 +1384,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 1349, time: 1349,
team: Some(Some(Blue)), team: Some(Blue),
), ),
], ],
"firstcap": Some(Blue), "firstcap": Some(Blue),

View file

@ -1352,7 +1352,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 959, time: 959,
team: Some(Some(Blue)), team: Some(Blue),
), ),
], ],
"firstcap": Some(Blue), "firstcap": Some(Blue),
@ -1570,7 +1570,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 1299, time: 1299,
team: Some(Some(Blue)), team: Some(Blue),
), ),
], ],
"firstcap": Some(Blue), "firstcap": Some(Blue),

View file

@ -747,7 +747,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 116, time: 116,
team: Some(Some(Blue)), team: Some(Blue),
), ),
], ],
"firstcap": Some(Blue), "firstcap": Some(Blue),
@ -866,7 +866,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 267, time: 267,
team: Some(Some(Blue)), team: Some(Blue),
), ),
], ],
"firstcap": Some(Blue), "firstcap": Some(Blue),
@ -986,7 +986,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 366, time: 366,
team: Some(Some(Blue)), team: Some(Blue),
), ),
], ],
"firstcap": Some(Blue), "firstcap": Some(Blue),
@ -1166,7 +1166,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 645, time: 645,
team: Some(Some(Red)), team: Some(Red),
), ),
], ],
"firstcap": Some(Blue), "firstcap": Some(Blue),
@ -1279,7 +1279,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 779, time: 779,
team: Some(Some(Blue)), team: Some(Blue),
), ),
], ],
"firstcap": Some(Blue), "firstcap": Some(Blue),
@ -1411,7 +1411,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 1003, time: 1003,
team: Some(Some(Blue)), team: Some(Blue),
), ),
], ],
"firstcap": Some(Blue), "firstcap": Some(Blue),

View file

@ -1304,7 +1304,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 645, time: 645,
team: Some(Some(Blue)), team: Some(Blue),
), ),
], ],
"firstcap": Some(Blue), "firstcap": Some(Blue),
@ -1565,7 +1565,7 @@ RawLog(
Event( Event(
type: "round_win", type: "round_win",
time: 1296, time: 1296,
team: Some(Some(Red)), team: Some(Red),
), ),
], ],
"firstcap": Some(Blue), "firstcap": Some(Blue),