Skip to content

Commit

Permalink
Changed reputation policy
Browse files Browse the repository at this point in the history
  • Loading branch information
EnesBaserr committed Dec 8, 2024
1 parent 7b8a145 commit 556fe29
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public Long getDownvoteCount() {
return votes.stream().filter(vote -> !vote.isUpvote()).count();
}

public Long getVoteDifference() {
return Math.max(this.getUpvoteCount() - this.getDownvoteCount(), 0);
}

public Integer getRating() {
return (int)(this.getUpvoteCount() - this.getDownvoteCount());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,8 @@ public Long getUpvoteCount() {
public Long getDownvoteCount() {
return votes.stream().filter(vote -> !vote.isUpvote()).count();
}
public Long getVoteDifference() {
return Math.max(getUpvoteCount() - getDownvoteCount(), 0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ public Optional<User> getUserById(Long id) {
public Long calculateReputation(User user) {
List<Question> questions = questionRepository.findByAuthorId(user.getId());
long questionCount = questions.size();
Long questionUpvoteCount = questions.stream().map(Question::getUpvoteCount).reduce(0L, Long::sum);
Long questionDownvoteCount = questions.stream().map(Question::getDownvoteCount).reduce(0L, Long::sum);
Long questionVoteDifference = questions.stream().map(Question::getVoteDifference).reduce(0L, Long::sum);
List< Answer> answers= answerRepository.findByAnsweredBy(user.getId());
long answerCount = answers.size();
Long answerUpvoteCount = answers.stream().map(Answer::getUpvoteCount).reduce(0L, Long::sum);
Long answerDownvoteCount = answers.stream().map(Answer::getDownvoteCount).reduce(0L, Long::sum);
return (questionCount * 10 + answerCount * 15 + questionUpvoteCount * 25 + answerUpvoteCount * 30) - (questionDownvoteCount*10 + answerDownvoteCount*15);
Long answerVoteDifference = answers.stream().map(Answer::getVoteDifference).reduce(0L, Long::sum);
return (questionCount * 10 + answerCount * 15 + questionVoteDifference * 25 + answerVoteDifference * 30);

}

Expand Down

0 comments on commit 556fe29

Please sign in to comment.