banshee r5155 - in trunk/banshee: . src/Clients/Booter/Booter src/Core/Banshee.Core/Banshee.Collection src/Core/Banshee.Services/Banshee.Collection.Database src/Core/Banshee.Services/Banshee.Database src/Core/Banshee.Services/Banshee.MediaEngine src/Core/Banshee.Services/Banshee.Query src/Core/Banshee.Services/Banshee.SmartPlaylist src/Core/Banshee.ThickClient/Banshee.Collection.Gui src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data



Author: gburt
Date: Sat Mar 21 02:21:04 2009
New Revision: 5155
URL: http://svn.gnome.org/viewvc/banshee?rev=5155&view=rev

Log:
2009-03-20  Gabriel Burt  <gabriel burt gmail com>

	* src/Clients/Booter/Booter/Entry.cs:
	* src/Core/Banshee.Core/Banshee.Collection/TrackInfo.cs:
	* src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs:
	* src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs:
	* src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs:
	* src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs:
	* src/Core/Banshee.Services/Banshee.SmartPlaylist/Migrator.cs:
	* src/Core/Banshee.ThickClient/Banshee.Collection.Gui/DefaultColumnController.cs:
	* src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/StatisticsPage.cs:
	* src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmTrackInfo.cs:
	* src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackInfo.cs:
	Patch from Brian Lucas and Alexander Kojevnikov adding a score
	column/field that is updated automatically based on how far a song was
	played before it was skipped (or over).  It has a value of 0 to 100, where
	100 would mean that every time you played the song you listened to the
	whole thing (BGO #555116)

Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Clients/Booter/Booter/Entry.cs
   trunk/banshee/src/Core/Banshee.Core/Banshee.Collection/TrackInfo.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/Migrator.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/DefaultColumnController.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/StatisticsPage.cs
   trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmTrackInfo.cs
   trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackInfo.cs

Modified: trunk/banshee/src/Clients/Booter/Booter/Entry.cs
==============================================================================
--- trunk/banshee/src/Clients/Booter/Booter/Entry.cs	(original)
+++ trunk/banshee/src/Clients/Booter/Booter/Entry.cs	Sat Mar 21 02:21:04 2009
@@ -187,7 +187,8 @@
                     new LayoutOption ("query-track-count", Catalog.GetString ("Track Count")),
                     new LayoutOption ("query-disc", Catalog.GetString ("Disc Number")),
                     new LayoutOption ("query-year", Catalog.GetString ("Year")),
-                    new LayoutOption ("query-rating", Catalog.GetString ("Rating"))
+                    new LayoutOption ("query-rating", Catalog.GetString ("Rating")),
+                    new LayoutOption ("query-score", Catalog.GetString ("Score"))
                 ),
                 
                 new LayoutGroup ("ui", Catalog.GetString ("User Interface Options"),

Modified: trunk/banshee/src/Core/Banshee.Core/Banshee.Collection/TrackInfo.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Core/Banshee.Collection/TrackInfo.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Core/Banshee.Collection/TrackInfo.cs	Sat Mar 21 02:21:04 2009
@@ -59,7 +59,7 @@
         public delegate bool IsPlayingHandler (TrackInfo track);
         public static IsPlayingHandler IsPlayingMethod;
 
-        public delegate void PlaybackFinishedHandler (TrackInfo track, double percentComplete);
+        public delegate void PlaybackFinishedHandler (TrackInfo track, double percentCompleted);
         public static event PlaybackFinishedHandler PlaybackFinished;
 
         private SafeUri uri;
@@ -92,6 +92,7 @@
         private int disc_count;
         private int year;
         private int rating;
+        private int score;
         private int bpm;
         private int bit_rate;
 
@@ -111,25 +112,26 @@
         {
         }
 
-        public virtual void IncrementPlayCount ()
+        public virtual void OnPlaybackFinished (double percentCompleted)
         {
-            LastPlayed = DateTime.Now;
-            PlayCount++;
-            OnPlaybackFinished (1.0);
-        }
+            double total_plays = PlayCount + SkipCount;
+            if (total_plays <= 0) {
+                Score = (int) Math.Floor ((Score + (percentCompleted * 100)) / 2);
+            } else {
+                Score = (int) Math.Floor ((((double)Score * total_plays) + (percentCompleted * 100)) / (total_plays + 1));
+            }
 
-        public virtual void IncrementSkipCount ()
-        {
-            LastSkipped = DateTime.Now;
-            SkipCount++;
-            OnPlaybackFinished (0.0);
-        }
+            if (percentCompleted <= 0.5) {
+                LastSkipped = DateTime.Now;
+                SkipCount++;
+            } else {
+                LastPlayed = DateTime.Now;
+                PlayCount++;
+            }
 
-        private void OnPlaybackFinished (double percentComplete)
-        {
             PlaybackFinishedHandler handler = PlaybackFinished;
             if (handler != null) {
-                handler (this, percentComplete);
+                handler (this, percentCompleted);
             }
         }
 
@@ -393,6 +395,12 @@
         }
         
         [Exportable]
