add death while equipped for weapon route
This commit is contained in:
@@ -48,6 +48,7 @@ router.get(
|
|||||||
total_distance: number
|
total_distance: number
|
||||||
username?: string
|
username?: string
|
||||||
host?: number
|
host?: number
|
||||||
|
deaths_while_equipped?: number
|
||||||
}
|
}
|
||||||
} = {}
|
} = {}
|
||||||
let index: 'cause_of_death' | 'attacker_id' | 'map' | 'servername' | 'game_mode'
|
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 === 'attacker_id') data[requestIndex].username = e.attacker_name
|
||||||
if (index === 'servername') data[requestIndex].host = e.host
|
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].deaths += Number(e.deaths)
|
||||||
data[requestIndex].kills += Number(e.kills)
|
data[requestIndex].kills += Number(e.kills)
|
||||||
data[requestIndex].total_distance += Number(e.total_distance)
|
data[requestIndex].total_distance += Number(e.total_distance)
|
||||||
|
|||||||
+31
-1
@@ -33,12 +33,22 @@ export default async function listenKills() {
|
|||||||
e.map == payload.map &&
|
e.map == payload.map &&
|
||||||
e.servername == payload.servername
|
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) {
|
if (!killEntry) {
|
||||||
killEntry = {
|
killEntry = {
|
||||||
kills: 0,
|
kills: 0,
|
||||||
deaths: 0,
|
deaths: 0,
|
||||||
max_distance: 0,
|
max_distance: 0,
|
||||||
total_distance: 0,
|
total_distance: 0,
|
||||||
|
deaths_with_weapon: 0,
|
||||||
attacker_name: payload.attacker_name,
|
attacker_name: payload.attacker_name,
|
||||||
attacker_id: payload.attacker_id,
|
attacker_id: payload.attacker_id,
|
||||||
cause_of_death: payload.cause_of_death,
|
cause_of_death: payload.cause_of_death,
|
||||||
@@ -56,9 +66,10 @@ export default async function listenKills() {
|
|||||||
deaths: 0,
|
deaths: 0,
|
||||||
max_distance: 0,
|
max_distance: 0,
|
||||||
total_distance: 0,
|
total_distance: 0,
|
||||||
|
deaths_with_weapon: 0,
|
||||||
attacker_name: payload.victim_name,
|
attacker_name: payload.victim_name,
|
||||||
attacker_id: payload.victim_id,
|
attacker_id: payload.victim_id,
|
||||||
cause_of_death: payload.victim_current_weapon,
|
cause_of_death: payload.cause_of_death,
|
||||||
game_mode: payload.game_mode,
|
game_mode: payload.game_mode,
|
||||||
host: payload.host,
|
host: payload.host,
|
||||||
map: payload.map,
|
map: payload.map,
|
||||||
@@ -67,10 +78,29 @@ export default async function listenKills() {
|
|||||||
allData.push(deathEntry)
|
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.kills++
|
||||||
killEntry.total_distance += payload.distance
|
killEntry.total_distance += payload.distance
|
||||||
killEntry.max_distance = Math.max(killEntry.max_distance || 0, payload.distance)
|
killEntry.max_distance = Math.max(killEntry.max_distance || 0, payload.distance)
|
||||||
deathEntry.deaths++
|
deathEntry.deaths++
|
||||||
|
deathWithWeaponEntry.deaths++
|
||||||
})
|
})
|
||||||
return pgClient
|
return pgClient
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,6 +77,27 @@ async function processGlobalStats() {
|
|||||||
'host',
|
'host',
|
||||||
'game_mode'
|
'game_mode'
|
||||||
])
|
])
|
||||||
|
).with('deathswithweapon', (db) =>
|
||||||
|
db
|
||||||
|
.selectFrom('kill')
|
||||||
|
.select([
|
||||||
|
count<number>('id').as('deaths'),
|
||||||
|
'victim_id',
|
||||||
|
sql<string>`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')
|
.selectFrom('kills')
|
||||||
.fullJoin('deaths', (join) =>
|
.fullJoin('deaths', (join) =>
|
||||||
@@ -88,12 +109,22 @@ async function processGlobalStats() {
|
|||||||
.onRef('deaths.game_mode', '=', 'kills.game_mode')
|
.onRef('deaths.game_mode', '=', 'kills.game_mode')
|
||||||
.onRef('deaths.map', '=', 'kills.map')
|
.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')
|
//.selectAll('kills')
|
||||||
.select([
|
.select([
|
||||||
sql<string>`COALESCE(kills.attacker_name, deaths.victim_name)`.as('attacker_name'),
|
sql<string>`COALESCE(kills.attacker_name, deaths.victim_name)`.as('attacker_name'),
|
||||||
sql<string>`COALESCE(kills.attacker_id, deaths.victim_id)`.as('attacker_id'),
|
sql<string>`COALESCE(kills.attacker_id, deaths.victim_id)`.as('attacker_id'),
|
||||||
sql<number>`COALESCE(kills.kills, 0)`.as('kills'),
|
sql<number>`COALESCE(kills.kills, 0)`.as('kills'),
|
||||||
sql<number>`COALESCE(kills.total_distance, 0)`.as('total_distance'),
|
sql<number>`COALESCE(kills.total_distance, 0)`.as('total_distance'),
|
||||||
|
sql<number>`COALESCE(deathswithweapon.deaths, 0)`.as('deaths_with_weapon'),
|
||||||
sql<number>`COALESCE(kills.max_distance, 0)`.as('max_distance'),
|
sql<number>`COALESCE(kills.max_distance, 0)`.as('max_distance'),
|
||||||
sql<number>`COALESCE(deaths.deaths, 0)`.as('deaths'),
|
sql<number>`COALESCE(deaths.deaths, 0)`.as('deaths'),
|
||||||
sql<string>`COALESCE(kills.servername, deaths.servername)`.as('servername'),
|
sql<string>`COALESCE(kills.servername, deaths.servername)`.as('servername'),
|
||||||
|
|||||||
Reference in New Issue
Block a user