1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Proper handling of shared ranks everywhere

This commit is contained in:
Krateng 2019-03-14 11:07:20 +01:00
parent 8e37a902e5
commit 958337cadb
3 changed files with 276 additions and 260 deletions

View File

@ -464,12 +464,16 @@ def artistInfo(artist):
try:
c = [e for e in charts if e["artist"] == artist][0]
others = coa.getAllAssociated(artist)
return {"scrobbles":scrobbles,"position":charts.index(c) + 1,"associated":others}
position = charts.index(c)
while position != 0 and c["scrobbles"] == charts[position-1]["scrobbles"]: position -= 1
return {"scrobbles":scrobbles,"position":position + 1,"associated":others}
except:
# if the artist isnt in the charts, they are not being credited and we need to show information about the credited one
artist = coa.getCredited(artist)
c = [e for e in charts if e["artist"] == artist][0]
return {"replace":artist,"scrobbles":scrobbles,"position":charts.index(c) + 1}
position = charts.index(c)
while position != 0 and c["scrobbles"] == charts[position-1]["scrobbles"]: position -= 1
return {"replace":artist,"scrobbles":scrobbles,"position":position + 1}
@ -486,10 +490,13 @@ def trackInfo_external():
def trackInfo(artists,title):
charts = db_aggregate(by="TRACK")
scrobbles = len(db_query(artists=artists,title=title)) #we cant take the scrobble number from the charts because that includes all countas scrobbles
#scrobbles = len(db_query(artists=artists,title=title)) #chart entry of track always has right scrobble number, no countas rules here
c = [e for e in charts if set(e["track"]["artists"]) == set(artists) and e["track"]["title"] == title][0]
return {"scrobbles":scrobbles,"position":charts.index(c) + 1}
scrobbles = c["scrobbles"]
position = charts.index(c)
while position != 0 and c["scrobbles"] == charts[position-1]["scrobbles"]: position -= 1
return {"scrobbles":scrobbles,"position":position + 1}
@ -669,6 +676,7 @@ def rebuild():
global db_rulestate
db_rulestate = False
sync()
invalidate_caches()
os.system("python3 fixexisting.py")
global cla, coa
cla = CleanerAgent()
@ -841,8 +849,10 @@ def invalidate_caches():
global cacheday
cacheday = (now.year,now.month,now.day)
log("Database caches invalidated.")
def check_cache_age():
now = datetime.datetime.now()
now = datetime.datetime.utcnow()
global cacheday
if cacheday != (now.year,now.month,now.day): invalidate_caches()

View File

@ -112,12 +112,16 @@ def module_trackcharts(max_=None,**kwargs):
if max_ is not None and i>max_:
break
html += "<tr>"
if i == 1 or e["scrobbles"] < prev["scrobbles"]:
html += "<td class='rank'>#" + str(i) + "</td>"
else:
html += "<td class='rank'></td>"
html += "<td class='artists'>" + artistLinks(e["track"]["artists"]) + "</td>"
html += "<td class='title'>" + trackLink(e["track"]) + "</td>"
html += "<td class='amount'>" + scrobblesTrackLink(e["track"],kwargs_time,amount=e["scrobbles"]) + "</td>"
html += "<td class='bar'>" + scrobblesTrackLink(e["track"],kwargs_time,percent=e["scrobbles"]*100/maxbar) + "</td>"
html += "</tr>"
prev = e
html += "</table>"
return (html,representative)
@ -144,7 +148,10 @@ def module_artistcharts(max_=None,**kwargs):
if max_ is not None and i>max_:
break
html += "<tr>"
if i == 1 or e["scrobbles"] < prev["scrobbles"]:
html += "<td class='rank'>#" + str(i) + "</td>"
else:
html += "<td class='rank'></td>"
html += "<td class='artist'>" + artistLink(e["artist"])
if (e["counting"] != []):
html += " <span class='extra'>incl. " + ", ".join([artistLink(a) for a in e["counting"]]) + "</span>"
@ -152,6 +159,7 @@ def module_artistcharts(max_=None,**kwargs):
html += "<td class='amount'>" + scrobblesArtistLink(e["artist"],kwargs_time,amount=e["scrobbles"],associated=True) + "</td>"
html += "<td class='bar'>" + scrobblesArtistLink(e["artist"],kwargs_time,percent=e["scrobbles"]*100/maxbar,associated=True) + "</td>"
html += "</tr>"
prev = e
html += "</table>"
@ -266,4 +274,3 @@ def module_trackcharts_tiles(**kwargs):
html += """</tr></table>"""
return html

View File

@ -67,8 +67,6 @@ def database_post(pth):
response.status = e.code
return
return
@ -176,4 +174,5 @@ setproctitle.setproctitle("Maloja")
## start database server
_thread.start_new_thread(SourceFileLoader("database","database.py").load_module().runserver,(DATABASE_PORT,))
log("Starting up Maloja server...")
run(webserver, host='::', port=MAIN_PORT, server='waitress')