Skip to content

Commit

Permalink
Fix Glicko Rating (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-vimal authored Mar 6, 2020
1 parent c269b77 commit 5200ad7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ public ResponseEntity<List<UserRatingsResponse>> getUserRatings(@PathVariable St
}

@GetMapping(value = "/match/{pageNo}/{pageSize}")
public ResponseEntity<List<PrivateMatchResponse>> getManualAndAutoMatches(@PathVariable Integer pageNo, @PathVariable Integer pageSize, Authentication authentication) {
public ResponseEntity<List<PrivateMatchResponse>> getManualAndAutoExecutedMatches(@PathVariable Integer pageNo, @PathVariable Integer pageSize, Authentication authentication) {
String email = userService.getEmailFromAuthentication(authentication);
User user = userService.getUserByEmail(email);
Pageable pageable = PageRequest.of(pageNo - 1, pageSize);
return new ResponseEntity<>(matchService.getManualAndAutoMatchesPaginated(user.getUserId(), pageable), HttpStatus.OK);
return new ResponseEntity<>(matchService.getManualAndAutoExecutedMatchesPaginated(user.getUserId(), pageable), HttpStatus.OK);
}
}
3 changes: 2 additions & 1 deletion src/main/java/delta/codecharacter/server/model/TopMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ public class TopMatch {

@NotNull
@Field("created_at")
private Date createdAt;
@Builder.Default
private Date createdAt = new Date();
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,15 @@ public List<MatchResponse> getTopMatches(Integer PageNumber, Integer PageSize) {
* @param userId UserId of the player
* @return List of paginated manual and auto matches
*/
public List<PrivateMatchResponse> getManualAndAutoMatchesPaginated(Integer userId, Pageable pageable) {
public List<PrivateMatchResponse> getManualAndAutoExecutedMatchesPaginated(Integer userId, Pageable pageable) {
Aggregation aggregation = newAggregation(
match(
new Criteria().andOperator(
new Criteria().andOperator(
new Criteria().orOperator(Criteria.where("player_id_1").is(userId), Criteria.where("player_id_2").is(userId)),
new Criteria().orOperator(Criteria.where("match_mode").is(MatchMode.MANUAL), Criteria.where("match_mode").is(MatchMode.AUTO))
)
), Criteria.where("status").is("EXECUTED")
)
),
sort(Sort.by("createdAt").descending()),
skip((long) pageable.getPageNumber() * pageable.getPageSize()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public void calculateMatchRatings(Integer userId1, Integer userId2, Verdict verd
rating2.getRating(), matchService.getRecentMatchTime(userId2));

rating1.setRatingDeviation(weightedRatingDeviation1);
rating2.setRatingDeviation(weightedRatingDeviation2);

GlickoRating glickoRating1 = GlickoRating.builder()
.rating(rating1.getRating())
Expand All @@ -132,10 +131,10 @@ public void calculateMatchRatings(Integer userId1, Integer userId2, Verdict verd

// Calculate player 2 new rating
List<GlickoRating> opponentRatings2 = new ArrayList<>();
opponentRatings1.add(glickoRating1);
opponentRatings2.add(glickoRating1);

List<Double> matchScores2 = new ArrayList<>();
matchScores1.add(getVerdictScore(verdict, true));
matchScores2.add(getVerdictScore(verdict, true));

Double newRating2 = ratingCalculator.calculateNewRating(glickoRating2, opponentRatings2, matchScores2);

Expand All @@ -161,7 +160,8 @@ private Double getVerdictScore(Verdict verdict, boolean isOpponent) {
score = 0.5d;
}

if (isOpponent) return (1d - score);
if (isOpponent)
return (1d - score);

return score;
}
Expand Down

0 comments on commit 5200ad7

Please sign in to comment.