use of com.faforever.server.entity.GlobalRating in project faf-java-server by FAForever.
the class RatingServiceTest method calculateQuality.
@Test
public void calculateQuality() throws Exception {
Rating left = new GlobalRating().setMean(1600d).setDeviation(30d);
Rating right = new GlobalRating().setMean(900d).setDeviation(160d);
double quality = instance.calculateQuality(left, right);
assertThat(quality, is(0.16000885216755253));
}
use of com.faforever.server.entity.GlobalRating 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.GlobalRating in project faf-java-server by FAForever.
the class ClientServiceTest method sendUserDetails.
@Test
public void sendUserDetails() throws Exception {
Avatar avatar = new Avatar().setUrl("http://example.com").setDescription("Tooltip");
player.setAvailableAvatars(Collections.singletonList(new AvatarAssociation().setAvatar(avatar).setPlayer(player).setSelected(true))).setGlobalRating((GlobalRating) new GlobalRating().setNumGames(12).setMean(1100d).setDeviation(100d)).setLadder1v1Rating((Ladder1v1Rating) new Ladder1v1Rating().setMean(900d).setDeviation(50d)).setClanMemberships(Collections.singletonList(new ClanMembership().setClan(new Clan().setTag("FOO")))).setCountry("CH").setLogin("JUnit").setId(5);
instance.sendLoginDetails(player, player);
ArgumentCaptor<PlayerResponse> captor = ArgumentCaptor.forClass(PlayerResponse.class);
verify(clientGateway).send(captor.capture(), any());
PlayerResponse response = captor.getValue();
assertThat(response.getPlayerId(), is(5));
assertThat(response.getUsername(), is("JUnit"));
assertThat(response.getPlayer().getAvatar().getDescription(), is("Tooltip"));
assertThat(response.getPlayer().getAvatar().getUrl(), is("http://example.com"));
assertThat(response.getPlayer().getGlobalRating().getMean(), is(1100d));
assertThat(response.getPlayer().getGlobalRating().getDeviation(), is(100d));
assertThat(response.getPlayer().getLadder1v1Rating().getMean(), is(900d));
assertThat(response.getPlayer().getLadder1v1Rating().getDeviation(), is(50d));
assertThat(response.getPlayer().getNumberOfGames(), is(12));
assertThat(response.getPlayer().getClanTag(), is("FOO"));
assertThat(response.getCountry(), is("CH"));
}
use of com.faforever.server.entity.GlobalRating in project faf-java-server by FAForever.
the class GameService method updateGamePlayerStatsRating.
private void updateGamePlayerStatsRating(GamePlayerStats gamePlayerStats, Player player) {
Game game = player.getCurrentGame();
if (modService.isLadder1v1(game.getFeaturedMod())) {
if (player.getLadder1v1Rating() == null) {
ratingService.initLadder1v1Rating(player);
}
Assert.state(Optional.ofNullable(player.getLadder1v1Rating()).isPresent(), "Ladder1v1 rating not properly initialized");
Ladder1v1Rating ladder1v1Rating = player.getLadder1v1Rating();
gamePlayerStats.setDeviation(ladder1v1Rating.getDeviation());
gamePlayerStats.setMean(ladder1v1Rating.getMean());
} else {
if (player.getGlobalRating() == null) {
ratingService.initGlobalRating(player);
}
Assert.state(Optional.ofNullable(player.getGlobalRating()).isPresent(), "Global rating not properly initialized");
GlobalRating globalRating = player.getGlobalRating();
gamePlayerStats.setDeviation(globalRating.getDeviation());
gamePlayerStats.setMean(globalRating.getMean());
}
}
use of com.faforever.server.entity.GlobalRating in project faf-java-server by FAForever.
the class ClientService method toPlayerInformationResponse.
private PlayerResponse toPlayerInformationResponse(Player player) {
Optional<PlayerResponse.Player.Avatar> avatar = player.getAvailableAvatars().stream().filter(AvatarAssociation::isSelected).findFirst().map(association -> {
com.faforever.server.entity.Avatar avatarEntity = association.getAvatar();
return new PlayerResponse.Player.Avatar(avatarEntity.getUrl(), avatarEntity.getDescription());
});
Optional<Rating> globalRating = Optional.ofNullable(player.getGlobalRating()).map(rating -> new Rating(rating.getMean(), rating.getDeviation()));
Optional<Rating> ladder1v1Rating = Optional.ofNullable(player.getLadder1v1Rating()).map(rating -> new Rating(rating.getMean(), rating.getDeviation()));
return new PlayerResponse(player.getId(), player.getLogin(), player.getCountry(), new PlayerResponse.Player(globalRating.orElse(null), ladder1v1Rating.orElse(null), Optional.ofNullable(player.getGlobalRating()).map(GlobalRating::getNumGames).orElse(0), avatar.orElse(null), Optional.ofNullable(player.getClan()).map(Clan::getTag).orElse(null)));
}
Aggregations