-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-lookup.py
172 lines (131 loc) · 5.67 KB
/
generate-lookup.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import json
from io import BytesIO
from pathlib import Path
import numpy as np
import pandas as pd
import requests
class NpEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.integer):
return int(obj)
if isinstance(obj, np.floating):
return float(obj)
if isinstance(obj, np.ndarray):
return obj.tolist()
return super(NpEncoder, self).default(obj)
ITEM_SHEET_URL = "https://docs.google.com/spreadsheets/d/104CdfaEnvhYavh6reVtpB599rCa5uzDiaO0Jtrg5qR0/export?gid=135314365&format=csv"
DROP_SHEET_BASE_URL = "https://docs.google.com/spreadsheets/d/1_SlTjrVRTgHgfS7sRqx4CeJMqlz687HdSlYqiW-JvQA/export?format=xlsx"
DROP_SHEET_NAMES = [
"Best 5 APDrop (JP)",
"Best 5 Droprate (JP)",
"Best 5 APDrop (NA)",
"Best 5 Droprate (NA)",
]
print("Fetching items", end="", flush=True)
item_df = pd.read_csv(ITEM_SHEET_URL)
item_df = item_df[item_df["Image link"].str.contains("Items/") == 1]
item_dict = item_df.set_index("ID")[["NA Name", "Image link"]].T.to_dict()
print("... Fetched.\nFetching item icons...", end=" ", flush=True)
nice_items_r = requests.get("https://api.atlasacademy.io/export/JP/nice_item.json")
nice_items_r.raise_for_status()
nice_items = {item["id"]: item for item in nice_items_r.json()}
for item_info in item_dict.values():
item_info["rarity"] = nice_items[
int(item_info["Image link"].split("Items/")[1].split("_")[0])
]["background"]
print("Fetched.\nFetching dropsheet", end="", flush=True)
response = requests.get(DROP_SHEET_BASE_URL)
response.raise_for_status()
excel_data = BytesIO(response.content)
all_sheets = pd.read_excel(excel_data, sheet_name=None)
print("... Loaded.", flush=True)
result_dict = {}
rarity_order = {
"gold": 1,
"silver": 2,
"bronze": 3,
"secret gem": 4,
"magic gem": 5,
"gem": 6,
"monument": 7,
"piece": 8,
}
print(f"Sheet names: {DROP_SHEET_NAMES}\nProcesing data...", flush=True)
for sheet_name in DROP_SHEET_NAMES:
print(f"\t{sheet_name}", end="", flush=True)
df = all_sheets[sheet_name]
df_cleaned = df.iloc[1:]
# df.columns[1] # The index in the admin info sheet
df_cleaned.columns = df_cleaned.iloc[0]
df_cleaned = df_cleaned[df_cleaned.iloc[:, 0] != "Item"]
df_cleaned = df_cleaned[df_cleaned.iloc[:, 8] != "1P+1L+1T"].dropna(
axis=1, how="all"
)
with pd.option_context("future.no_silent_downcasting", True):
df_cleaned = (
df_cleaned.fillna(np.nan).replace([np.nan], [None]).reset_index(drop=True)
)
columns = ["No.", "Area", "Quest", "AP", "BP/AP", "AP/Drop", "Drop Chance", "Runs"]
sheet_list = []
# For a particular mat, the data is stored in its row and the subsequent 4 rows, making it 5 rows in total
for i in range(0, len(df_cleaned), 5):
# for i in range(0, 5, 5):
for index_base_add in [0, 14]:
# for index_base_add in [14]:
name = df_cleaned.iloc[i, index_base_add + 1] # Name
ID = df_cleaned.iloc[i, index_base_add] # ID
if pd.notna(name):
sub_dict_list = []
for j in range(i, i + 5):
if j < len(df_cleaned):
sub_dict = {
"No.": df_cleaned.iloc[j, index_base_add + 2], # No.
"Area": df_cleaned.iloc[j, index_base_add + 4], # Area
"Quest": df_cleaned.iloc[j, index_base_add + 5], # Quest
"AP": df_cleaned.iloc[j, index_base_add + 6], # AP
"BP/AP": df_cleaned.iloc[j, index_base_add + 7], # BP/AP
"AP/Drop": df_cleaned.iloc[
j, index_base_add + 8
], # AP/Drop
"Drop Chance": df_cleaned.iloc[
j, index_base_add + 10
], # Drop Chance
"Runs": df_cleaned.iloc[j, index_base_add + 12], # Runs
}
if sub_dict["Area"]: # Otherwise there is no data
sub_dict_list.append(sub_dict)
if not len(sub_dict_list):
continue
rarity = item_dict[ID]["rarity"]
if name.lower().endswith("piece"):
rarity = "piece"
elif name.lower().endswith("monument"):
rarity = "monument"
elif name.lower().startswith("gem"):
rarity = "gem"
elif name.lower().startswith("magic gem"):
rarity = "magic gem"
elif name.lower().startswith("secret gem"):
rarity = "secret gem"
sheet_list.append(
{
"name": name,
"image": item_dict[ID]["Image link"],
"id": item_dict[ID]["Image link"]
.split("Items/")[1]
.split("_")[0],
"rarity": rarity,
"data": sub_dict_list,
}
)
if "APDrop" in sheet_name:
sheet_name = sheet_name.replace("APDrop", "AP/Drop")
result_dict[sheet_name] = sorted(
sheet_list, key=lambda x: (rarity_order.get(x["rarity"], 0), x["id"])
)
print("... Done.", flush=True)
mats_file_name = Path("./assets/mats.json").resolve()
mats_file_name.parent.mkdir(parents=True, exist_ok=True)
with open(mats_file_name, "w") as f:
json.dump(result_dict, f, cls=NpEncoder)
print(f"Wrote drop data to `{mats_file_name}`", flush=True)