mirror of
https://github.com/amineo/t2-stat-parser.git
synced 2026-01-19 17:34:43 +00:00
Use new teamScoreGame key to display team v team score. Fall back to old tally method if its not available
This commit is contained in:
parent
c1fcb61731
commit
a14fec7355
|
|
@ -4,6 +4,7 @@
|
||||||
function formatPlayerStats(statObj: any) {
|
function formatPlayerStats(statObj: any) {
|
||||||
return {
|
return {
|
||||||
...statObj.stats,
|
...statObj.stats,
|
||||||
|
teamScoreGame: Number(statObj.stats.teamScoreGame),
|
||||||
masTG: Number(statObj.stats.masTG),
|
masTG: Number(statObj.stats.masTG),
|
||||||
cgMATG: Number(statObj.stats.cgMATG),
|
cgMATG: Number(statObj.stats.cgMATG),
|
||||||
kdrAvg: Number(statObj.stats.kdrAvg),
|
kdrAvg: Number(statObj.stats.kdrAvg),
|
||||||
|
|
|
||||||
|
|
@ -10,150 +10,179 @@ import formatPlayerStats from '../common/util/formatStats';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GameService {
|
export class GameService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly connection: Connection,
|
private readonly connection: Connection,
|
||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
@InjectRepository(Games) private readonly gamesRepository: Repository<Games>,
|
@InjectRepository(Games)
|
||||||
@InjectRepository(GameDetail) private readonly gameRepository: Repository<GameDetail>
|
private readonly gamesRepository: Repository<Games>,
|
||||||
) {}
|
@InjectRepository(GameDetail)
|
||||||
|
private readonly gameRepository: Repository<GameDetail>,
|
||||||
|
) {}
|
||||||
|
|
||||||
async findOne(gameId: string) {
|
async findOne(gameId: string) {
|
||||||
const query = await this.gameRepository.find({
|
const query = await this.gameRepository.find({
|
||||||
relations: [ 'game', 'playerGuid' ],
|
relations: ['game', 'playerGuid'],
|
||||||
where: [ { game: { gameId: gameId } } ]
|
where: [{ game: { gameId: gameId } }],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!query.length) {
|
if (!query.length) {
|
||||||
throw new NotFoundException(`Game ID: ${gameId} not found`);
|
throw new NotFoundException(`Game ID: ${gameId} not found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const game: any = {
|
const game: any = {
|
||||||
...query[0].game
|
...query[0].game,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Need to set return based off gameType
|
// Need to set return based off gameType
|
||||||
// Modify game object if not a CTF type game and return early
|
// Modify game object if not a CTF type game and return early
|
||||||
if (query[0].gametype !== 'CTFGame' && query[0].gametype !== 'SCtFGame') {
|
if (query[0].gametype !== 'CTFGame' && query[0].gametype !== 'SCtFGame') {
|
||||||
game['players'] = [];
|
game['players'] = [];
|
||||||
for (const player of query) {
|
for (const player of query) {
|
||||||
const { playerName } = player;
|
const { playerName } = player;
|
||||||
const stats = formatPlayerStats(player);
|
const stats = formatPlayerStats(player);
|
||||||
|
|
||||||
const p = {
|
const p = {
|
||||||
playerGuid: player.playerGuid.playerGuid,
|
playerGuid: player.playerGuid.playerGuid,
|
||||||
playerName,
|
playerName,
|
||||||
stats
|
stats,
|
||||||
};
|
};
|
||||||
|
|
||||||
game.players.push(p);
|
game.players.push(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Team Based game stats (CTF/SCtF)
|
// Team Based game stats (CTF/SCtF)
|
||||||
game['teams'] = {
|
game['teams'] = {
|
||||||
obs: { score: 0, players: [] },
|
obs: { score: 0, players: [] },
|
||||||
storm: { score: 0, players: [] },
|
storm: { score: 0, players: [] },
|
||||||
inferno: { score: 0, players: [] }
|
inferno: { score: 0, players: [] },
|
||||||
};
|
};
|
||||||
|
|
||||||
const teamZero = [],
|
const teamZero = [],
|
||||||
teamOne = [],
|
teamOne = [],
|
||||||
teamTwo = [];
|
teamTwo = [];
|
||||||
|
|
||||||
for (const player of query) {
|
for (const player of query) {
|
||||||
const { playerName } = player;
|
const { playerName } = player;
|
||||||
const stats = formatPlayerStats(player);
|
const stats = formatPlayerStats(player);
|
||||||
|
|
||||||
const p = {
|
const p = {
|
||||||
playerGuid: player.playerGuid.playerGuid,
|
playerGuid: player.playerGuid.playerGuid,
|
||||||
playerName,
|
playerName,
|
||||||
stats
|
stats,
|
||||||
};
|
};
|
||||||
|
|
||||||
const flagGrabsTG = parseInt(player.stats.flagGrabsTG[0]);
|
if (isNaN(player.stats.teamScoreGame)) {
|
||||||
const flagCapsTG = parseInt(player.stats.flagCapsTG[0]) * 100;
|
// legacy calculations for game totals (not using the new teamScoreGame attribute)
|
||||||
const totalFlagScore = flagGrabsTG + flagCapsTG;
|
const flagGrabsTG = parseInt(player.stats.flagGrabsTG[0]);
|
||||||
|
const flagCapsTG = parseInt(player.stats.flagCapsTG[0]) * 100;
|
||||||
|
const totalFlagScore = flagGrabsTG + flagCapsTG;
|
||||||
|
|
||||||
if (player.stats.dtTeamGame[0] === '1') {
|
if (player.stats.dtTeamGame[0] === '1') {
|
||||||
// Storm
|
// Storm
|
||||||
game.teams.storm.score += totalFlagScore;
|
game.teams.storm.score += totalFlagScore;
|
||||||
teamOne.push(p);
|
teamOne.push(p);
|
||||||
} else if (player.stats.dtTeamGame[0] === '2') {
|
} else if (player.stats.dtTeamGame[0] === '2') {
|
||||||
// Inferno
|
// Inferno
|
||||||
game.teams.inferno.score += totalFlagScore;
|
game.teams.inferno.score += totalFlagScore;
|
||||||
teamTwo.push(p);
|
teamTwo.push(p);
|
||||||
} else {
|
} else {
|
||||||
// OBS
|
// OBS
|
||||||
game.teams.obs.score += totalFlagScore;
|
game.teams.obs.score += totalFlagScore;
|
||||||
teamZero.push(p);
|
teamZero.push(p);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
// Use new player.stats.teamScoreGame key
|
||||||
|
if (player.stats.dtTeamGame[0] === '1') {
|
||||||
|
// Storm
|
||||||
|
game.teams.storm.score = Number(player.stats.teamScoreGame);
|
||||||
|
teamOne.push(p);
|
||||||
|
} else if (player.stats.dtTeamGame[0] === '2') {
|
||||||
|
// Inferno
|
||||||
|
game.teams.inferno.score = Number(player.stats.teamScoreGame);
|
||||||
|
teamTwo.push(p);
|
||||||
|
} else {
|
||||||
|
// OBS
|
||||||
|
game.teams.obs.score = Number(player.stats.teamScoreGame);
|
||||||
|
teamZero.push(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
game['teams']['obs']['players'] = teamZero.sort((a, b) => b.stats.scoreTG - a.stats.scoreTG);
|
game['teams']['obs']['players'] = teamZero.sort(
|
||||||
game['teams']['storm']['players'] = teamOne.sort((a, b) => b.stats.scoreTG - a.stats.scoreTG);
|
(a, b) => b.stats.scoreTG - a.stats.scoreTG,
|
||||||
game['teams']['inferno']['players'] = teamTwo.sort((a, b) => b.stats.scoreTG - a.stats.scoreTG);
|
);
|
||||||
|
game['teams']['storm']['players'] = teamOne.sort(
|
||||||
|
(a, b) => b.stats.scoreTG - a.stats.scoreTG,
|
||||||
|
);
|
||||||
|
game['teams']['inferno']['players'] = teamTwo.sort(
|
||||||
|
(a, b) => b.stats.scoreTG - a.stats.scoreTG,
|
||||||
|
);
|
||||||
|
|
||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOneAbvSummary(gameId: string) {
|
async findOneAbvSummary(gameId: string) {
|
||||||
const query = await this.gameRepository.find({
|
const query = await this.gameRepository.find({
|
||||||
relations: [ 'game', 'playerGuid' ],
|
relations: ['game', 'playerGuid'],
|
||||||
where: [ { game: { gameId: gameId } } ]
|
where: [{ game: { gameId: gameId } }],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!query.length) {
|
if (!query.length) {
|
||||||
throw new NotFoundException(`Game ID: ${gameId} not found`);
|
throw new NotFoundException(`Game ID: ${gameId} not found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const game: any = {
|
const game: any = {
|
||||||
...query[0].game
|
...query[0].game,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Need to set return based off gameType
|
// Need to set return based off gameType
|
||||||
// Modify game object if not a CTF type game and return early
|
// Modify game object if not a CTF type game and return early
|
||||||
if (query[0].gametype !== 'CTFGame' && query[0].gametype !== 'SCtFGame') {
|
if (query[0].gametype !== 'CTFGame' && query[0].gametype !== 'SCtFGame') {
|
||||||
game['totalScore'] = 0;
|
game['totalScore'] = 0;
|
||||||
|
|
||||||
for (const player of query) {
|
for (const player of query) {
|
||||||
const stats = formatPlayerStats(player);
|
const stats = formatPlayerStats(player);
|
||||||
|
|
||||||
game.totalScore += stats.scoreTG;
|
game.totalScore += stats.scoreTG;
|
||||||
}
|
}
|
||||||
|
|
||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Team Based game stats (CTF/SCtF)
|
// Team Based game stats (CTF/SCtF)
|
||||||
game['teams'] = {
|
game['teams'] = {
|
||||||
obs: { score: 0, playerCount: 0 },
|
obs: { score: 0, playerCount: 0 },
|
||||||
storm: { score: 0, playerCount: 0 },
|
storm: { score: 0, playerCount: 0 },
|
||||||
inferno: { score: 0, playerCount: 0 }
|
inferno: { score: 0, playerCount: 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const player of query) {
|
console.log(query);
|
||||||
const flagGrabsTG = parseInt(player.stats.flagGrabsTG[0]);
|
|
||||||
const flagCapsTG = parseInt(player.stats.flagCapsTG[0]) * 100;
|
|
||||||
const totalFlagScore = flagGrabsTG + flagCapsTG;
|
|
||||||
|
|
||||||
if (player.stats.dtTeamGame[0] === '1') {
|
for (const player of query) {
|
||||||
// Storm
|
const flagGrabsTG = parseInt(player.stats.flagGrabsTG[0]);
|
||||||
game.teams.storm.score += totalFlagScore;
|
const flagCapsTG = parseInt(player.stats.flagCapsTG[0]) * 100;
|
||||||
game.teams.storm.playerCount += 1;
|
const totalFlagScore = flagGrabsTG + flagCapsTG;
|
||||||
} else if (player.stats.dtTeamGame[0] === '2') {
|
|
||||||
// Inferno
|
|
||||||
game.teams.inferno.score += totalFlagScore;
|
|
||||||
game.teams.inferno.playerCount += 1;
|
|
||||||
} else {
|
|
||||||
// OBS
|
|
||||||
game.teams.obs.score += totalFlagScore;
|
|
||||||
game.teams.obs.playerCount += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
game['totalScore'] = game.teams.storm.score + game.teams.inferno.score + game.teams.obs.score;
|
|
||||||
|
|
||||||
return game;
|
if (player.stats.dtTeamGame[0] === '1') {
|
||||||
}
|
// Storm
|
||||||
|
game.teams.storm.score += totalFlagScore;
|
||||||
|
game.teams.storm.playerCount += 1;
|
||||||
|
} else if (player.stats.dtTeamGame[0] === '2') {
|
||||||
|
// Inferno
|
||||||
|
game.teams.inferno.score += totalFlagScore;
|
||||||
|
game.teams.inferno.playerCount += 1;
|
||||||
|
} else {
|
||||||
|
// OBS
|
||||||
|
game.teams.obs.score += totalFlagScore;
|
||||||
|
game.teams.obs.playerCount += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
game['totalScore'] =
|
||||||
|
game.teams.storm.score + game.teams.inferno.score + game.teams.obs.score;
|
||||||
|
|
||||||
|
return game;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ services:
|
||||||
replicas: 1
|
replicas: 1
|
||||||
|
|
||||||
api:
|
api:
|
||||||
image: "amineo/t2-stats-api:v0.0.13"
|
image: "amineo/t2-stats-api:v0.0.14"
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: ./build/api/Dockerfile
|
dockerfile: ./build/api/Dockerfile
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue