Search in sources :

Example 1 with GamePlayerStats

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()));
}
Also used : Player(com.faforever.server.entity.Player) GamePlayerStats(com.faforever.server.entity.GamePlayerStats) Ladder1v1Rating(com.faforever.server.entity.Ladder1v1Rating) Test(org.junit.Test)

Example 2 with GamePlayerStats

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()));
}
Also used : Player(com.faforever.server.entity.Player) GamePlayerStats(com.faforever.server.entity.GamePlayerStats) GlobalRating(com.faforever.server.entity.GlobalRating) Test(org.junit.Test)

Example 3 with GamePlayerStats

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());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays(java.util.Arrays) ProgrammingError(com.faforever.server.error.ProgrammingError) ModVersion(com.faforever.server.entity.ModVersion) BiFunction(java.util.function.BiFunction) ArmyResult(com.faforever.server.entity.ArmyResult) PlayerOfflineEvent(com.faforever.server.player.PlayerOfflineEvent) PlayerService(com.faforever.server.player.PlayerService) Metrics(com.faforever.server.stats.Metrics) Player(com.faforever.server.entity.Player) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) Pair(org.springframework.data.util.Pair) ArmyStatistics(com.faforever.server.stats.ArmyStatistics) ClientService(com.faforever.server.client.ClientService) CounterService(org.springframework.boot.actuate.metrics.CounterService) ConnectionAware(com.faforever.server.client.ConnectionAware) RatingService(com.faforever.server.rating.RatingService) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EventListener(org.springframework.context.event.EventListener) ErrorCode(com.faforever.server.error.ErrorCode) Streams(com.google.common.collect.Streams) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) GameState(com.faforever.server.entity.GameState) MapService(com.faforever.server.map.MapService) Ladder1v1Rating(com.faforever.server.entity.Ladder1v1Rating) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Requests(com.faforever.server.error.Requests) Stream(java.util.stream.Stream) DivisionService(com.faforever.server.ladder1v1.DivisionService) RatingType(com.faforever.server.rating.RatingType) Game(com.faforever.server.entity.Game) GlobalRating(com.faforever.server.entity.GlobalRating) Entry(java.util.Map.Entry) Optional(java.util.Optional) RequestException(com.faforever.server.error.RequestException) Joiner(com.google.common.base.Joiner) ModService(com.faforever.server.mod.ModService) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) FeaturedMod(com.faforever.server.entity.FeaturedMod) Validity(com.faforever.server.entity.Validity) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) VictoryCondition(com.faforever.server.entity.VictoryCondition) GameResponses(com.faforever.server.client.GameResponses) Service(org.springframework.stereotype.Service) ServerProperties(com.faforever.server.config.ServerProperties) Iterator(java.util.Iterator) FeaturedModFileVersion(com.faforever.server.game.GameResponse.FeaturedModFileVersion) EntityManager(javax.persistence.EntityManager) Consumer(java.util.function.Consumer) SimMod(com.faforever.server.game.GameResponse.SimMod) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) ArmyStatisticsService(com.faforever.server.stats.ArmyStatisticsService) PlayerOnlineEvent(com.faforever.server.player.PlayerOnlineEvent) GamePlayerStats(com.faforever.server.entity.GamePlayerStats) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) GamePlayerStats(com.faforever.server.entity.GamePlayerStats) ArmyResult(com.faforever.server.entity.ArmyResult)

Example 4 with GamePlayerStats

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);
}
Also used : Player(com.faforever.server.entity.Player) GamePlayerStats(com.faforever.server.entity.GamePlayerStats)

Example 5 with GamePlayerStats

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);
    });
}
Also used : GamePlayerStats(com.faforever.server.entity.GamePlayerStats) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

GamePlayerStats (com.faforever.server.entity.GamePlayerStats)8 Player (com.faforever.server.entity.Player)5 GlobalRating (com.faforever.server.entity.GlobalRating)4 Ladder1v1Rating (com.faforever.server.entity.Ladder1v1Rating)4 HashMap (java.util.HashMap)4 Map (java.util.Map)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Test (org.junit.Test)3 ServerProperties (com.faforever.server.config.ServerProperties)2 Game (com.faforever.server.entity.Game)2 Rating (com.faforever.server.entity.Rating)2 ProgrammingError (com.faforever.server.error.ProgrammingError)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ClientService (com.faforever.server.client.ClientService)1 ConnectionAware (com.faforever.server.client.ConnectionAware)1 GameResponses (com.faforever.server.client.GameResponses)1 ArmyResult (com.faforever.server.entity.ArmyResult)1 CoopLeaderboardEntry (com.faforever.server.entity.CoopLeaderboardEntry)1 CoopMap (com.faforever.server.entity.CoopMap)1