forked from ArchipelagoMW/AsyncTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yaml_output_converter.py
108 lines (90 loc) · 3.42 KB
/
yaml_output_converter.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""This file was originally made as a quick & dirty helper tool, not meant for public eyes.
If you like good code, avert your eyes."""
import csv
import string
import yaml
import itertools
import sys
with open(sys.argv[1], 'r') as f:
mystery = yaml.unsafe_load(f.read())
shuffles = {"bigkey_shuffle": "b", "compass_shuffle": "c", "map_shuffle": "m"}
ignored = {"open_pyramid"}
always = {"game", "accessibility", "progression_balancing"}
rows = []
players = list(mystery["name"].values())
player_games = list(mystery["game"].values())
START = 1
for START, player in enumerate(players, 1):
if player.startswith("Player") and all(c in string.digits for c in player.lstrip("Player")):
print("First generic player:", player, START)
break
print(player)
END = len(players) + 1
print(START, END)
print("unnamed players follow")
for p in range(START, END):
row = {"keysanity": ""}
for key, value in [(k, v) for k, v in mystery.items() if isinstance(v, dict)]:
if not key in ignored:
if p not in value:
row[key] = None
continue
pvalue = value[p]
try:
pkey = getattr(pvalue, "current_key", pvalue)
except:
pass
if key == "smallkey_shuffle":
if pkey == "universal":
row["keysanity"] += "u"
elif pkey != "original_dungeon":
row["keysanity"] += "s"
elif key in shuffles:
if pkey != "original_dungeon":
row["keysanity"] += shuffles[key]
else:
row[key] = pvalue
row["keysanity"] = "".join(sorted(row["keysanity"]))
rows.append(row)
def get_option_name(option):
getter = getattr(option, "get_current_option_name", None)
if getter:
return getter()
else:
return option
def get_option_header(option, key):
getter = getattr(option, "display_name", None)
if getter:
return getter
else:
return key
# filter identical options out
games = set(row["game"] for row in rows)
print("Games", games)
for game in games:
remove = set()
game_rows = [row for row in rows if row["game"] == game]
for key, value in next(iter(game_rows)).items():
if all(row[key] == value for row in game_rows):
remove.add(key)
remove -= {"game"}
for key in remove:
for row in game_rows:
del row[key]
with open('mystery_result.csv', 'w') as mysterycsv:
rows = [{get_option_header(data, key): get_option_name(data) for key, data in row.items()} for row in rows]
fieldnames = set(itertools.chain.from_iterable(((key for key, value in dictionary.items() if value not in {"", None})
for dictionary in rows)))
fieldnames -= {"game"}
fieldnames = sorted(fieldnames)
fieldnames = ["game"] + fieldnames
writer = csv.DictWriter(mysterycsv, fieldnames=fieldnames, lineterminator='\n')
writer.writeheader()
for row in rows:
writer.writerow({key: value for key, value in row.items() if key in fieldnames})
with open("mystery_players.csv", 'w') as mysterycsv:
writer = csv.DictWriter(mysterycsv, fieldnames=["Slot", "Name", "Game"], lineterminator='\n')
writer.writeheader()
for i, name in enumerate(players, 1):
writer.writerow({"Slot": i, "Name": name, "Game": player_games[i-1]})
print("Done")