예제 #1
0
        private void GenerateTree(String artistName)
        {
            //Going to separate artists based on the genres used to describe them.
            //Assume that the first artist is what we're pivoting on.

            if (NodeDictionary.ContainsKey(artistName))
            {
                return;
            }

            ArtistList rootArtistList = Client.GetArtist(artistName);

            //TODO: Using the first one for now.  Since there could be multiple roots, we'll need to handle this.
            Artist          rootArtist    = rootArtistList.Artists.Items[0];
            ArtistViewModel rootViewModel = new ArtistViewModel(rootArtist);
            HierarchyNode   root          = new HierarchyNode(rootViewModel, null, 0);

            RootNodes.Add(root);
            rootViewModel.SetHierarchyNode(root);
            NodeDictionary.Add(rootArtist.Name, root);

            ArtistGroup relatedArtistList = Client.GetRelatedArtists(rootArtist.ID);

            //First determine which artists are new; add those.
            List <Artist> newArtists = new List <Artist>();
            int           nodesAdded = 0;

            foreach (Artist relatedArtist in relatedArtistList.Artists)
            {
                if (NodeDictionary.ContainsKey(relatedArtist.Name))
                {
                    continue;
                }

                if (nodesAdded < MaxChildren)
                {
                    newArtists.Add(relatedArtist);

                    ArtistViewModel artistViewModel   = new ArtistViewModel(relatedArtist);
                    HierarchyNode   relatedArtistNode = new HierarchyNode(artistViewModel, root, 1);
                    root.Children.Add(relatedArtistNode);
                    artistViewModel.SetHierarchyNode(relatedArtistNode);
                    NodeDictionary.Add(relatedArtist.Name, relatedArtistNode);

                    nodesAdded++;
                }
                else
                {
                    break;
                }
            }
        }
예제 #2
0
        public Artist Recommend(SpotifyClient client, Playlist playlist)
        {
            //Find a common ancestor for a portion of the artists in the playlist.
            IEnumerable<Track> playlistEntries = playlist.Tracks.Select(track => track.Track);

            Dictionary<string, ArtistGroup> cachedRelatedArtists = new Dictionary<string, ArtistGroup>();

            Dictionary<string, RecommendationCriteria> relatedArtistMap = new Dictionary<string, RecommendationCriteria>();
            playlistEntries.ToList().ForEach(track =>
            {
                ArtistGroup relatedArtists = null;
                if (!cachedRelatedArtists.ContainsKey(track.Artists.First().ID))
                {
                    relatedArtists = client.GetRelatedArtists(track.Artists.First().ID); //Handle only the first artist for now...
                    cachedRelatedArtists.Add(track.Artists.First().ID, relatedArtists);
                }
                else
                {
                    relatedArtists = cachedRelatedArtists[track.Artists.First().ID];
                }

                relatedArtists.Artists.ForEach(relatedArtist =>
                {
                    if (!relatedArtistMap.ContainsKey(relatedArtist.ID))
                    {
                        RecommendationCriteria recommendationCriteria = new RecommendationCriteria();
                        relatedArtistMap.Add(relatedArtist.ID, recommendationCriteria);
                        recommendationCriteria.TargetedArtist = relatedArtist;
                    }

                    if (!relatedArtistMap[relatedArtist.ID].RelatedArtists.Where(artist => artist.ID == track.Artists.First().ID).Any())
                        relatedArtistMap[relatedArtist.ID].RelatedArtists.Add(track.Artists.First());

                    relatedArtistMap[relatedArtist.ID].Weight++;
                });
            });

            //Other ideas:
            //Recommend by the playlist contents.
            //  Evaluate whether the playlist is a collection of like-artists or individual songs of a particular type (e.g. energetic, fast?)
            //Recommend by the artist selected.
            //
            //Recommend something completely new.  
            //Recommend a set of brand-new songs.
            //  Analyze all changelists to get an idea of what a person likes in particular.  
            //  Easily solution is to find artists that they don't have that are similar.
            //  Could also randomly find songs from various areas:
            //      The current Top 10-40 on the charts.
            //      The list of a band that is playing near you live.
            //      Find a whole smattering of a different genre (trip hop, hip hop, grunge alternative).
            //Recommend by a specific song.
            //      Find songs that were popular at the same time (may not need to be part of the same genre).

            IOrderedEnumerable<KeyValuePair<string, RecommendationCriteria>> orderedDictionary = relatedArtistMap.OrderByDescending(keyValuePair => keyValuePair.Value.Weight)
                                                                                                                    .ThenByDescending(keyValuePair => keyValuePair.Value.RelatedArtists.Count());
            KeyValuePair<string, RecommendationCriteria> recommendedEntry = orderedDictionary.First();
            return recommendedEntry.Value.TargetedArtist;
        }
