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

Fix: Score calculation and avoid counting 'dismissed'-reviews as comments #97

Merged
merged 2 commits into from
Sep 18, 2024
Merged
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 @@ -40,7 +40,7 @@ public List<LeaderboardEntry> createLeaderboard() {
logger.info("Creating leaderboard dataset");

List<User> users = userService.getAllUsers();
logger.info("Found " + users.size() + " users");
logger.info("Leaderboard has " + users.size() + " users");

OffsetDateTime cutOffTime = new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24 * timeframe)
.toInstant().atOffset(ZoneOffset.UTC);
Expand All @@ -49,7 +49,6 @@ public List<LeaderboardEntry> createLeaderboard() {
if (user.getType() != UserType.USER) {
return null;
}
logger.info("User: " + user.getLogin());
AtomicInteger score = new AtomicInteger(0);
Set<PullRequestReviewDTO> changesRequestedSet = new HashSet<>();
Set<PullRequestReviewDTO> approvedSet = new HashSet<>();
Expand All @@ -64,16 +63,20 @@ public List<LeaderboardEntry> createLeaderboard() {
}
PullRequestReviewDTO reviewDTO = new PullRequestReviewDTO(review.getId(), review.getCreatedAt(),
review.getUpdatedAt(), review.getSubmittedAt(), review.getState());

switch (review.getState()) {
case CHANGES_REQUESTED:
changesRequestedSet.add(reviewDTO);
break;
case APPROVED:
approvedSet.add(reviewDTO);
break;
default:
case COMMENTED:
commentSet.add(reviewDTO);
break;
default:
// ignore other states and don't add to score
return;
}
score.addAndGet(calculateScore(review.getPullRequest()));
});
Expand Down Expand Up @@ -105,8 +108,8 @@ public List<LeaderboardEntry> createLeaderboard() {
* @return score
*/
private int calculateScore(PullRequest pullRequest) {
Double complexityScore = (pullRequest.getChangedFiles() * 3) + (pullRequest.getCommits() * 0.5)
+ pullRequest.getAdditions() + pullRequest.getDeletions();
Double complexityScore = ((pullRequest.getChangedFiles() * 3) + (pullRequest.getCommits() * 0.5)
+ pullRequest.getAdditions() + pullRequest.getDeletions()) / 10;
if (complexityScore < 10) {
return 1; // Simple
} else if (complexityScore < 50) {
Expand Down
Loading