Package org.localify.playlist
Class PlaylistUtils
java.lang.Object
org.localify.playlist.PlaylistUtils
A utility class for playlist-related operations.
-
Constructor Summary
ConstructorsConstructorDescriptionPlaylistUtils(ArtistRepository artistRepository, UserCityRepository userCityRepository, UserRepository userRepository, CityRepository cityRepository, ArtistCityRepository artistCityRepository, UserRecommendationRepository userRecommendationRepository, SongRepository songRepository, PlaylistSongPairRepository playlistSongPairRepository, EventRepository eventRepository, VenueRepository venueRepository, ArtistEventRepository artistEventRepository, FestivalUserRepository festivalUserRepository, PlaylistRepository playlistRepository) Constructs a new PlaylistUtils. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTopSongs(Map<Artist, TopSongQueue> artistSongs, Artist artist, int songLimit) Adds the top songs for an artist to a map.buildPairs(RecommendedArtistDto rec, Map<Artist, TopSongQueue> artistSongs, List<Song> heavyRotation, int localPerSeed, boolean useSeedSong) Builds a pair of artists for a playlist.voidChecks if a playlist can be created from a list of recommendations.intcompareArtistsByNextEvent(AbstractMap.SimpleEntry<Artist, Event> ae1, AbstractMap.SimpleEntry<Artist, Event> ae2) Compares two artist-event pairs by the event's start time.intcompareByPopularity(Song s1, Song s2) Compares two songs by popularity.intcompareByRotationPopularity(Song s1, Song s2, List<Song> heavyRotation) Compares two songs by their presence in a user's heavy rotation and then by popularity.Filters a user artist recommendation.getOrCreateEmptyPlaylist(User user, String name) Gets or creates an empty playlist for a user.makeCityPlaylist(UUID cityId) Creates a playlist for a city.makeUserFestivalPlaylist(List<RecommendedFestivalArtistDto> rec, UUID userId, UUID festivalId, List<Song> heavyRotation, int localPerSeed, boolean useSeedSong) Creates a playlist for a user for a festival.makeUserPlaylist(List<RecommendedArtistDto> rec, UUID userId, UUID cityId, List<Song> heavyRotation, int localPerSeed, boolean useSeedSong) Creates a playlist for a user for a city.makeVenuePlaylist(UUID venueId) Creates a playlist for a venue.pickTopSongsMultinomial(List<Song> songs, int numSongs) Picks a number of top songs from a list using a multinomial distribution based on popularity.savePlaylistDescription(Playlist playlist, String description) Saves the description for a playlist.savePlaylistToFestivalUser(FestivalUser festivalUser, Playlist playlist) Saves a playlist to a festival user.savePlaylistToUser(UserCity userCity, Playlist playlist) Saves a playlist to a user's city.voidsaveSongPairs(Playlist playlist, List<ArtistPair> selected) Saves a list of song pairs to a playlist.voidsoftShuffleByPopularityAndAdd(List<AbstractMap.SimpleEntry<Artist, Event>> artists, List<AbstractMap.SimpleEntry<Artist, Event>> artistsWithoutEvents) Soft-shuffles a list of artists without events by popularity and adds them to a list of artists with events.
-
Constructor Details
-
PlaylistUtils
@Autowired public PlaylistUtils(ArtistRepository artistRepository, UserCityRepository userCityRepository, UserRepository userRepository, CityRepository cityRepository, ArtistCityRepository artistCityRepository, UserRecommendationRepository userRecommendationRepository, SongRepository songRepository, PlaylistSongPairRepository playlistSongPairRepository, EventRepository eventRepository, VenueRepository venueRepository, ArtistEventRepository artistEventRepository, FestivalUserRepository festivalUserRepository, PlaylistRepository playlistRepository) Constructs a new PlaylistUtils.- Parameters:
artistRepository- The artist repository.userCityRepository- The user city repository.userRepository- The user repository.cityRepository- The city repository.artistCityRepository- The artist city repository.userRecommendationRepository- The user recommendation repository.songRepository- The song repository.playlistSongPairRepository- The playlist song pair repository.eventRepository- The event repository.venueRepository- The venue repository.artistEventRepository- The artist event repository.festivalUserRepository- The festival user repository.playlistRepository- The playlist repository.
-
-
Method Details
-
filter
Filters a user artist recommendation.- Parameters:
rec- The recommendation to filter.- Returns:
- The filtered recommendation, or null if it doesn't meet the criteria.
-
compareByRotationPopularity
Compares two songs by their presence in a user's heavy rotation and then by popularity.- Parameters:
s1- The first song.s2- The second song.heavyRotation- The list of songs in heavy rotation.- Returns:
- A negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
-
compareByPopularity
Compares two songs by popularity.- Parameters:
s1- The first song.s2- The second song.- Returns:
- A negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
-
addTopSongs
Adds the top songs for an artist to a map.- Parameters:
artistSongs- The map of artists to their top songs.artist- The artist.songLimit- The maximum number of songs to add.
-
buildPairs
public ArtistPair buildPairs(RecommendedArtistDto rec, Map<Artist, TopSongQueue> artistSongs, List<Song> heavyRotation, int localPerSeed, boolean useSeedSong) Builds a pair of artists for a playlist.- Parameters:
rec- The recommended artist DTO.artistSongs- A map of artists to their top songs.heavyRotation- A list of songs in heavy rotation.localPerSeed- The number of local artists to include per seed artist.useSeedSong- Whether to include a song from the seed artist.- Returns:
- The artist pair.
-
saveSongPairs
Saves a list of song pairs to a playlist.- Parameters:
playlist- The playlist.selected- The list of selected artist pairs.
-
checkPlaylistCreatability
Checks if a playlist can be created from a list of recommendations.- Parameters:
recs- The list of recommended artist DTOs.
-
getOrCreateEmptyPlaylist
Gets or creates an empty playlist for a user.- Parameters:
user- The user.name- The name of the playlist.- Returns:
- The playlist.
-
savePlaylistDescription
Saves the description for a playlist.- Parameters:
playlist- The playlist.description- The description.- Returns:
- The updated playlist.
-
savePlaylistToFestivalUser
Saves a playlist to a festival user.- Parameters:
festivalUser- The festival user.playlist- The playlist.- Returns:
- The updated festival user.
-
makeUserFestivalPlaylist
@Transactional(propagation=REQUIRES_NEW) public Playlist makeUserFestivalPlaylist(List<RecommendedFestivalArtistDto> rec, UUID userId, UUID festivalId, List<Song> heavyRotation, int localPerSeed, boolean useSeedSong) Creates a playlist for a user for a festival.- Parameters:
rec- The list of recommended festival artist DTOs.userId- The ID of the user.festivalId- The ID of the festival.heavyRotation- A list of songs in heavy rotation.localPerSeed- The number of local artists to include per seed artist.useSeedSong- Whether to include a song from the seed artist.- Returns:
- The created playlist.
-
savePlaylistToUser
Saves a playlist to a user's city.- Parameters:
userCity- The user city.playlist- The playlist.- Returns:
- The updated user city.
-
makeUserPlaylist
@Transactional(propagation=REQUIRES_NEW) public Playlist makeUserPlaylist(List<RecommendedArtistDto> rec, UUID userId, UUID cityId, List<Song> heavyRotation, int localPerSeed, boolean useSeedSong) Creates a playlist for a user for a city.- Parameters:
rec- The list of recommended artist DTOs.userId- The ID of the user.cityId- The ID of the city.heavyRotation- A list of songs in heavy rotation.localPerSeed- The number of local artists to include per seed artist.useSeedSong- Whether to include a song from the seed artist.- Returns:
- The created playlist.
-
compareArtistsByNextEvent
public int compareArtistsByNextEvent(AbstractMap.SimpleEntry<Artist, Event> ae1, AbstractMap.SimpleEntry<Artist, Event> ae2) Compares two artist-event pairs by the event's start time.- Parameters:
ae1- The first artist-event pair.ae2- The second artist-event pair.- Returns:
- A negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
-
softShuffleByPopularityAndAdd
public void softShuffleByPopularityAndAdd(List<AbstractMap.SimpleEntry<Artist, Event>> artists, List<AbstractMap.SimpleEntry<Artist, Event>> artistsWithoutEvents) Soft-shuffles a list of artists without events by popularity and adds them to a list of artists with events.- Parameters:
artists- The list of artists with events.artistsWithoutEvents- The list of artists without events.
-
pickTopSongsMultinomial
Picks a number of top songs from a list using a multinomial distribution based on popularity.- Parameters:
songs- The list of songs.numSongs- The number of songs to pick.- Returns:
- A list of the selected songs.
-
makeCityPlaylist
Creates a playlist for a city.- Parameters:
cityId- The ID of the city.- Returns:
- The created playlist.
-
makeVenuePlaylist
Creates a playlist for a venue.- Parameters:
venueId- The ID of the venue.- Returns:
- The created playlist.
-