~ubuntu-branches/ubuntu/precise/rhythmbox/precise-201203091205

« back to all changes in this revision

Viewing changes to shell/rb-play-order-random-by-age-and-rating.c

Tags: upstream-0.9.5
ImportĀ upstreamĀ versionĀ 0.9.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 *
16
16
 *  You should have received a copy of the GNU General Public License
17
17
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
19
19
 *
20
20
 */
21
21
 
64
64
rb_random_by_age_and_rating_get_entry_weight (RBRandomPlayOrder *rorder, RhythmDB *db, RhythmDBEntry *entry)
65
65
{
66
66
        time_t now;
67
 
        glong last_play;
68
 
        glong seconds_since_last_play;
 
67
        gulong last_play;
 
68
        gulong seconds_since_last_play;
69
69
        gdouble rating;
70
70
 
71
71
        /* This finds the log of the number of seconds since the last play.
72
72
         * It handles never played automatically, since now-0 is a valid
73
73
         * argument to log(). */
74
74
        time (&now);
75
 
        last_play = entry->last_played;
 
75
        last_play = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_LAST_PLAYED);
76
76
        seconds_since_last_play = now - last_play;
77
77
        /* The lowest weight should be 0. */
78
78
        if (seconds_since_last_play < 1)
79
79
                seconds_since_last_play = 1;
80
80
 
81
 
        if (entry->rating > 0.01)
82
 
                rating = entry->rating;
83
 
        else
 
81
        rating = rhythmdb_entry_get_double (entry, RHYTHMDB_PROP_RATING);
 
82
 
 
83
        /* treat unrated as 2.5 for the purposes of probabilities */
 
84
        if (rating < 0.01)
84
85
                rating = 2.5;
85
86
 
86
87
        return log (seconds_since_last_play) * (rating + 1.0);