+        public virtual int Score {
+            get { return score; }
+            set {score = value; }
+        }
+
+        [Exportable]
         public virtual int Bpm {
             get { return bpm; }
             set { bpm = value; }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Collection.Database/DatabaseTrackInfo.cs	Sat Mar 21 02:21:04 2009
@@ -78,19 +78,12 @@
             Provider.Copy (original, this);
         }
 
-        public override void IncrementPlayCount ()
+        public override void OnPlaybackFinished (double percentCompleted)
         {
-            if (ProviderRefresh ()) {
-                base.IncrementPlayCount ();
-                Save (true, BansheeQuery.PlayCountField, BansheeQuery.LastPlayedField);
-            }
-        }
-
-        public override void IncrementSkipCount ()
-        {
-            if (ProviderRefresh ()) {
-                base.IncrementSkipCount ();
-                Save (true, BansheeQuery.SkipCountField, BansheeQuery.LastSkippedField);
+            if (ProviderRefresh()) {
+                base.OnPlaybackFinished (percentCompleted);
+                Save (true, BansheeQuery.ScoreField, BansheeQuery.SkipCountField, BansheeQuery.LastSkippedField, 
+                    BansheeQuery.PlayCountField, BansheeQuery.LastPlayedField);
             }
         }
 
@@ -568,6 +561,12 @@
             set { rating = value; }
         }
 
+        [DatabaseColumn]
+        public override int Score {
+            get { return base.Score; }
+            set { base.Score = value; }
+        }
+
         public int SavedRating {
             get { return rating; }
             set {

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs	Sat Mar 21 02:21:04 2009
@@ -52,7 +52,7 @@
         // NOTE: Whenever there is a change in ANY of the database schema,
         //       this version MUST be incremented and a migration method
         //       MUST be supplied to match the new version number
-        protected const int CURRENT_VERSION = 28;
+        protected const int CURRENT_VERSION = 29;
         protected const int CURRENT_METADATA_VERSION = 5;
         
 #region Migration Driver
@@ -640,7 +640,7 @@
 
             return true;
         }
-        
+
 #endregion
 
 #region Version 28
@@ -661,6 +661,22 @@
 
 #endregion
 
+#region Version 29
+
+        [DatabaseVersion (29)]
+        private bool Migrate_29 ()
+        {
+            Execute ("ALTER TABLE CoreTracks ADD COLUMN Score INTEGER DEFAULT 0");
+            Execute (@"
+                UPDATE CoreTracks
+                SET Score = CAST(ROUND(100.00 * PlayCount / (PlayCount + SkipCount)) AS INTEGER)
+                WHERE PlayCount + SkipCount > 0
+            ");
+            return true;
+        }
+
+#endregion
+
 #pragma warning restore 0169
         
 #region Fresh database setup
@@ -742,6 +758,7 @@
 
                     Comment             TEXT,
                     Rating              INTEGER,
+                    Score               INTEGER,
                     PlayCount           INTEGER,
                     SkipCount           INTEGER,
                     LastPlayedStamp     INTEGER,
@@ -925,6 +942,7 @@
                         Genre,
                         NULL, NULL, NULL, NULL, NULL, NULL,
                         Rating,
+                        0,
                         NumberOfPlays,
                         0,
                         LastPlayedStamp,

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs	Sat Mar 21 02:21:04 2009
@@ -337,12 +337,11 @@
         public void IncrementLastPlayed ()
         {
             if (!incremented_last_played && CurrentTrack != null && CurrentTrack.PlaybackError == StreamPlaybackError.None) {
-                // If we're at least 50% done playing a song, mark it as played, otherwise as skipped
-                // If the Length <= 0, assume the song was finished and increment its play count
-                if (active_engine.Length <= 0 || active_engine.Position >= active_engine.Length / 2) {
-                    CurrentTrack.IncrementPlayCount ();
+                //if Length <= 0 assume 100% completion:
+                if (active_engine.Length <= 0) {
+                    CurrentTrack.OnPlaybackFinished (1);
                 } else {
-                    CurrentTrack.IncrementSkipCount ();
+                    CurrentTrack.OnPlaybackFinished ((double)active_engine.Position / (double)active_engine.Length);
                 }
                 incremented_last_played = true;
             }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Query/BansheeQuery.cs	Sat Mar 21 02:21:04 2009
@@ -69,6 +69,9 @@
             CreateQueryOrder ("Rating",     desc, Catalog.GetString ("Highest Rating"), RatingField),
             CreateQueryOrder ("Rating",     asc,  Catalog.GetString ("Lowest Rating"), RatingField),
             null,
+            CreateQueryOrder ("Score",      desc, Catalog.GetString ("Highest Score"), ScoreField),
+            CreateQueryOrder ("Score",      asc,  Catalog.GetString ("Lowest Score"), ScoreField),
+            null,
             CreateQueryOrder ("PlayCount",  desc, Catalog.GetString ("Most Often Played"), PlayCountField),
             CreateQueryOrder ("PlayCount",  asc,  Catalog.GetString ("Least Often Played"), PlayCountField),
             null,
@@ -318,6 +321,14 @@
             "CoreTracks.TrackID {2} IN (SELECT TrackID FROM CoreSmartPlaylistEntries WHERE SmartPlaylistID = {1})", typeof(SmartPlaylistQueryValue),
             "smartplaylistid", "smartplaylist"
         );
+
+        public static QueryField ScoreField = new QueryField (
+            "score", "Score",
+            Catalog.GetString ("Score"), "CoreTracks.Score", typeof(IntegerQueryValue),
+            //Translators: These are unique search fields (and nouns). Please, no spaces. Blank ok.
+            Catalog.GetString ("score"),
+            "score"
+        );
         
 #endregion
 
@@ -325,7 +336,7 @@
             ArtistField, AlbumField, AlbumArtistField, TitleField, TrackNumberField, TrackCountField, DiscNumberField, DiscCountField,
             YearField, GenreField, ComposerField, ConductorField, GroupingField, CommentField, LicenseUriField, RatingField, PlayCountField,
             SkipCountField, FileSizeField, UriField, DurationField, MimeTypeField, LastPlayedField, LastSkippedField,
-            BpmField, BitRateField, DateAddedField, PlaylistField, SmartPlaylistField
+            BpmField, BitRateField, DateAddedField, PlaylistField, SmartPlaylistField, ScoreField
         );
 
         // Type Initializer
@@ -428,6 +439,7 @@
                 case "disccount":
                 case "duration":
                 case "rating":
+                case "score":
                 case "playcount":
                 case "skipcount":
                 case "filesize":

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/Migrator.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/Migrator.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.SmartPlaylist/Migrator.cs	Sat Mar 21 02:21:04 2009
@@ -92,6 +92,8 @@
             order_hash.Add ("Title",                BansheeQuery.FindOrder ("Title", true));
             order_hash.Add ("Rating DESC",          BansheeQuery.FindOrder ("Rating", false));
             order_hash.Add ("Rating ASC",           BansheeQuery.FindOrder ("Rating", true));
+            order_hash.Add ("Score DESC",           BansheeQuery.FindOrder ("Score", false));
+            order_hash.Add ("Score ASC",            BansheeQuery.FindOrder ("Score", true));
             order_hash.Add ("NumberOfPlays DESC",   BansheeQuery.FindOrder ("PlayCount", false));
             order_hash.Add ("NumberOfPlays ASC",    BansheeQuery.FindOrder ("PlayCount", true));
             order_hash.Add ("DateAddedStamp DESC",  BansheeQuery.FindOrder ("DateAddedStamp", false));

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/DefaultColumnController.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/DefaultColumnController.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/DefaultColumnController.cs	Sat Mar 21 02:21:04 2009
@@ -72,6 +72,7 @@
                 AlbumColumn,
                 CommentColumn,
                 RatingColumn,
+                ScoreColumn,
                 DurationColumn,
                 GenreColumn,
                 YearColumn,
@@ -132,6 +133,7 @@
             bitrate_column      = Create (BansheeQuery.BitRateField, 0.10, false, br_cell);
             
             rating_column       = Create (BansheeQuery.RatingField, 0.15, false, new ColumnCellRating (null, true));
+            score_column        = Create (BansheeQuery.ScoreField, 0.15, false, new ColumnCellPositiveInt (null, true, 2, 5));
             composer_column     = CreateText (BansheeQuery.ComposerField, 0.25);
             conductor_column    = CreateText (BansheeQuery.ConductorField, 0.25);
             grouping_column     = CreateText (BansheeQuery.GroupingField, 0.25);
@@ -253,6 +255,11 @@
             get { return rating_column; }
         }
         
+        private SortableColumn score_column;
+        public SortableColumn ScoreColumn {
+            get { return score_column; }
+        }
+
         private SortableColumn last_played_column;
         public SortableColumn LastPlayedColumn {
             get { return last_played_column; }

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/StatisticsPage.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/StatisticsPage.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/StatisticsPage.cs	Sat Mar 21 02:21:04 2009
@@ -158,6 +158,7 @@
                 ? track.LastSkipped.ToString () : Catalog.GetString ("Unknown"));
             AddItem (Catalog.GetString ("Play Count:"), track.PlayCount);
             AddItem (Catalog.GetString ("Skip Count:"), track.SkipCount);
+            AddItem (Catalog.GetString ("Score:"), track.Score);
         }
         
         private void AddFileSizeItem (long bytes)

