Skip to content

Commit

Permalink
hotfix : Adjusting the number of average rating decimal places
Browse files Browse the repository at this point in the history
  • Loading branch information
Son-GyeongSik committed Nov 23, 2023
1 parent db578f3 commit 31d4f70
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -154,6 +155,7 @@ public List<RecommendLecture> getRecommendsByDomain(int domainId) {

private List<RecommendLecture> getRecommendLectures(List<?> lectures) {
List<RecommendLecture> recommendLectures = new ArrayList<>();
DecimalFormat decimalFormat = new DecimalFormat("#.#");

for (Object lecture : lectures) {
if (lecture instanceof VideoEntity) {
Expand All @@ -164,7 +166,8 @@ private List<RecommendLecture> getRecommendLectures(List<?> lectures) {
.channel(video.getChannel())
.lectureCode(video.getVideoCode())
.isPlaylist(false)
.rating((double) video.getAccumulatedRating() / video.getReviewCount())
.rating(Double.parseDouble(decimalFormat.format((double) video.getAccumulatedRating()
/ video.getReviewCount())))
.reviewCount(video.getReviewCount())
.thumbnail(video.getThumbnail())
.build());
Expand All @@ -176,7 +179,8 @@ private List<RecommendLecture> getRecommendLectures(List<?> lectures) {
.channel(playlist.getChannel())
.lectureCode(playlist.getPlaylistCode())
.isPlaylist(true)
.rating((double) playlist.getAccumulatedRating() / playlist.getReviewCount())
.rating(Double.parseDouble(decimalFormat.format((double) playlist.getAccumulatedRating()
/ playlist.getReviewCount())))
.reviewCount(playlist.getReviewCount())
.thumbnail(playlist.getThumbnail())
.build());
Expand Down

0 comments on commit 31d4f70

Please sign in to comment.