mirror of
https://github.com/amineo/t2-stat-parser.git
synced 2026-01-19 17:34:43 +00:00
Update return formats
This commit is contained in:
parent
67eb8db0c8
commit
c10cd44615
|
|
@ -58,6 +58,10 @@ export class GameService {
|
||||||
inferno: { score: 0, players: [] }
|
inferno: { score: 0, players: [] }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const teamZero = [],
|
||||||
|
teamOne = [],
|
||||||
|
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);
|
||||||
|
|
@ -75,22 +79,80 @@ export class GameService {
|
||||||
if (player.stats.dtTeamGame[0] === '1') {
|
if (player.stats.dtTeamGame[0] === '1') {
|
||||||
// Storm
|
// Storm
|
||||||
game.teams.storm.score += totalFlagScore;
|
game.teams.storm.score += totalFlagScore;
|
||||||
game.teams.storm.players.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;
|
||||||
game.teams.inferno.players.push(p);
|
teamTwo.push(p);
|
||||||
} else {
|
} else {
|
||||||
// OBS
|
// OBS
|
||||||
game.teams.obs.score += totalFlagScore;
|
game.teams.obs.score += totalFlagScore;
|
||||||
game.teams.obs.players.push(p);
|
teamZero.push(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//const teamZero: any = game; //game.find(({ stats }) => stats.dtTeamGame[0] === '3');
|
game['teams']['obs']['players'] = teamZero.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);
|
||||||
|
|
||||||
// const teamOne: any = game.find(({ stats }) => stats.dtTeamGame[0] === '1');
|
return game;
|
||||||
// const teamTwo: any = game.find(({ stats }) => stats.dtTeamGame[0] === '2');
|
}
|
||||||
|
|
||||||
|
async findOneAbvSummary(gameId: string) {
|
||||||
|
const query = await this.gameRepository.find({
|
||||||
|
relations: [ 'game', 'playerGuid' ],
|
||||||
|
where: [ { game: { gameId: gameId } } ]
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!query.length) {
|
||||||
|
throw new NotFoundException(`Game ID: ${gameId} not found`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const game: any = {
|
||||||
|
...query[0].game
|
||||||
|
};
|
||||||
|
|
||||||
|
// Need to set return based off gameType
|
||||||
|
// Modify game object if not a CTF type game and return early
|
||||||
|
if (query[0].gametype !== 'CTFGame' && query[0].gametype !== 'SCtFGame') {
|
||||||
|
game['totalScore'] = 0;
|
||||||
|
|
||||||
|
for (const player of query) {
|
||||||
|
const stats = formatPlayerStats(player);
|
||||||
|
|
||||||
|
game.totalScore += stats.scoreTG;
|
||||||
|
}
|
||||||
|
|
||||||
|
return game;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Team Based game stats (CTF/SCtF)
|
||||||
|
game['teams'] = {
|
||||||
|
obs: { score: 0, playerCount: 0 },
|
||||||
|
storm: { score: 0, playerCount: 0 },
|
||||||
|
inferno: { score: 0, playerCount: 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const player of 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') {
|
||||||
|
// 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;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,14 @@ export class GamesService {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return games;
|
const abvSummary = [];
|
||||||
|
for (const game of games) {
|
||||||
|
const summary = await this.gameService.findOneAbvSummary(game.gameId);
|
||||||
|
abvSummary.push(summary);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only return games when the score is 100 or greater
|
||||||
|
return abvSummary.filter((g) => g.totalScore >= 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAllWithSummary(paginationQuery: PaginationQueryDto) {
|
async findAllWithSummary(paginationQuery: PaginationQueryDto) {
|
||||||
|
|
@ -50,13 +57,11 @@ export class GamesService {
|
||||||
withSummary.push(summary);
|
withSummary.push(summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Game findOne service needs to bubble up the game details as parent object and set players below it
|
|
||||||
|
|
||||||
return withSummary;
|
return withSummary;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findByType(gametype: string) {
|
async findByType(gametype: string) {
|
||||||
const game = await this.gamesRepository.find({
|
const games = await this.gamesRepository.find({
|
||||||
where: { gametype: gametype },
|
where: { gametype: gametype },
|
||||||
skip: 0,
|
skip: 0,
|
||||||
take: 10,
|
take: 10,
|
||||||
|
|
@ -64,10 +69,18 @@ export class GamesService {
|
||||||
gameId: 'DESC'
|
gameId: 'DESC'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!game.length) {
|
if (!games.length) {
|
||||||
throw new NotFoundException(`Game Type: ${gametype} not found`);
|
throw new NotFoundException(`Game Type: ${gametype} not found`);
|
||||||
}
|
}
|
||||||
return game;
|
|
||||||
|
const abvSummary = [];
|
||||||
|
for (const game of games) {
|
||||||
|
const summary = await this.gameService.findOneAbvSummary(game.gameId);
|
||||||
|
abvSummary.push(summary);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only return games when the score is 100 or greater
|
||||||
|
return abvSummary.filter((g) => g.totalScore >= 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findByTypeWithSummary(gametype: string, paginationQuery: PaginationQueryDto) {
|
async findByTypeWithSummary(gametype: string, paginationQuery: PaginationQueryDto) {
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ export class PlayersService {
|
||||||
async findAll(paginationQuery: PaginationQueryDto) {
|
async findAll(paginationQuery: PaginationQueryDto) {
|
||||||
const { limit, offset } = paginationQuery;
|
const { limit, offset } = paginationQuery;
|
||||||
|
|
||||||
const returnMaxLimit = Math.min(300, Math.max(0, limit));
|
const returnMaxLimit = Math.min(500, Math.max(0, limit));
|
||||||
|
|
||||||
const players = await this.playersRepository.find({
|
const players = await this.playersRepository.find({
|
||||||
skip: offset,
|
skip: offset,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue