-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaderboard.py
49 lines (39 loc) · 1.34 KB
/
leaderboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import json
import cache
import helper_functions as helperfunc
from item_values import itemValues as values
schema = cache.getSchema()
item_values = {}
for name in values:
for item in schema:
if item["name"] == name:
item_values[str(item["id"])] = values[name]
break
if len(item_values) != len(values):
raise LookupError ("Couldn't find all keys! Please review to make sure no keys are missing.")
del schema, values, item, name
print(item_values)
ships = {}
for day, dayCount in helperfunc.dateRange():
print("Getting Ships, {} days left".format(dayCount))
for ship in cache.getFromCache("ships", date=day):
ships[ship["hex_code"]] = {
"name": ship["name"],
"items": ship["items"]
}
print("calculating values for {} ships".format(len(ships)))
for hex in ships:
items = ships[hex]["items"]
value = 0
for id in items:
value += items[id] * item_values.get(id, 0)
ships[hex]["value"] = value
print("Sorting...")
sorted =sorted(ships, key=lambda x: ships[x]["value"], reverse=True)
print("Outputting")
output = "Ship Stats:\n"
for hex in sorted[:500]:
ship = ships[hex]
output += "#{}: {} {} got {} points\n".format(sorted.index(hex)+1, hex, ship["name"], ship["value"])
with open("output.txt", "w", encoding="utf-8") as f:
f.write(output)