Lower team participation threshold from 80% to 67%, improve team score accuracy

This commit is contained in:
Brian Beck 2021-05-31 22:10:55 -07:00
parent e01179fd72
commit e55c6ed9da

View file

@ -230,13 +230,13 @@ export class PlayersService {
'game.datestamp', 'game.datestamp',
'join_g.*', 'join_g.*',
]) ])
// Determine whether they spent at least 80% of the total match time on // Determine whether they spent at least 67% of the total match time on
// one team, and then determine whether that means they won or lost. // one team, and then determine whether that means they won or lost.
// Note that this team may be different from `dtTeamGame`. // Note that this team may be different from `dtTeamGame`.
.addSelect( .addSelect(
`CASE `CASE
WHEN WHEN
((game.stats->'timeOnTeamOneTG'->>0)::float / (game.stats->'matchRunTimeTG'->>0)::float) >= 0.8 ((game.stats->'timeOnTeamOneTG'->>0)::float / (game.stats->'matchRunTimeTG'->>0)::float) >= 0.67
THEN CASE THEN CASE
WHEN WHEN
join_g.score_storm > join_g.score_inferno join_g.score_storm > join_g.score_inferno
@ -249,7 +249,7 @@ export class PlayersService {
THEN 'draw' THEN 'draw'
END END
WHEN WHEN
((game.stats->'timeOnTeamTwoTG'->>0)::float / (game.stats->'matchRunTimeTG'->>0)::float) >= 0.8 ((game.stats->'timeOnTeamTwoTG'->>0)::float / (game.stats->'matchRunTimeTG'->>0)::float) >= 0.67
THEN CASE THEN CASE
WHEN WHEN
join_g.score_inferno > join_g.score_storm join_g.score_inferno > join_g.score_storm
@ -272,26 +272,25 @@ export class PlayersService {
qb qb
.select(['g.game_id']) .select(['g.game_id'])
.addSelect( .addSelect(
"COUNT((g.stats->'dtTeamGame'->>0)::integer = 1 OR NULL)::integer", "COUNT(CASE WHEN (g.stats->'dtTeamGame'->>0)::integer = 1 AND (g.stats->'timeOnTeamOneTG'->>0)::float > 0 THEN 1 ELSE NULL END)::integer",
'team_size_storm', 'team_size_storm',
) )
.addSelect( .addSelect(
"COUNT((g.stats->'dtTeamGame'->>0)::integer = 2 OR NULL)::integer", "COUNT(CASE WHEN (g.stats->'dtTeamGame'->>0)::integer = 2 AND (g.stats->'timeOnTeamTwoTG'->>0)::float > 0 THEN 1 ELSE NULL END)::integer",
'team_size_inferno', 'team_size_inferno',
) )
// `teamScoreGame` can get screwed up: players on one team can be // `teamScoreGame` can get screwed up: players on one team
// assigned the score from the other team (most likely due to team // can be assigned the score from the other team (most
// switching). So to determine each team's score, we take the // likely due to team switching). So to determine each
// average `teamScoreGame` of all players on that team. Due to the // team's score, we take the most common `teamScoreGame`
// mentioned bug, it won't be 100% accurate, but should be good // from all players on that team who don't have a `timeOnTeam`
// enough to determine which team won most of the time, which is all // value of 0.
// that matters for this stat.
.addSelect( .addSelect(
"(mode() WITHIN GROUP (ORDER BY CASE WHEN (g.stats->'dtTeamGame'->>0)::integer = 1 THEN (g.stats->'teamScoreGame'->>0)::integer ELSE NULL END)) / 100", "(mode() WITHIN GROUP (ORDER BY CASE WHEN ((g.stats->'dtTeamGame'->>0)::integer = 1 AND (g.stats->'timeOnTeamOneTG'->>0)::float > 0) THEN (g.stats->'teamScoreGame'->>0)::integer ELSE NULL END)) / 100",
'score_storm', 'score_storm',
) )
.addSelect( .addSelect(
"(mode() WITHIN GROUP (ORDER BY CASE WHEN (g.stats->'dtTeamGame'->>0)::integer = 2 THEN (g.stats->'teamScoreGame'->>0)::integer ELSE NULL END)) / 100", "(mode() WITHIN GROUP (ORDER BY CASE WHEN ((g.stats->'dtTeamGame'->>0)::integer = 2 AND (g.stats->'timeOnTeamTwoTG'->>0)::float > 0) THEN (g.stats->'teamScoreGame'->>0)::integer ELSE NULL END)) / 100",
'score_inferno', 'score_inferno',
) )
.from(GameDetail, 'g') .from(GameDetail, 'g')
@ -302,9 +301,9 @@ export class PlayersService {
'join_g.game_id = game.game_id', 'join_g.game_id = game.game_id',
) )
.where('game.gametype = :gameType') .where('game.gametype = :gameType')
// Only count if the player's `gamePCT` was at least 80%. This is // Only count if the player's `gamePCT` was at least 67%. This is
// effectively how much of the match they were present for. // effectively how much of the match they were present for.
.andWhere("(game.stats->'gamePCT'->>0)::float >= 80") .andWhere("(game.stats->'gamePCT'->>0)::float >= 67")
// As an extra precaution against prematurely ended matches, only count // As an extra precaution against prematurely ended matches, only count
// games that lasted at least 10 minutes. // games that lasted at least 10 minutes.
.andWhere("(game.stats->'matchRunTimeTG'->>0)::float >= 10") .andWhere("(game.stats->'matchRunTimeTG'->>0)::float >= 10")