use of com.faforever.server.entity.GamePlayerStats in project faf-java-server by FAForever.
the class RatingServiceTest method updateLadder1v1Ratings.
@Test
public void updateLadder1v1Ratings() throws Exception {
Player player1 = (Player) new Player().setLadder1v1Rating((Ladder1v1Rating) new Ladder1v1Rating().setMean(1500d).setDeviation(500d)).setId(1);
Player player2 = (Player) new Player().setLadder1v1Rating((Ladder1v1Rating) new Ladder1v1Rating().setMean(1500d).setDeviation(500d)).setId(2);
List<GamePlayerStats> playerStats = Arrays.asList(new GamePlayerStats().setPlayer(player1).setTeam(NO_TEAM_ID).setMean(player1.getLadder1v1Rating().getMean()).setDeviation(player1.getLadder1v1Rating().getDeviation()).setScore(10), new GamePlayerStats().setPlayer(player2).setTeam(NO_TEAM_ID).setMean(player2.getLadder1v1Rating().getMean()).setDeviation(player2.getLadder1v1Rating().getDeviation()).setScore(-1));
instance.updateRatings(playerStats, NO_TEAM_ID, RatingType.LADDER_1V1);
assertThat(player1.getLadder1v1Rating().getMean(), is(1765.511882354831));
assertThat(player1.getLadder1v1Rating().getDeviation(), is(429.1918779825801));
assertThat(player2.getLadder1v1Rating().getMean(), is(1234.4881176451688));
assertThat(player2.getLadder1v1Rating().getDeviation(), is(429.1918779825801));
assertThat(player1.getGlobalRating(), is(nullValue()));
assertThat(player2.getGlobalRating(), is(nullValue()));
}
use of com.faforever.server.entity.GamePlayerStats in project faf-java-server by FAForever.
the class RatingServiceTest method updateGlobalRatings.
@Test
public void updateGlobalRatings() throws Exception {
Player player1 = (Player) new Player().setGlobalRating((GlobalRating) new GlobalRating().setMean(1500d).setDeviation(500d)).setId(1);
Player player2 = (Player) new Player().setGlobalRating((GlobalRating) new GlobalRating().setMean(1500d).setDeviation(500d)).setId(2);
List<GamePlayerStats> playerStats = Arrays.asList(new GamePlayerStats().setPlayer(player1).setTeam(NO_TEAM_ID).setMean(player1.getGlobalRating().getMean()).setDeviation(player1.getGlobalRating().getDeviation()).setScore(10), new GamePlayerStats().setPlayer(player2).setTeam(NO_TEAM_ID).setMean(player2.getGlobalRating().getMean()).setDeviation(player2.getGlobalRating().getDeviation()).setScore(-1));
instance.updateRatings(playerStats, NO_TEAM_ID, RatingType.GLOBAL);
assertThat(player1.getGlobalRating().getMean(), is(1765.511882354831));
assertThat(player1.getGlobalRating().getDeviation(), is(429.1918779825801));
assertThat(player2.getGlobalRating().getMean(), is(1234.4881176451688));
assertThat(player2.getGlobalRating().getDeviation(), is(429.1918779825801));
assertThat(player1.getLadder1v1Rating(), is(nullValue()));
assertThat(player2.getLadder1v1Rating(), is(nullValue()));
}
use of com.faforever.server.entity.GamePlayerStats in project faf-java-server by FAForever.
the class GameService method settlePlayerScores.
/**
* Determines the final army results and updates the players' scores with them.
*/
private void settlePlayerScores(Game game) {
Map<Integer, ArmyResult> armyIdToResult = findMostReportedCompleteArmyResultsReportedByConnectedPlayers(game);
for (Entry<Integer, GamePlayerStats> entry : game.getPlayerStats().entrySet()) {
Integer playerId = entry.getKey();
Integer armyScore = Optional.ofNullable(game.getPlayerOptions()).map(playerOptions -> playerOptions.get(playerId)).map(options -> (Integer) options.get(OPTION_ARMY)).map(armyIdToResult::get).map(ArmyResult::getScore).orElse(null);
entry.getValue().setScore(armyScore).setScoreTime(Instant.now());
}
}
use of com.faforever.server.entity.GamePlayerStats in project faf-java-server by FAForever.
the class GameService method updateDivisionScoresIfValid.
private void updateDivisionScoresIfValid(Game game) {
if (game.getValidity() != Validity.VALID && !game.isRatingEnforced()) {
log.trace("Skipping update of division scores for invalid game: {}", game);
return;
}
if (!modService.isLadder1v1(game.getFeaturedMod())) {
log.trace("Skipping update of division scores for non-ladder1v1 game: {}", game);
return;
}
log.trace("Updating division scores for game: {}", game);
Assert.state(game.getConnectedPlayers().size() == 2, "A ladder1v1 game must have exactly 2 players");
Iterator<Player> playerIterator = game.getConnectedPlayers().values().iterator();
Player playerOne = playerIterator.next();
Player playerTwo = playerIterator.next();
Player winner = null;
if (!game.isMutuallyAgreedDraw()) {
winner = game.getPlayerStats().values().stream().filter(gamePlayerStats -> gamePlayerStats.getScore() != null).max(Comparator.comparingInt(GamePlayerStats::getScore)).map(GamePlayerStats::getPlayer).orElse(null);
log.trace("Game '{}' did not end with mutual draw, winner is: {}", game, winner);
} else {
log.trace("Game '{}' ended with mutual draw", game);
}
log.debug("Posting results for game '{}', playerOne: '{}', playerTwo: '{}', winner: '{}'", game, playerOne, playerTwo, winner);
divisionService.postResult(playerOne, playerTwo, winner);
}
use of com.faforever.server.entity.GamePlayerStats in project faf-java-server by FAForever.
the class GameService method createGamePlayerStats.
private void createGamePlayerStats(Game game) {
// TODO test how this handles observers
game.getConnectedPlayers().values().forEach(player -> {
GamePlayerStats gamePlayerStats = new GamePlayerStats(game, player);
Optional<Map<String, Object>> optional = Optional.ofNullable(game.getPlayerOptions().get(player.getId()));
if (!optional.isPresent()) {
log.warn("No player options available for player '{}' in game '{}'", player, game);
} else {
Map<String, Object> options = optional.get();
updateGamePlayerStatsFromOptions(gamePlayerStats, options);
}
updateGamePlayerStatsRating(gamePlayerStats, player);
gamePlayerStats.setPlayer(player);
game.getPlayerStats().put(player.getId(), gamePlayerStats);
});
}
Aggregations