Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional fixes #88

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class LevelStatusService {
*/
@Transactional
public void initializeLevelStatus(@NotNull Integer userId) {
if (levelStatusRepository.findByUserId(userId) != null)
return;
List<Integer> initialStars = Arrays.asList(0);
LevelStatus levelStatus = LevelStatus.builder()
.userId(userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ public void updateMatch(UpdateMatchRequest updateMatchRequest) {
return;
}
Verdict matchVerdict = deduceMatchVerdict(updateMatchRequest.getGameResults());
SubmitStatus submitStatus = submitStatusRepository.findByUserId(match.getPlayerId1());

List<GameLogs> gameLogsList = new ArrayList<>();
var gameResults = updateMatchRequest.getGameResults();
Expand All @@ -434,7 +435,11 @@ public void updateMatch(UpdateMatchRequest updateMatchRequest) {
Integer playerId = match.getPlayerId1();
socketService.sendMessage(socketMatchResultDest + playerId, gameLogsList.toString());
String matchMessage = getMatchResultByVerdict(matchId, matchVerdict, playerId);
socketService.sendMessage(socketAlertMessageDest + playerId, matchMessage);

// If this is a test match for submitting code, there is no need to display match result
if (!(submitStatus !=null && submitStatus.getIsPending()))
socketService.sendMessage(socketAlertMessageDest + playerId, matchMessage);

createMatchNotification(playerId, matchMessage);
}

Expand Down Expand Up @@ -497,10 +502,10 @@ public void updateMatch(UpdateMatchRequest updateMatchRequest) {

if (starCount > 0) levelStatusService.updateLevelStatus(playerId, currentLevel, starCount);

SubmitStatus submitStatus = submitStatusRepository.findByUserId(playerId);
if (submitStatus !=null && submitStatus.getIsPending())
if (submitStatus !=null && submitStatus.getIsPending()) {
versionControlService.confirmLockedCode(playerId);
socketService.sendMessage(socketAlertMessageDest + match.getPlayerId1(), "Code Locked");
socketService.sendMessage(socketAlertMessageDest + match.getPlayerId1(), "Code Locked");
}
}

matchRepository.save(match);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ public void calculateMatchRatings(Integer userId1, Integer userId2, Verdict verd

// Calculate weighted rating deviations for both players
Double weightedRatingDeviation1 = ratingCalculator.calculateWeightedRatingDeviation(
rating1.getRating(), matchService.getRecentMatchTime(userId1));
rating1.getRatingDeviation(), matchService.getRecentMatchTime(userId1));
Double weightedRatingDeviation2 = ratingCalculator.calculateWeightedRatingDeviation(
rating2.getRating(), matchService.getRecentMatchTime(userId2));
rating2.getRatingDeviation(), matchService.getRecentMatchTime(userId2));

rating1.setRatingDeviation(weightedRatingDeviation1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class RatingCalculator {
// Constants
private Double q = (Math.log(10) / 400);

private Double minRatingDeviation = 50d;
private Double minRatingDeviation = 30d;

// Amount which decides how much a player's rating deviation changes every time period
private Double c = 416d;
Expand All @@ -25,10 +25,10 @@ public class RatingCalculator {
* @return g(rd)
*/
private Double calculateGRD(Double rd) {
Double numerator = 1d + 3d * (q * q) * (rd * rd);
Double numerator = 3d * (q * q) * (rd * rd);
Double pi = Math.PI;
Double denominator = pi * pi;
return (1d / Math.sqrt(numerator / denominator));
return (1d / Math.sqrt(1d + (numerator / denominator)));
}

/**
Expand Down