Skip to content

Commit

Permalink
added kills and deaths columns
Browse files Browse the repository at this point in the history
  • Loading branch information
scottadkin committed Feb 9, 2025
1 parent 71dc059 commit 7884f6b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions install.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ const queries = [
map_id int NOT NULL,
player_id int NOT NULL,
weapon_id int NOT NULL,
kills int NOT NULL,
deaths int NOT NULL,
shots int NOT NULL,
hits int NOT NULL,
accuracy float NOT NULL,
Expand Down
19 changes: 16 additions & 3 deletions src/app/lib/classicWeaponStats.mjs
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import { bulkInsert } from "./database.mjs";

export async function bulkInsertMatchStats(matchId, mapId, gametypeId, playerManager){
export async function bulkInsertMatchStats(matchId, mapId, gametypeId, playerManager, weaponsManager){

const insertVars = [];

for(const player of Object.values(playerManager.mergedPlayers)){

for(const [weaponId, s] of Object.entries(player.classicWeaponStats)){

const altStats = weaponsManager.getPlayerWeaponStats(player.masterId, weaponId);

let kills = 0;
let deaths = 0;

if(altStats.kills !== undefined){
kills = altStats.kills;
}

if(altStats.deaths !== undefined){
deaths = altStats.deaths;
}

insertVars.push([
matchId, gametypeId, mapId, player.masterId, weaponId, s.shots, s.hits, s.accuracy, s.damage
matchId, gametypeId, mapId, player.masterId, weaponId, kills, deaths, s.shots, s.hits, s.accuracy, s.damage
]);
}
}

const query = `INSERT INTO nstats_classic_weapon_match_stats (match_id,gametype_id,map_id,player_id,weapon_id,shots,hits,accuracy,damage) VALUES ?`;
const query = `INSERT INTO nstats_classic_weapon_match_stats (match_id,gametype_id,map_id,player_id,weapon_id,kills,deaths,shots,hits,accuracy,damage) VALUES ?`;

await bulkInsert(query, insertVars);
}
6 changes: 4 additions & 2 deletions src/app/lib/importer/classicWeaponStats.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default class ClassicWeaponStats{

const pStats = player.classicWeaponStats;


if(pStats[weaponId] === undefined){

pStats[weaponId] = {
Expand All @@ -81,10 +82,11 @@ export default class ClassicWeaponStats{
}


async insertMatchStats(matchId, mapId, gametypeId, playerManager){
async insertMatchStats(matchId, mapId, gametypeId, playerManager, weaponsManager){



await bulkInsertMatchStats(matchId, mapId, gametypeId, playerManager);
await bulkInsertMatchStats(matchId, mapId, gametypeId, playerManager, weaponsManager);

}
}
2 changes: 1 addition & 1 deletion src/app/lib/matchParser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export class MatchParser{
await this.players.updateMapAverages(this.gametype.id, this.map.id);
await this.weapons.updateMapTotals(this.map.id);

await this.classicWeaponStats.insertMatchStats(this.matchId, this.map.id, this.gametype.id, this.players)
await this.classicWeaponStats.insertMatchStats(this.matchId, this.map.id, this.gametype.id, this.players, this.weapons);



Expand Down

0 comments on commit 7884f6b

Please sign in to comment.