~ubuntu-branches/ubuntu/vivid/banshee-community-extensions/vivid

« back to all changes in this revision

Viewing changes to src/Mirage/Banshee.Mirage/RandomBySimilar.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2010-11-24 14:59:52 UTC
  • Revision ID: james.westby@ubuntu.com-20101124145952-6xcdipawrpnn00n0
Tags: 1.9.0-1ubuntu2
* [5c94c08] Disable OpenVP extension temporarily.
* [609c47e] Enable Ubuntu One Music Store by default
* [6d26f8b] Fix build with new RandomBy APIs included in git snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
        // The RANDOM_CONDITION will exclude the played/skipped items for us, but we need to
48
48
        // add the Similarity-based selection[, exclusion], and ordering.
49
49
 
50
 
        private string cache_condition;
51
 
 
52
50
        public RandomBySimilar () : base ("mirage_similar")
53
51
        {
54
52
            MiragePlugin.Init ();
58
56
            Description = AddinManager.CurrentLocalizer.GetString ("Play songs similar to those already played");
59
57
 
60
58
            // TODO Mirage's PlaylistGeneratorSource ensures no more than 50% of tracks are by same artist
 
59
            Select = ", HYENA_BINARY_FUNCTION ('MIRAGE_DISTANCE', ?, mirage.ScmsData) as Distance";
 
60
            From = "LEFT OUTER JOIN MirageTrackAnalysis mirage ON (mirage.TrackID = CoreTracks.TrackID) ";
61
61
            Condition = "mirage.Status = 0 AND CoreTracks.ArtistID NOT IN (?) AND Distance > 0";
62
 
            From = "LEFT OUTER JOIN MirageTrackAnalysis mirage ON (mirage.TrackID = CoreTracks.TrackID) ";
63
 
            Select = ", HYENA_BINARY_FUNCTION ('MIRAGE_DISTANCE', ?, mirage.ScmsData) as Distance";
64
62
            OrderBy = "Distance ASC, RANDOM ()";
65
63
 
66
 
            cache_condition = String.Format ("AND {0} {1} ORDER BY {2}", Condition, RANDOM_CONDITION, OrderBy);
67
64
        }
68
65
 
69
66
        public override bool Next (DateTime after)
71
68
            return true;
72
69
        }
73
70
 
74
 
        public override TrackInfo GetPlaybackTrack (DateTime after)
75
 
        {
76
 
            return GetTrack (after, true);
77
 
        }
78
 
 
79
 
        public override DatabaseTrackInfo GetShufflerTrack (DateTime after)
80
 
        {
81
 
            return GetTrack (after, false);
82
 
        }
83
 
 
84
 
        private DatabaseTrackInfo GetTrack (DateTime after, bool playback)
85
 
        {
86
 
            using (var context = GetSimilarityContext (after, playback)) {
87
 
                var track = playback
88
 
                    ? Cache.GetSingle (Select, From, cache_condition, context.Id, context.AvoidArtistIds, after, after) as DatabaseTrackInfo
89
 
                    : GetTrack (ShufflerQuery, context.Id, context.AvoidArtistIds, after) as DatabaseTrackInfo;
90
 
 
91
 
                if (MiragePlugin.Debug) {
92
 
                    Console.WriteLine ("Mirage got {0} as lowest avg distance to the similarity context", track == null ? "(null)" : track.Uri.ToString ());
93
 
                    context.DumpDebug ();
94
 
                }
95
 
                return track;
96
 
            }
 
71
        protected override RandomBy.QueryContext GetQueryContext (DateTime after)
 
72
        {
 
73
            return GetSimilarityContext (after, Shuffler == Shuffler.Playback);
97
74
        }
98
75
 
99
76
        private SimilarityContext GetSimilarityContext (DateTime after, bool playback)
101
78
            var context = new SimilarityContext ();
102
79
 
103
80
            if (!playback) {
104
 
                // Manually added songs are the strongest postiive signal for what we want
 
81
                // Manually added songs are the strongest postive signal for what we want
105
82
                context.AddSeeds (GetSeeds (
106
83
                    "d.ModificationType = 1 AND d.LastModifiedAt IS NOT NULL AND d.LastModifiedAt > ? ORDER BY d.LastModifiedAt DESC",
107
84
                    after, 4, SimilarityContext.SelectedWeight
108
85
                ));
109
86
            }
110
87
 
111
 
            // Played songs are the next strongest postiive signal for what we want
 
88
            // Played songs are the next strongest postive signal for what we want
112
89
            context.AddSeeds (GetSeeds (
113
90
                "t.LastPlayedStamp IS NOT NULL AND t.LastPlayedStamp > MAX (?, coalesce(d.LastModifiedAt, 0), coalesce(t.LastSkippedStamp, 0)) ORDER BY t.LastPlayedStamp DESC",
114
91
                after, playback ? 4 : 2, SimilarityContext.PlayedWeight