Skip to content

Instantly share code, notes, and snippets.

@dividuum
Last active November 21, 2016 12:41
Show Gist options
  • Save dividuum/5bdffe157a97b456e6e2224606758acb to your computer and use it in GitHub Desktop.
Save dividuum/5bdffe157a97b456e6e2224606758acb to your computer and use it in GitHub Desktop.
import os, json
stats = {}
keys = set()
for fname in os.listdir("stats"):
name = fname.replace(".json", "")
with file("stats/%s" % fname) as f:
data = json.load(f)
stats[name] = data
for k, v in data.iteritems():
keys.add(k)
all_keys = sorted(keys)
for key in all_keys:
print key
achievements = []
for name, key, what in (
('Biggest bunny', 'stat.jump', 'Number of jumps'),
('Lone walker', 'stat.walkOneCm', 'Walking distance in cm'),
('Look, a shoe!', 'stat.junkFished', 'Junk fished'),
("I'm a sailor now", 'stat.boatOneCm', 'Distance by boat in cm'),
('Look at my DPS', 'stat.damageDealt', 'Damage dealt'),
("I'm a tank", 'stat.damageTaken', 'Damage taken'),
("I'm totally not the horse killer", 'stat.killEntity.EntityHorse', 'Number of horses killed'),
('Tinted glass', 'stat.killEntity.Squid', 'Squids killed'),
('Worthless trades', 'stat.killEntity.Villager', 'Villagers killed'),
('Ouch! My head', 'stat.breakItem.310', 'Number of own diamond helmets broken'),
('Let me put this here', 'stat.drop', 'Items dropped'),
('All the way to the top', 'stat.climbOneCm', 'Number of cm climbed'),
("Let's craft some melons", 'stat.craftItem.103', 'Melons crafted. Hu?'),
("Trapped chests are better chests", 'stat.craftItem.146', 'Trapped chests crafted'),
("We build our base with redstone blocks", 'stat.craftItem.152', 'Number of redstone blocks crafted'),
('That rug really ties the room together','stat.craftItem.171', 'Number of carpets crafted'),
('Coal miners', 'stat.craftItem.263', 'Number of coal blocks crafted'),
('What time is it?', 'stat.craftItem.347', 'Number of clocks crafted'),
("Diabetes", 'stat.craftItem.353', 'Number of sugar items crafted'),
("Potato factory", 'stat.craftItem.393', 'Number of potatoes crafted'),
("I'm rich", 'stat.craftItem.57', 'Number of diamond blocks crafted'),
('Horsing around', 'stat.horseOneCm', 'Distance by horse in cm'),
('Pigging around', 'stat.pigOneCm', 'Distance by pig in cm'),
('I have no life', 'stat.playOneMinute', 'Playtime in ticks (20/second, still seems too high?)'),
('I can stop anytime I want', 'stat.leaveGame', 'Number of quits'),
# ('Sneaky bastard', 'stat.sneakTime', 'Sneak button presses'),
):
scores = []
for player, stat in stats.iteritems():
if key in stat:
scores.append((stat[key], player))
scores.sort(reverse=True)
achievements.append((name, what, scores[:100]))
for name, prefix, what in (
('Break all the blocks!', 'stat.mineBlock.', 'Total number of blocks broken'),
('Craft all the things!', 'stat.craftItem.', 'Total number of items crafted'),
):
scores = []
for player, stat in stats.iteritems():
count = 0
for key in all_keys:
if key.startswith(prefix) and key in stat:
count += stat[key]
scores.append((count, player))
scores.sort(reverse=True)
achievements.append((name, what, scores[:100]))
out = []
out.append("<html><body>")
out.append("<h1>Random HCF Map 16 stats</h1>")
out.append("made possible by <a href='https://redd.it/5bj638'>https://redd.it/5bj638</a>.<hr/>")
for name, what, scores in achievements:
out.append("<h1>%s</h1><h3>%s</h3>" % (name, what))
out.append("<table>")
for score, name in scores:
out.append("<tr><td><img src='https://minotar.net/avatar/%s/16'> %s</td><td>%s</td></tr>" % (
name, name, score
))
out.append("</table>")
out.append("<br/><br/><br/><br/><br/>")
with file("stats.html", "wb") as f:
f.write("".join(out))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment