Skip to content

Commit

Permalink
[feature] #130 평점 계산 코드 수정 (4점 미만이면 마이너스 되도록)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeesw committed May 4, 2024
1 parent f03f522 commit 25b63c4
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,15 @@ public Review saveReview(ReviewDto dto) {

int numberOfReviews = reviewRepository.countByReceiverUserId(receiver.getUserId());
double oldCoffeeBean = receiver.getCoffeeBean();
double newCoffeeBean = oldCoffeeBean + (dto.getRating() * 0.1) * numberOfReviews;

double baseline = 46.0;
double ratio = 0.1;
double standard = 4.0;

// 46 + (평점 합계 + (새로운 평점 - 기준 평점) * 반영 비율) / (평점 개수 + 1)
double newCoffeeBean =
baseline + ((oldCoffeeBean - baseline) * numberOfReviews + (dto.getRating() - standard) * ratio) /
(numberOfReviews + 1);

receiver.setCoffeeBean(newCoffeeBean);
userRepository.save(receiver);
Expand Down

0 comments on commit 25b63c4

Please sign in to comment.