Score system
The score system will help determine what users do and don't like. When the user chooses a song or listens to > 75% of a song, we increment the score. If the user selects a different song in the first 1/3 of playback then we decrement the score. Songs with a score >= 0 will always be played. Songs with a score < 0 have a 50% chance of playing.
This commit is contained in:
parent
5835f55eb2
commit
50f7e1203d
|
@ -48,6 +48,13 @@ def lib_inc_count(id):
|
||||||
global library
|
global library
|
||||||
if id >= 0:
|
if id >= 0:
|
||||||
library.inc_count(id)
|
library.inc_count(id)
|
||||||
|
library.save()
|
||||||
|
|
||||||
|
def lib_inc_score(id, amount=1):
|
||||||
|
global library
|
||||||
|
if id >= 0:
|
||||||
|
library.inc_score(id, amount)
|
||||||
|
library.save()
|
||||||
|
|
||||||
def lib_play_id(id):
|
def lib_play_id(id):
|
||||||
global cur_lib_id
|
global cur_lib_id
|
||||||
|
@ -116,13 +123,21 @@ def choose_next():
|
||||||
if next != None:
|
if next != None:
|
||||||
return call("NEXT", lib_play_id, next)
|
return call("NEXT", lib_play_id, next)
|
||||||
|
|
||||||
def plist_next():
|
def change_score():
|
||||||
prcnt = libsaria.music.get_progress()
|
prcnt = libsaria.music.get_progress()
|
||||||
if prcnt > 75:
|
if prcnt > 0.75:
|
||||||
lib_inc_count(cur_lib_id)
|
lib_inc_count(cur_lib_id)
|
||||||
|
lib_inc_score(cur_lib_id)
|
||||||
|
if prcnt < 0.33:
|
||||||
|
lib_inc_score(cur_lib_id, -1)
|
||||||
|
|
||||||
|
def plist_next():
|
||||||
|
change_score()
|
||||||
|
choose_next()
|
||||||
|
|
||||||
def catch_eos(arg=None):
|
def catch_eos(arg=None):
|
||||||
lib_inc_count(cur_lib_id)
|
lib_inc_count(cur_lib_id)
|
||||||
|
lib_inc_score(cur_lib_id)
|
||||||
choose_next()
|
choose_next()
|
||||||
libsaria.event.invite("POSTEOS", catch_eos)
|
libsaria.event.invite("POSTEOS", catch_eos)
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ class TrackRecord:
|
||||||
self.lenstr = lenstr
|
self.lenstr = lenstr
|
||||||
self.count = 0
|
self.count = 0
|
||||||
self.year = year
|
self.year = year
|
||||||
#self.like = None
|
self.score = 0
|
||||||
|
|
||||||
self.fs = None
|
self.fs = None
|
||||||
self.tags = None
|
self.tags = None
|
||||||
|
@ -112,6 +112,8 @@ class Collection:
|
||||||
return rec.year
|
return rec.year
|
||||||
if attr == "lenstr":
|
if attr == "lenstr":
|
||||||
return rec.lenstr
|
return rec.lenstr
|
||||||
|
if attr == "score":
|
||||||
|
return rec.score
|
||||||
|
|
||||||
tags = rec.tags.walk_backwards()
|
tags = rec.tags.walk_backwards()
|
||||||
if attr == "artist":
|
if attr == "artist":
|
||||||
|
|
|
@ -42,6 +42,11 @@ class Library(collection.Collection):
|
||||||
if rec:
|
if rec:
|
||||||
rec.count += 1
|
rec.count += 1
|
||||||
|
|
||||||
|
def inc_score(self, id, amount):
|
||||||
|
rec = self.records.get(id, None)
|
||||||
|
if rec:
|
||||||
|
rec.score += amount
|
||||||
|
|
||||||
def update(self, path):
|
def update(self, path):
|
||||||
global badfiles
|
global badfiles
|
||||||
FileRef = libsaria.collection.FileRef
|
FileRef = libsaria.collection.FileRef
|
||||||
|
@ -86,6 +91,19 @@ class Playlist(collection.Collection):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def random(self):
|
def random(self):
|
||||||
|
if self.size == 0:
|
||||||
|
return
|
||||||
|
getattr = libsaria.collection.lib_get_attr
|
||||||
|
for i in xrange(5):
|
||||||
|
id = self.get_rand_candidate()
|
||||||
|
if getattr(id, "score") >= 0:
|
||||||
|
return id
|
||||||
|
play_anyway = rand.randint(0, 1)
|
||||||
|
if play_anyway == 1:
|
||||||
|
return id
|
||||||
|
return id
|
||||||
|
|
||||||
|
def get_rand_candidate(self):
|
||||||
num = self.num_visible()
|
num = self.num_visible()
|
||||||
next_idx = rand.randint(0, num-1)
|
next_idx = rand.randint(0, num-1)
|
||||||
func = self.visible
|
func = self.visible
|
||||||
|
|
|
@ -54,15 +54,14 @@ class Collection(gtk.ScrolledWindow):
|
||||||
row = row[0]
|
row = row[0]
|
||||||
list_iter = list.get_iter(row)
|
list_iter = list.get_iter(row)
|
||||||
list_row = list[list_iter]
|
list_row = list[list_iter]
|
||||||
string = self.mouse_motion(list_row)
|
items = self.mouse_motion(list_row)
|
||||||
list.set_value(list_iter, len(list_row)-1, "Played: %s"%string)
|
list.set_value(list_iter, len(list_row)-1,
|
||||||
|
"Played: %s Score: %s" % items)
|
||||||
|
|
||||||
def add_selected_to_playlist(self):
|
def add_selected_to_playlist(self):
|
||||||
print "adding selected to playlist"
|
|
||||||
self.list.for_each_selected(collection.plist_add_libid)
|
self.list.for_each_selected(collection.plist_add_libid)
|
||||||
collection.plist_save()
|
collection.plist_save()
|
||||||
collection.plist_refresh()
|
collection.plist_refresh()
|
||||||
print "done!"
|
|
||||||
|
|
||||||
|
|
||||||
class Library(Collection):
|
class Library(Collection):
|
||||||
|
@ -91,10 +90,13 @@ class Library(Collection):
|
||||||
self.populate()
|
self.populate()
|
||||||
|
|
||||||
def mouse_motion(self, row):
|
def mouse_motion(self, row):
|
||||||
return collection.lib_get_attr(row[0], "playcount")
|
return (collection.lib_get_attr(row[0], "playcount"),
|
||||||
|
collection.lib_get_attr(row[0], "score"))
|
||||||
|
|
||||||
def select_row(self, row):
|
def select_row(self, row):
|
||||||
|
collection.change_score()
|
||||||
collection.lib_play_id(row[0])
|
collection.lib_play_id(row[0])
|
||||||
|
collection.lib_inc_score(row[0], 1)
|
||||||
|
|
||||||
def filter(self, text):
|
def filter(self, text):
|
||||||
collection.lib_filter(text)
|
collection.lib_filter(text)
|
||||||
|
@ -128,10 +130,13 @@ class Playlist(Collection):
|
||||||
#print "Populating took: %s" % (after - before)
|
#print "Populating took: %s" % (after - before)
|
||||||
|
|
||||||
def mouse_motion(self, row):
|
def mouse_motion(self, row):
|
||||||
return collection.lib_get_attr(row[0], "playcount")
|
return (collection.lib_get_attr(row[0], "playcount"),
|
||||||
|
collection.lib_get_attr(row[0], "score"))
|
||||||
|
|
||||||
def select_row(self, row):
|
def select_row(self, row):
|
||||||
|
collection.change_score()
|
||||||
collection.lib_play_id(row[0])
|
collection.lib_play_id(row[0])
|
||||||
|
collection.lib_inc_score(row[0], 1)
|
||||||
|
|
||||||
def filter(self, text):
|
def filter(self, text):
|
||||||
collection.plist_filter(text)
|
collection.plist_filter(text)
|
||||||
|
|
Loading…
Reference in New Issue