예제 #3
0
        public Artist Recommend(SpotifyClient client, Playlist playlist)
        {
            //Find a common ancestor for a portion of the artists in the playlist.
            IEnumerable <Track> playlistEntries = playlist.Tracks.Select(track => track.Track);

            Dictionary <string, ArtistGroup> cachedRelatedArtists = new Dictionary <string, ArtistGroup>();

            Dictionary <string, RecommendationCriteria> relatedArtistMap = new Dictionary <string, RecommendationCriteria>();

            playlistEntries.ToList().ForEach(track =>
            {
                ArtistGroup relatedArtists = null;
                if (!cachedRelatedArtists.ContainsKey(track.Artists.First().ID))
                {
                    relatedArtists = client.GetRelatedArtists(track.Artists.First().ID); //Handle only the first artist for now...
                    cachedRelatedArtists.Add(track.Artists.First().ID, relatedArtists);
                }
                else
                {
                    relatedArtists = cachedRelatedArtists[track.Artists.First().ID];
                }

                relatedArtists.Artists.ForEach(relatedArtist =>
                {
                    if (!relatedArtistMap.ContainsKey(relatedArtist.ID))
                    {
                        RecommendationCriteria recommendationCriteria = new RecommendationCriteria();
                        relatedArtistMap.Add(relatedArtist.ID, recommendationCriteria);
                        recommendationCriteria.TargetedArtist = relatedArtist;
                    }

                    if (!relatedArtistMap[relatedArtist.ID].RelatedArtists.Where(artist => artist.ID == track.Artists.First().ID).Any())
                    {
                        relatedArtistMap[relatedArtist.ID].RelatedArtists.Add(track.Artists.First());
                    }

                    relatedArtistMap[relatedArtist.ID].Weight++;
                });
            });

            //Other ideas:
            //Recommend by the playlist contents.
            //  Evaluate whether the playlist is a collection of like-artists or individual songs of a particular type (e.g. energetic, fast?)
            //Recommend by the artist selected.
            //
            //Recommend something completely new.
            //Recommend a set of brand-new songs.
            //  Analyze all changelists to get an idea of what a person likes in particular.
            //  Easily solution is to find artists that they don't have that are similar.
            //  Could also randomly find songs from various areas:
            //      The current Top 10-40 on the charts.
            //      The list of a band that is playing near you live.
            //      Find a whole smattering of a different genre (trip hop, hip hop, grunge alternative).
            //Recommend by a specific song.
            //      Find songs that were popular at the same time (may not need to be part of the same genre).

            IOrderedEnumerable <KeyValuePair <string, RecommendationCriteria> > orderedDictionary = relatedArtistMap.OrderByDescending(keyValuePair => keyValuePair.Value.Weight)
                                                                                                    .ThenByDescending(keyValuePair => keyValuePair.Value.RelatedArtists.Count());
            KeyValuePair <string, RecommendationCriteria> recommendedEntry = orderedDictionary.First();

            return(recommendedEntry.Value.TargetedArtist);
        }