From 3595249b6036f25ba5ce1af5b36f1788aae2dfe1 Mon Sep 17 00:00:00 2001 From: legonzaur Date: Thu, 20 Apr 2023 20:00:22 +0200 Subject: [PATCH] add death while equipped for weapon route --- src/client/client.ts | 2 ++ src/process/onKill.ts | 32 +++++++++++++++++++++++++++++++- src/process/process.ts | 31 +++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/client/client.ts b/src/client/client.ts index 0c8cdab..7af8423 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -48,6 +48,7 @@ router.get( total_distance: number username?: string host?: number + deaths_while_equipped?: number } } = {} let index: 'cause_of_death' | 'attacker_id' | 'map' | 'servername' | 'game_mode' @@ -85,6 +86,7 @@ router.get( } if (index === 'attacker_id') data[requestIndex].username = e.attacker_name if (index === 'servername') data[requestIndex].host = e.host + if (index === 'cause_of_death') data[requestIndex].deaths_while_equipped = Number(e.deaths_with_weapon) data[requestIndex].deaths += Number(e.deaths) data[requestIndex].kills += Number(e.kills) data[requestIndex].total_distance += Number(e.total_distance) diff --git a/src/process/onKill.ts b/src/process/onKill.ts index df9944d..3d514c6 100644 --- a/src/process/onKill.ts +++ b/src/process/onKill.ts @@ -33,12 +33,22 @@ export default async function listenKills() { e.map == payload.map && e.servername == payload.servername ) + let deathWithWeaponEntry = allData.find( + (e) => + e.attacker_id == payload.victim_id && + e.cause_of_death == payload.victim_current_weapon && + e.game_mode == payload.game_mode && + e.host == payload.host && + e.map == payload.map && + e.servername == payload.servername + ) if (!killEntry) { killEntry = { kills: 0, deaths: 0, max_distance: 0, total_distance: 0, + deaths_with_weapon: 0, attacker_name: payload.attacker_name, attacker_id: payload.attacker_id, cause_of_death: payload.cause_of_death, @@ -56,9 +66,10 @@ export default async function listenKills() { deaths: 0, max_distance: 0, total_distance: 0, + deaths_with_weapon: 0, attacker_name: payload.victim_name, attacker_id: payload.victim_id, - cause_of_death: payload.victim_current_weapon, + cause_of_death: payload.cause_of_death, game_mode: payload.game_mode, host: payload.host, map: payload.map, @@ -67,10 +78,29 @@ export default async function listenKills() { allData.push(deathEntry) } + if (!deathWithWeaponEntry) { + deathWithWeaponEntry = { + kills: 0, + deaths: 0, + max_distance: 0, + total_distance: 0, + deaths_with_weapon: 0, + attacker_name: payload.victim_name, + attacker_id: payload.victim_id, + cause_of_death: payload.victim_current_weapon, + game_mode: payload.game_mode, + host: payload.host, + map: payload.map, + servername: payload.servername + } + allData.push(deathWithWeaponEntry) + } + killEntry.kills++ killEntry.total_distance += payload.distance killEntry.max_distance = Math.max(killEntry.max_distance || 0, payload.distance) deathEntry.deaths++ + deathWithWeaponEntry.deaths++ }) return pgClient } diff --git a/src/process/process.ts b/src/process/process.ts index e9ed7c7..33334ae 100644 --- a/src/process/process.ts +++ b/src/process/process.ts @@ -77,6 +77,27 @@ async function processGlobalStats() { 'host', 'game_mode' ]) + ).with('deathswithweapon', (db) => + db + .selectFrom('kill') + .select([ + count('id').as('deaths'), + 'victim_id', + sql`last(victim_name)`.as('victim_name'), + 'victim_current_weapon', + 'map', + 'game_mode', + 'servername', + 'host' + ]) + .groupBy([ + 'victim_id', + 'victim_current_weapon', + 'map', + 'servername', + 'host', + 'game_mode' + ]) ) .selectFrom('kills') .fullJoin('deaths', (join) => @@ -88,12 +109,22 @@ async function processGlobalStats() { .onRef('deaths.game_mode', '=', 'kills.game_mode') .onRef('deaths.map', '=', 'kills.map') ) + .fullJoin('deathswithweapon', (join) => + join + .onRef('deathswithweapon.victim_id', '=', 'kills.attacker_id') + .onRef('deathswithweapon.victim_current_weapon', '=', 'kills.cause_of_death') + .onRef('deathswithweapon.servername', '=', 'kills.servername') + .onRef('deathswithweapon.host', '=', 'kills.host') + .onRef('deathswithweapon.game_mode', '=', 'kills.game_mode') + .onRef('deathswithweapon.map', '=', 'kills.map') + ) //.selectAll('kills') .select([ sql`COALESCE(kills.attacker_name, deaths.victim_name)`.as('attacker_name'), sql`COALESCE(kills.attacker_id, deaths.victim_id)`.as('attacker_id'), sql`COALESCE(kills.kills, 0)`.as('kills'), sql`COALESCE(kills.total_distance, 0)`.as('total_distance'), + sql`COALESCE(deathswithweapon.deaths, 0)`.as('deaths_with_weapon'), sql`COALESCE(kills.max_distance, 0)`.as('max_distance'), sql`COALESCE(deaths.deaths, 0)`.as('deaths'), sql`COALESCE(kills.servername, deaths.servername)`.as('servername'),