mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Removed compare functionality
This commit is contained in:
parent
1df51748b6
commit
7021099e7b
@ -261,7 +261,7 @@ def artist_info(artist):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@waitfordb
|
||||||
def track_info(track):
|
def track_info(track):
|
||||||
|
|
||||||
track = sqldb.get_track(sqldb.get_track_id(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])
|
"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):
|
def incoming_scrobble(artists,title,album=None,duration=None,time=None,fix=True):
|
||||||
|
@ -1,112 +0,0 @@
|
|||||||
{% extends "abstracts/base.jinja" %}
|
|
||||||
{% block title %}Maloja - Compare{% endblock %}
|
|
||||||
|
|
||||||
{% import 'snippets/links.jinja' as links %}
|
|
||||||
|
|
||||||
{% block scripts %}
|
|
||||||
<style>
|
|
||||||
.comparecircle {
|
|
||||||
height:500px;
|
|
||||||
width:500px;
|
|
||||||
border-radius:250px;
|
|
||||||
border: 1px solid rgba(245,245,220,0.3);
|
|
||||||
margin:auto;
|
|
||||||
margin-top:100px;
|
|
||||||
text-align:center;
|
|
||||||
line-height:500px;
|
|
||||||
font-size:60px;
|
|
||||||
color:black;
|
|
||||||
/* background-image: linear-gradient(to right,KEY_CIRCLE_CSS); */
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
table tr td:first-child {
|
|
||||||
text-align: left;
|
|
||||||
padding:10px;
|
|
||||||
width:33%;
|
|
||||||
}
|
|
||||||
table tr td {
|
|
||||||
text-align: center;
|
|
||||||
padding:10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
table tr td:last-child {
|
|
||||||
text-align: right;
|
|
||||||
padding:10px;
|
|
||||||
width:33%;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% set data = db.compare(specialkeys.remote) %}
|
|
||||||
{% set comparedata = data.result %}
|
|
||||||
{% set info = data.info %}
|
|
||||||
{% set bestartist = data.commonartist %}
|
|
||||||
<!--
|
|
||||||
{% set categories =
|
|
||||||
{
|
|
||||||
"unique_self":"rgba(255,255,255,0.2)",
|
|
||||||
"more_self":"rgba(255,255,255,0.5)",
|
|
||||||
"common":"white",
|
|
||||||
"more_other":"rgba(255,255,255,0.5)",
|
|
||||||
"unique_other":"rgba(255,255,255,0.2)"
|
|
||||||
}
|
|
||||||
%}-->
|
|
||||||
<!--
|
|
||||||
{% set css = [] %}
|
|
||||||
{% set cumulative = 0 %}
|
|
||||||
{% for cat in categories %}
|
|
||||||
{% set cumulative = cumulative + (comparedata[cat][1]*100) %}
|
|
||||||
{% set _ = css.append(categories[cat] + " " + cumulative.__str__() + "%") %}
|
|
||||||
{% endfor %}-->
|
|
||||||
|
|
||||||
{% 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 %}
|
|
||||||
<table style="width:99%;">
|
|
||||||
<tr>
|
|
||||||
<td><h1>{{ info.ownname }}</h1></td>
|
|
||||||
<td>
|
|
||||||
|
|
||||||
<div class="comparecircle"
|
|
||||||
style="background-image: radial-gradient(rgb({{ r }},{{ g }}, {{ b }}) {{ pixel_fullmatch }}px, transparent {{ pixel_partialmatch }}px);">
|
|
||||||
{{ match | round(1) }}%
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td><h1>{{ info.remotename }}</h1></td>
|
|
||||||
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td></td>
|
|
||||||
<td style="font-size:70%;color:grey;">
|
|
||||||
The size of the circle shows matching music taste.
|
|
||||||
The fuzziness of its border indicates differences in quantity.
|
|
||||||
</td>
|
|
||||||
<td></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td></td>
|
|
||||||
<td>
|
|
||||||
<span>Common Favorite</span>
|
|
||||||
<h2 style="margin:7px;">{{ links.link(bestartist) }}</h2>
|
|
||||||
<img src="{{ utilities.getArtistImage(bestartist) }}" style="width:80px;" />
|
|
||||||
</td>
|
|
||||||
<td></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
|
Loading…
x
Reference in New Issue
Block a user