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:
parent
8e37a902e5
commit
958337cadb
22
database.py
22
database.py
@ -464,12 +464,16 @@ def artistInfo(artist):
|
|||||||
try:
|
try:
|
||||||
c = [e for e in charts if e["artist"] == artist][0]
|
c = [e for e in charts if e["artist"] == artist][0]
|
||||||
others = coa.getAllAssociated(artist)
|
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:
|
except:
|
||||||
# if the artist isnt in the charts, they are not being credited and we need to show information about the credited one
|
# 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)
|
artist = coa.getCredited(artist)
|
||||||
c = [e for e in charts if e["artist"] == artist][0]
|
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):
|
def trackInfo(artists,title):
|
||||||
charts = db_aggregate(by="TRACK")
|
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]
|
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
|
global db_rulestate
|
||||||
db_rulestate = False
|
db_rulestate = False
|
||||||
sync()
|
sync()
|
||||||
|
invalidate_caches()
|
||||||
os.system("python3 fixexisting.py")
|
os.system("python3 fixexisting.py")
|
||||||
global cla, coa
|
global cla, coa
|
||||||
cla = CleanerAgent()
|
cla = CleanerAgent()
|
||||||
@ -841,8 +849,10 @@ def invalidate_caches():
|
|||||||
global cacheday
|
global cacheday
|
||||||
cacheday = (now.year,now.month,now.day)
|
cacheday = (now.year,now.month,now.day)
|
||||||
|
|
||||||
|
log("Database caches invalidated.")
|
||||||
|
|
||||||
def check_cache_age():
|
def check_cache_age():
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.utcnow()
|
||||||
global cacheday
|
global cacheday
|
||||||
if cacheday != (now.year,now.month,now.day): invalidate_caches()
|
if cacheday != (now.year,now.month,now.day): invalidate_caches()
|
||||||
|
|
||||||
|
@ -112,12 +112,16 @@ def module_trackcharts(max_=None,**kwargs):
|
|||||||
if max_ is not None and i>max_:
|
if max_ is not None and i>max_:
|
||||||
break
|
break
|
||||||
html += "<tr>"
|
html += "<tr>"
|
||||||
html += "<td class='rank'>#" + str(i) + "</td>"
|
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='artists'>" + artistLinks(e["track"]["artists"]) + "</td>"
|
||||||
html += "<td class='title'>" + trackLink(e["track"]) + "</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='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 += "<td class='bar'>" + scrobblesTrackLink(e["track"],kwargs_time,percent=e["scrobbles"]*100/maxbar) + "</td>"
|
||||||
html += "</tr>"
|
html += "</tr>"
|
||||||
|
prev = e
|
||||||
html += "</table>"
|
html += "</table>"
|
||||||
|
|
||||||
return (html,representative)
|
return (html,representative)
|
||||||
@ -144,7 +148,10 @@ def module_artistcharts(max_=None,**kwargs):
|
|||||||
if max_ is not None and i>max_:
|
if max_ is not None and i>max_:
|
||||||
break
|
break
|
||||||
html += "<tr>"
|
html += "<tr>"
|
||||||
html += "<td class='rank'>#" + str(i) + "</td>"
|
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"])
|
html += "<td class='artist'>" + artistLink(e["artist"])
|
||||||
if (e["counting"] != []):
|
if (e["counting"] != []):
|
||||||
html += " <span class='extra'>incl. " + ", ".join([artistLink(a) for a in e["counting"]]) + "</span>"
|
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='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 += "<td class='bar'>" + scrobblesArtistLink(e["artist"],kwargs_time,percent=e["scrobbles"]*100/maxbar,associated=True) + "</td>"
|
||||||
html += "</tr>"
|
html += "</tr>"
|
||||||
|
prev = e
|
||||||
|
|
||||||
html += "</table>"
|
html += "</table>"
|
||||||
|
|
||||||
@ -266,4 +274,3 @@ def module_trackcharts_tiles(**kwargs):
|
|||||||
html += """</tr></table>"""
|
html += """</tr></table>"""
|
||||||
|
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
@ -67,8 +67,6 @@ def database_post(pth):
|
|||||||
response.status = e.code
|
response.status = e.code
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
@ -176,4 +174,5 @@ setproctitle.setproctitle("Maloja")
|
|||||||
## start database server
|
## start database server
|
||||||
_thread.start_new_thread(SourceFileLoader("database","database.py").load_module().runserver,(DATABASE_PORT,))
|
_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')
|
run(webserver, host='::', port=MAIN_PORT, server='waitress')
|
||||||
|
Loading…
Reference in New Issue
Block a user