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

[SWM-387] Feat : supplement recommendation logic #131

Merged
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 @@ -14,6 +14,7 @@
import org.springframework.transaction.annotation.Transactional;

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

@Slf4j
@Service
Expand All @@ -39,8 +40,8 @@ public Recommendations getRecommendations(Long memberId) {
List<RecommendLecture> generalRecommendLectureList = new ArrayList<>();
List<RecommendLecture> channelRecommendLectureList = getRecommendsByChannel(memberId);

generalRecommendLectureList.addAll(getRecommendLectures(videoService.getTopRatedVideos(5)));
generalRecommendLectureList.addAll(getRecommendLectures(playlistService.getTopRatedPlaylists(5)));
generalRecommendLectureList.addAll(getRecommendLectures(videoService.getTopRatedVideos(10)));
generalRecommendLectureList.addAll(getRecommendLectures(playlistService.getTopRatedPlaylists(10)));

Set<String> enrolledLectureSet = lectureService.getEnrolledLectures(memberId);

Expand All @@ -49,22 +50,26 @@ public Recommendations getRecommendations(Long memberId) {
channelRecommendLectureList.removeIf(recommendLecture -> (recommendLecture.getLectureCode().equals(lectureCode)));
}

Collections.shuffle(generalRecommendLectureList);
Collections.shuffle(channelRecommendLectureList);
Recommendations recommendations = Recommendations.builder()
.generalRecommendations(generalRecommendLectureList)
.channelRecommendations(channelRecommendLectureList)
.channelRecommendations(channelRecommendLectureList.stream()
.limit(20)
.collect(Collectors.toList()))
.build();

return recommendations;
}


public List<RecommendLecture> getRecommendsByChannel(Long memberId) {
List<RecommendLecture> recommendLecturesByChannel = new ArrayList<>();
HashSet<RecommendLecture> recommendLectureSetByChannel = new HashSet<>();
List<String> channels = lectureService.getMostEnrolledChannels(memberId);

final int SELECT_BY_RANDOM_LIMIT = 1;
final int SELECT_BY_PUBLISH_DATE_LIMIT = 2;
final int SELECT_BY_VIEWED_LIMIT = 3;
final int SELECT_BY_RANDOM_LIMIT = 2;
final int SELECT_BY_PUBLISH_DATE_LIMIT = 3;
final int SELECT_BY_VIEWED_LIMIT = 5;

for (String channelName : channels) {
List<Object> lectures = new ArrayList<>();
Expand All @@ -78,10 +83,10 @@ public List<RecommendLecture> getRecommendsByChannel(Long memberId) {
lectures.addAll(videoRepository.getLatestOrderByChannel(channelName, SELECT_BY_PUBLISH_DATE_LIMIT));
lectures.addAll(playlistRepository.getLatestOrderByChannel(channelName, SELECT_BY_PUBLISH_DATE_LIMIT));

recommendLecturesByChannel.addAll(getRecommendLectures(lectures));
recommendLectureSetByChannel.addAll(getRecommendLectures(lectures));
}

return recommendLecturesByChannel;
return new ArrayList<>(recommendLectureSetByChannel);
}

public List<RecommendLecture> getRecommendLectures(List<?> lectures) {
Expand Down
Loading