use of com.faforever.server.entity.GamePlayerStats in project faf-java-server by FAForever.
the class RatingService method teamsById.
private Map<Integer, ScoredTeam> teamsById(Collection<GamePlayerStats> playerStats, int noTeamId) {
int highestTeamId = playerStats.stream().map(GamePlayerStats::getTeam).max(Integer::compareTo).orElse(noTeamId);
Map<Integer, ScoredTeam> teamsById = new HashMap<>();
for (GamePlayerStats playerStat : playerStats) {
IPlayer player = new Player<>(playerStat.getPlayer().getId());
jskills.Rating rating = new jskills.Rating(playerStat.getMean(), playerStat.getDeviation());
int teamId = playerStat.getTeam();
if (teamId == noTeamId) {
// If a player is in the "no team" team, assign him to his own team
teamId = playerStat.getPlayer().getId() + highestTeamId;
}
teamsById.computeIfAbsent(teamId, ScoredTeam::new).addPlayer(player, rating);
teamsById.get(teamId).getScore().updateAndGet(score -> score + playerStat.getScore());
}
return teamsById;
}
use of com.faforever.server.entity.GamePlayerStats in project faf-java-server by FAForever.
the class RatingService method updateRatings.
/**
* Updates the ratings of all players in {@code playerStats} as well as their global/ladder1v1 rating,
* according to the outcome of the game <strong> without persisting the results</strong>.
*
* @param noTeamId ID of the "no team" team
*/
@SuppressWarnings("unchecked")
public void updateRatings(Collection<GamePlayerStats> playerStats, int noTeamId, RatingType ratingType) {
Map<Integer, GamePlayerStats> playerStatsByPlayerId = playerStats.stream().collect(Collectors.toMap(stats -> stats.getPlayer().getId(), Function.identity()));
Map<Integer, ScoredTeam> teamsById = teamsById(playerStats, noTeamId);
List<ScoredTeam> teamsSortedByScore = new ArrayList<>(teamsById.values());
teamsSortedByScore.sort(Comparator.comparingInt(o -> ((ScoredTeam) o).getScore().intValue()).reversed());
int[] teamRanks = calculateTeamRanks(teamsSortedByScore);
// New ArrayList is needed because the JSkill API doesn't handle subclass type parameters
TrueSkillCalculator.calculateNewRatings(gameInfo, new ArrayList<>(teamsSortedByScore), teamRanks).entrySet().forEach(entry -> {
Player<Integer> player = (Player<Integer>) entry.getKey();
GamePlayerStats stats = playerStatsByPlayerId.get(player.getId());
updatePlayerStats(entry, stats);
updateRating(ratingType, stats);
});
}
use of com.faforever.server.entity.GamePlayerStats in project faf-java-server by FAForever.
the class CoopServiceTest method reportOperationComplete.
@Test
public void reportOperationComplete() throws Exception {
Game game = new Game().setId(42).setMapName("SCMP_001");
Map<Integer, GamePlayerStats> playerStats = game.getPlayerStats();
playerStats.put(1, new GamePlayerStats());
playerStats.put(2, new GamePlayerStats());
playerStats.put(3, new GamePlayerStats());
Player player = new Player();
player.setCurrentGame(game);
CoopMap mission = new CoopMap();
when(coopMapRepository.findOneByFilenameLikeIgnoreCase("SCMP_001")).thenReturn(Optional.of(mission));
instance.reportOperationComplete(player, false, Duration.ofMinutes(8));
ArgumentCaptor<CoopLeaderboardEntry> captor = ArgumentCaptor.forClass(CoopLeaderboardEntry.class);
verify(coopLeaderboardRepository).save(captor.capture());
CoopLeaderboardEntry entry = captor.getValue();
assertThat(entry.getGameId(), is(42L));
assertThat(entry.getMission(), is(mission));
assertThat(entry.getPlayerCount(), is(3));
assertThat(entry.getTime(), is(Time.from(Instant.EPOCH.plus(Duration.ofMinutes(8)))));
}
Aggregations