Add script for a tildebadge leaderboard

This commit is contained in:
Robert Miles 2020-06-08 16:06:27 -04:00
parent 40225a6544
commit f251a5b995
1 changed files with 23 additions and 0 deletions

23
tildebadge_leaderboard.py Normal file
View File

@ -0,0 +1,23 @@
import json, os.path, sys, csv
from collections import Counter
with open(os.path.join(os.path.dirname(__file__),"badges.json")) as f: badges = json.load(f)
with open(os.path.join(os.path.dirname(__file__),"association.json")) as f: assoc = json.load(f)
users = []
for user in badges:
n=0
r=0
for badge in badges[user]:
if badge["name"]!="Tildebadge": continue
n+=1
r+=1 if badge["normal"] else 0
if n: users.append([assoc.get(user,user),n,"{:02.2%}".format(r/n)])
users.sort(key=lambda x: (-x[1],-float(x[2][:-1])))
seq = sorted([x[1] for x in users],reverse=True)
for i, u in enumerate(users):
u.insert(0,seq.index(u[1])+1)
csv.writer(sys.stdout).writerows(users)