From 7021099e7b9447730749e6e633a803deb95c5cdd Mon Sep 17 00:00:00 2001 From: krateng Date: Sun, 9 Jan 2022 01:14:06 +0100 Subject: [PATCH] Removed compare functionality --- maloja/database/__init__.py | 87 +------------------------ maloja/web/jinja/compare.jinja | 112 --------------------------------- 2 files changed, 1 insertion(+), 198 deletions(-) delete mode 100644 maloja/web/jinja/compare.jinja diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index 2bf9c4f..ba9bfa7 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -261,7 +261,7 @@ def artist_info(artist): - +@waitfordb def track_info(track): track = sqldb.get_track(sqldb.get_track_id(track)) @@ -294,91 +294,6 @@ def track_info(track): "topweeks":len([e for e in performance_weekly if e['rank'] == 1]) } -def tracks_info(tracks): - - tracks = [sqldb.get_track(sqldb.get_track_id(track)) for track in tracks] - alltimecharts = get_charts_tracks(timerange=alltime()) - - result = [] - for track in tracks: - c = [e for e in alltimecharts if e["track"] == track][0] - scrobbles = c["scrobbles"] - position = c["rank"] - cert = None - threshold_gold, threshold_platinum, threshold_diamond = malojaconfig["SCROBBLES_GOLD","SCROBBLES_PLATINUM","SCROBBLES_DIAMOND"] - if scrobbles >= threshold_diamond: cert = "diamond" - elif scrobbles >= threshold_platinum: cert = "platinum" - elif scrobbles >= threshold_gold: cert = "gold" - - performance_weekly = get_performance(track=track,step="week")[:-1] #current week doesn't count - performance_yearly = get_performance(track=track,step="year")[:-1] #current year doesn't count - - result.append({ - "track":track, - "scrobbles":scrobbles, - "position":position, - "medals":{ - "gold":[e['range'] for e in performance_yearly if e['rank'] == 1], - "silver":[e['range'] for e in performance_yearly if e['rank'] == 2], - "bronze":[e['range'] for e in performance_yearly if e['rank'] == 3] - }, - "certification":cert, - "topweeks":len([e for e in performance_weekly if e['rank'] == 1]) - }) - - return result - - -def compare(remoteurl): - import json - compareurl = remoteurl + "/api/info" - - response = urllib.request.urlopen(compareurl) - strangerinfo = json.loads(response.read()) - owninfo = info() - - #add_known_server(compareto) - - artists = {} - - for a in owninfo["artists"]: - artists[a.lower()] = {"name":a,"self":int(owninfo["artists"][a]*1000),"other":0} - - for a in strangerinfo["artists"]: - artists[a.lower()] = artists.setdefault(a.lower(),{"name":a,"self":0}) - artists[a.lower()]["other"] = int(strangerinfo["artists"][a]*1000) - - for a in artists: - common = min(artists[a]["self"],artists[a]["other"]) - artists[a]["self"] -= common - artists[a]["other"] -= common - artists[a]["common"] = common - - best = sorted((artists[a]["name"] for a in artists),key=lambda x: artists[x.lower()]["common"],reverse=True) - - result = { - "unique_self":sum(artists[a]["self"] for a in artists if artists[a]["common"] == 0), - "more_self":sum(artists[a]["self"] for a in artists if artists[a]["common"] != 0), - "common":sum(artists[a]["common"] for a in artists), - "more_other":sum(artists[a]["other"] for a in artists if artists[a]["common"] != 0), - "unique_other":sum(artists[a]["other"] for a in artists if artists[a]["common"] == 0) - } - - total = sum(result[c] for c in result) - - for r in result: - result[r] = (result[r],result[r]/total) - - - - return { - "result":result, - "info":{ - "ownname":owninfo["name"], - "remotename":strangerinfo["name"] - }, - "commonartist":best[0] - } def incoming_scrobble(artists,title,album=None,duration=None,time=None,fix=True): diff --git a/maloja/web/jinja/compare.jinja b/maloja/web/jinja/compare.jinja deleted file mode 100644 index 9eaea42..0000000 --- a/maloja/web/jinja/compare.jinja +++ /dev/null @@ -1,112 +0,0 @@ -{% extends "abstracts/base.jinja" %} -{% block title %}Maloja - Compare{% endblock %} - -{% import 'snippets/links.jinja' as links %} - -{% block scripts %} - -{% endblock %} - -{% set data = db.compare(specialkeys.remote) %} -{% set comparedata = data.result %} -{% set info = data.info %} -{% set bestartist = data.commonartist %} - - - -{% set fullmatch = comparedata.common[1]*100 %} -{% set partialmatch = comparedata.more_self[1]*100 + comparedata.more_other[1]*100 %} - -{% set match = fullmatch + (partialmatch)/2 %} -{% set pixel_fullmatch = fullmatch * 2.5 %} -{% set pixel_partialmatch = (fullmatch+partialmatch) * 2.5 %} - -{% set match = [match,100] | min %} - -{% set r = [255*match/50,255] | min %} -{% set g = [255*match/50,255] | min %} -{% set b = [255*(match/50-1),0] | max %} - - -{% block content %} - - - - - - - - - - - - - - - - - -

{{ info.ownname }}

- -
- {{ match | round(1) }}% - -
-

{{ info.remotename }}

- The size of the circle shows matching music taste. - The fuzziness of its border indicates differences in quantity. -
- Common Favorite -

{{ links.link(bestartist) }}

- -
- - -{% endblock %}