Modified: trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmTrackInfo.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmTrackInfo.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmTrackInfo.cs	Sat Mar 21 02:21:04 2009
@@ -80,16 +80,16 @@
             CanSaveToDatabase = false;
         }
 
-        public override void IncrementPlayCount ()
+        public override void OnPlaybackFinished (double percentCompleted)
         {
-            base.IncrementPlayCount ();
+            base.OnPlaybackFinished (percentCompleted);
 
             station.PlayCount++;
             station.Save ();
         }
 
-		public void Love () 
-		{
+        public void Love ()
+        {
             loved = true; hated = false;
             ThreadAssist.Spawn (delegate {
                 try {
@@ -98,10 +98,10 @@
                     Hyena.Log.Warning ("Got Exception Trying to Love Song", e.ToString (), false);
                 }
             });
-		}
+        }
 
-		public void Ban () 
-		{
+        public void Ban ()
+        {
             loved = false; hated = true;
             ThreadAssist.Spawn (delegate {
                 try {
@@ -110,6 +110,6 @@
                     Hyena.Log.Warning ("Got Exception Trying to Ban Song", e.ToString (), false);
                 }
             });
-		}
+        }
     }
 }

Modified: trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackInfo.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackInfo.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Podcasting/Banshee.Podcasting.Data/PodcastTrackInfo.cs	Sat Mar 21 02:21:04 2009
@@ -179,9 +179,9 @@
             TrackInfo.PlaybackFinished += OnPlaybackFinished;
         }
 
-        private static void OnPlaybackFinished (TrackInfo track, double percentComplete)
+        private static void OnPlaybackFinished (TrackInfo track, double percentCompleted)
         {
-            if (percentComplete > 0.5 && track.PlayCount > 0) {
+            if (percentCompleted > 0.5 && track.PlayCount > 0) {
                 PodcastTrackInfo pi = PodcastTrackInfo.From (track);
                 if (pi != null && !pi.Item.IsRead) {
                     pi.Item.IsRead = true;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]