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:
Anthony Mineo 2020-09-30 16:20:16 -04:00
parent c1fcb61731
commit a14fec7355
3 changed files with 151 additions and 121 deletions

View file

@ -4,6 +4,7 @@
function formatPlayerStats(statObj: any) {
return {
...statObj.stats,
teamScoreGame: Number(statObj.stats.teamScoreGame),
masTG: Number(statObj.stats.masTG),
cgMATG: Number(statObj.stats.cgMATG),
kdrAvg: Number(statObj.stats.kdrAvg),

View file

@ -10,150 +10,179 @@ import formatPlayerStats from '../common/util/formatStats';
@Injectable()
export class GameService {
constructor(
private readonly connection: Connection,
private readonly configService: ConfigService,
@InjectRepository(Games) private readonly gamesRepository: Repository<Games>,
@InjectRepository(GameDetail) private readonly gameRepository: Repository<GameDetail>
) {}
constructor(
private readonly connection: Connection,
private readonly configService: ConfigService,
@InjectRepository(Games)
private readonly gamesRepository: Repository<Games>,
@InjectRepository(GameDetail)
private readonly gameRepository: Repository<GameDetail>,
) {}
async findOne(gameId: string) {
const query = await this.gameRepository.find({
relations: [ 'game', 'playerGuid' ],
where: [ { game: { gameId: gameId } } ]
});
async findOne(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`);
}
if (!query.length) {
throw new NotFoundException(`Game ID: ${gameId} not found`);
}
const game: any = {
...query[0].game
};
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['players'] = [];
for (const player of query) {
const { playerName } = player;
const stats = formatPlayerStats(player);
// 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['players'] = [];
for (const player of query) {
const { playerName } = player;
const stats = formatPlayerStats(player);
const p = {
playerGuid: player.playerGuid.playerGuid,
playerName,
stats
};
const p = {
playerGuid: player.playerGuid.playerGuid,
playerName,
stats,
};
game.players.push(p);
}
game.players.push(p);
}
return game;
}
return game;
}
// Team Based game stats (CTF/SCtF)
game['teams'] = {
obs: { score: 0, players: [] },
storm: { score: 0, players: [] },
inferno: { score: 0, players: [] }
};
// Team Based game stats (CTF/SCtF)
game['teams'] = {
obs: { score: 0, players: [] },
storm: { score: 0, players: [] },
inferno: { score: 0, players: [] },
};
const teamZero = [],
teamOne = [],
teamTwo = [];
const teamZero = [],
teamOne = [],
teamTwo = [];
for (const player of query) {
const { playerName } = player;
const stats = formatPlayerStats(player);
for (const player of query) {
const { playerName } = player;
const stats = formatPlayerStats(player);
const p = {
playerGuid: player.playerGuid.playerGuid,
playerName,
stats
};
const p = {
playerGuid: player.playerGuid.playerGuid,
playerName,
stats,
};
const flagGrabsTG = parseInt(player.stats.flagGrabsTG[0]);
const flagCapsTG = parseInt(player.stats.flagCapsTG[0]) * 100;
const totalFlagScore = flagGrabsTG + flagCapsTG;
if (isNaN(player.stats.teamScoreGame)) {
// legacy calculations for game totals (not using the new teamScoreGame attribute)
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;
teamOne.push(p);
} else if (player.stats.dtTeamGame[0] === '2') {
// Inferno
game.teams.inferno.score += totalFlagScore;
teamTwo.push(p);
} else {
// OBS
game.teams.obs.score += totalFlagScore;
teamZero.push(p);
}
}
if (player.stats.dtTeamGame[0] === '1') {
// Storm
game.teams.storm.score += totalFlagScore;
teamOne.push(p);
} else if (player.stats.dtTeamGame[0] === '2') {
// Inferno
game.teams.inferno.score += totalFlagScore;
teamTwo.push(p);
} else {
// OBS
game.teams.obs.score += totalFlagScore;
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']['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);
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,
);
return game;
}
return game;
}
async findOneAbvSummary(gameId: string) {
const query = await this.gameRepository.find({
relations: [ 'game', 'playerGuid' ],
where: [ { game: { gameId: gameId } } ]
});
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`);
}
if (!query.length) {
throw new NotFoundException(`Game ID: ${gameId} not found`);
}
const game: any = {
...query[0].game
};
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;
// 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);
for (const player of query) {
const stats = formatPlayerStats(player);
game.totalScore += stats.scoreTG;
}
game.totalScore += stats.scoreTG;
}
return game;
}
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 }
};
// 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;
console.log(query);
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;
for (const player of query) {
const flagGrabsTG = parseInt(player.stats.flagGrabsTG[0]);
const flagCapsTG = parseInt(player.stats.flagCapsTG[0]) * 100;
const totalFlagScore = flagGrabsTG + flagCapsTG;
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;
}
}

View file

@ -44,7 +44,7 @@ services:
replicas: 1
api:
image: "amineo/t2-stats-api:v0.0.13"
image: "amineo/t2-stats-api:v0.0.14"
build:
context: .
dockerfile: ./build/api/Dockerfile