-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtml_out.py
350 lines (311 loc) · 14.8 KB
/
html_out.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
import rio
import uuid
from datetime import datetime, timezone
from player import Player
# |HC | M0 | +2 | +3 | +4 | +5 | +6 | +7 | +8 | +9 |+10 |
#WREWARD = [0, 0, 509, 509, 512, 512, 515, 515, 519, 519, 522] # Season 4 DF
WREWARD = [593, 603, 606, 610, 610, 613, 613, 616, 619, 619, 623] # Season 1 TWW
MYTH_TRACK_BREAKPOINT = 623
HERO_TRACK_BREAKPOINT = 610
CHAMPION_TRACK_BREAKPOINT = 603
KEY_LEVEL_TO_GET_MYTH_GEAR = len(WREWARD) - 1 # currently: +10
DUNGEONS_BACKGROUND = {
"AA": "resources/dungeons/DF/AA.png", # Season 4
"COS": "resources/dungeons/DF/COS.png",
"HOV": "resources/dungeons/DF/HOV.png",
"RLP": "resources/dungeons/DF/RLP.png", # Season 4
"SBG": "resources/dungeons/DF/SBG.png",
"TJS": "resources/dungeons/DF/TJS.png",
"AV": "resources/dungeons/DF/AV.png", # Season 4
"NO": "resources/dungeons/DF/NO.png", # Season 4
# Season 2
"BH": "resources/dungeons/DF/BH.png", # Season 4
"FH": "resources/dungeons/DF/FH.png", # Season 4
"HOI": "resources/dungeons/DF/HOI.png", # Season 4
"NELT": "resources/dungeons/DF/NELT.png", # Season 4
"NL": "resources/dungeons/DF/NL.png",
"ULD": "resources/dungeons/DF/ULD.png",
"UNDR": "resources/dungeons/DF/UNDR.png",
"VP": "resources/dungeons/DF/VP.png",
# Season 3
"AD": "resources/dungeons/DF/AD.png",
"BRH": "resources/dungeons/DF/BRH.png",
"DHT": "resources/dungeons/DF/DHT.png",
"EB": "resources/dungeons/DF/EB.png",
"FALL": "resources/dungeons/DF/RISE.png",
"RISE": "resources/dungeons/DF/RISE.png",
"TOTT": "resources/dungeons/DF/TOTT.png",
"WM": "resources/dungeons/DF/WM.png",
# TWW Season 1
"SIEGE": "resources/dungeons/TWW/SIEGE.png",
"GB": "resources/dungeons/TWW/GB.png",
"NW": "resources/dungeons/TWW/NW.png",
"MISTS": "resources/dungeons/TWW/MISTS.png",
"SV": "resources/dungeons/TWW/SV.png",
"COT": "resources/dungeons/TWW/COT.png",
"DAWN": "resources/dungeons/TWW/DAWN.png",
"ARAK": "resources/dungeons/TWW/ARAK.png",
}
def get_instance_from_player(player, ini):
best = {}
# alter = {}
best.update({'run': 0})
best.update({'upgrade': 0})
best.update({'score': 0})
best.update({'affix': 0})
# alter.update({'run': 0})
# alter.update({'upgrade': 0})
# alter.update({'score': 0})
# alter.update({'affix': 0})
for x in player.mythic_plus_best_runs():
if x['short_name'] == ini:
best.update({'run':x['mythic_level']})
best.update({'upgrade':x['num_keystone_upgrades']})
best.update({'score':x['score']})
best.update({'affix':x['affixes'][0]['id']})
break
# for x in player.mythic_plus_alternate_runs():
# if x['short_name'] == ini:
# alter.update({'run':x['mythic_level']})
# alter.update({'upgrade':x['num_keystone_upgrades']})
# alter.update({'score':x['score']})
# alter.update({'affix':x['affixes'][0]['id']})
# break
return best#, alter
def get_sterne(upgrade):
return '*' * upgrade
def gen_score_tt(scores):
tt = '<table class="tbl_tt" style="border: none;width:unset;margin-left: auto; margin-right: auto;">'
for k, v in scores.items():
tt += '<tr style="background-color: unset">'
icon = f'<img id="roleicon" src=resources/icons/role_{k}.png>'
tt += f'<td style="text-align: center;">{icon}</td><td style="text-align: left;"> {v}</td>'
tt += '</tr>'
tt += '</table>'
return tt
def gen_rewards_html(player, weekly):
epic_color = "#c600ff"
rare_color = "#0081ff"
uncommon_color = "#1eff00"
str_html = ''
for i in [0, 3, 7]:
if i != 0:
str_html += f' / '
if len(player._data[weekly]) > i:
if player._data[weekly][i]['mythic_level'] >= len(WREWARD) - 1:
reward = WREWARD[len(WREWARD) - 1]
else:
reward = WREWARD[player._data[weekly][i]['mythic_level']]
reward_str = f'<span>{reward}</span>'
if reward >= CHAMPION_TRACK_BREAKPOINT:
reward_str = f'<span style="color: {uncommon_color}">{reward}</span>'
if reward >= HERO_TRACK_BREAKPOINT:
reward_str = f'<span style="color: {rare_color}">{reward}</span>'
if reward >= MYTH_TRACK_BREAKPOINT:
reward_str = f'<span style="color: {epic_color}">{reward}</span>'
str_html += reward_str
else:
str_html += f'-'
if i == 0:
break
else:
str_html = str_html[:-4]
return str_html
def gen_general_tab(players):
table_id = uuid.uuid4().hex
str_html = f'<table id="{table_id}">\n'
str_html += f'<tr>'
str_html += f'<th onclick="sortTable(0, \'td_player\', \'{table_id}\')">Player</th>\n'
str_html += f'<th onclick="sortTable(0, \'td_ilvl\', \'{table_id}\')" class="ilvl">ilvl</th>\n'
str_html += f'<th>Embellishments</th>\n'
str_html += f'<th onclick="sortTable(0, \'td_spec\', \'{table_id}\')">Spec</th>'
str_html += f'<th onclick="sortTable(0, \'td_achiev\', \'{table_id}\')">Achievement Points</th>'
str_html += f'<th colspan="2">Professions</th>\n'
str_html += f'</tr>\n'
for p in players:
tier = p.get_tier_items()
embellishments = p.embellishments()
embellishments_tt = Player.embellishment_list_to_tooltip(embellishments)
str_html += f'<tr class="player_row" onclick="highlightRow(this)">\n'
str_html += f'<td class="td_player" title="Last Update: {p.days_since_last_update()} days ago"><a href="{p.profile_url()}" target="_blank"><img src="{p.thumbnail_url()}" width="35" height="35" style="float:left"></a><p style="color:{p.class_color};padding:5px 0px 0px 3em;margin:0px;text-align:left">{p.name}</p></td>\n'
str_html += f'<td class="td_ilvl" title="{tier}"><span style="color: {p.class_color}">{round(float(p.ilvl),1)}</span></td>\n'
str_html += f'<td class="td_embellishments" title="{embellishments_tt}">{len(embellishments)}</td>\n'
str_html += f'<td class="td_spec"><a href="{p.talents_url()}" target="_blank"><img class="spec_icon" title="{p.spec}" src="{p.spec_icon()}"></a></td>\n'
str_html += f'<td class="td_achiev">{p.achievement_points}</td>\n'
str_html += f'<td>{p.profession_string(1)}</td><td>{p.profession_string(2)}</td>\n'
str_html += f'</tr>\n'
str_html += f'</table>\n'
return str_html
def gen_score_table(players, inis, colors, isTyrannical):
table_id = uuid.uuid4().hex
str_html = f'<table id="{table_id}">\n'
str_html += f'<tr><th onclick="sortTable(0, \'td_player\', \'{table_id}\')">Player</th>\n'
str_html += f'<th onclick="sortTable(0, \'td_ilvl\', \'{table_id}\')" class="ilvl">ilvl</th>\n'
str_html += f'<th onclick="sortTable(0, \'td_score\', \'{table_id}\')" class="score">Score</th>\n'
for count, x in enumerate(inis):
if x['timer'] == 0:
ini_timer = ""
str_keystone_upgrade_timer = ""
else:
time_format = "%M:%S"
timer_dt = datetime.fromtimestamp(x['timer'])
keystone_upgrade_2 = datetime.fromtimestamp(x['upgrade_2'])
keystone_upgrade_3 = datetime.fromtimestamp(x['upgrade_3'])
ini_timer = f'[{timer_dt.strftime(time_format)}]'
str_keystone_upgrade_timer = f' +2: {keystone_upgrade_2.strftime(time_format)} +3: {keystone_upgrade_3.strftime(time_format)}'
str_html += f'<th onclick="sortTable({count}, \'td_dungeon\', \'{table_id}\')" '\
f'class="dungeon" style="background-image: url({DUNGEONS_BACKGROUND[x["short"]]})" ' \
f'title="{x["name"]}{str_keystone_upgrade_timer}">{x["short"]}<br>{ini_timer}</th>\n'
str_html += f'</tr>\n'
high_score = rio.get_highest_score(players)
for p in players:
mainSize = 17
secSize = 13
#-----------------------------------------------------------
# Count Tier Items and Build a string
tier = p.get_tier_items()
#----------------------------------
# Create Player Line on Website !!
str_html += f'<tr class="player_row" onclick="highlightRow(this)">\n'
str_html += f'<td class="td_player" title="Last Update: {p.days_since_last_update()} days ago {tier}"><a href="{p.profile_url()}" target="_blank"><img src="{p.thumbnail_url()}" width="35" height="35" style="float:left"></a><p style="font-size:{mainSize}px;color:{p.class_color};padding:5px 0px 0px 3em;margin:0px;text-align:left">{p.name}</p></td>\n'
str_html += f'<td class="td_ilvl"><span style="color: {p.class_color}">{round(float(p.ilvl),1)}</span></td>'
score = p.score # Player Score
score_tt = gen_score_tt(p.relevant_scores())
color = rio.get_color(colors, score)
str_html += f'<td class="td_score">' \
f'<div class="tooltip">' \
f'<span style="color:{color}">{score:.1f}</span>' \
f'<span class="tooltiptext">{score_tt}</span>' \
f'</div>' \
f'</td>\n'
#-----------------------------
for ini in inis:
# Iterate Instances:
best = get_instance_from_player(p, ini['short'])
best.update({'color': rio.get_color(colors, best['score'] * (len(inis)*2), high_score, len(inis))})
best.update({'sterne': get_sterne(best['upgrade'])})
# alter.update({'color': rio.get_color(colors, alter['score'] * (len(inis)*2), high_score, len(inis))})
# alter.update({'sterne': get_sterne(alter['upgrade'])})
# first = {}
# sec = {}
# if isTyrannical:
# if best['affix'] == 9:
# first = best
# sec = alter
# else:
# sec = best
# first = alter
# else:
# if best['affix'] == 10:
# first = best
# sec = alter
# else:
# sec = best
# first = alter
ini_score = round(best["score"])# + alter["score"] * 0.5, 1)
str_html += f'<td class="td_dungeon" title="{ini_score}">' \
f'<span style="font-size:{mainSize}px;color:{best["color"]}">{best["run"]}</span>' \
f'<span style="font-size:{mainSize}px;color:yellow">{best["sterne"]}</span>' \
f'</td>\n'
# f'<span style="color:white"> | </span>' \
# f'<span style="font-size:{secSize}px;color:{sec["color"]}">{sec["run"]}</span>' \
# f'<span style="font-size:{secSize}px;color:yellow">{sec["sterne"]}</span>' \
str_html += f'</tr>\n'
str_html += f'</table>\n'
return str_html
def gen_weekly(players, inis, colors, weekly, runs_dict):
players = rio.sort_players_by(players, weekly)
high = rio.get_highest_score(players)
table_id = uuid.uuid4().hex
str_html = f'<table id="{table_id}">\n'
str_html += f'<tr><th onclick="sortTable(0, \'td_player\', \'{table_id}\')">Player</th>'
str_html += f'<th onclick="sortTable(0, \'td_ilvl\', \'{table_id}\')" class="ilvl">ilvl</th>'
str_html += f'<th onclick="sortTable(0, \'td_twenty\', \'{table_id}\')" class="twenty">+{KEY_LEVEL_TO_GET_MYTH_GEAR}</th>'
str_html += f'<th onclick="sortTable(0, \'td_rewards\', \'{table_id}\')" class="rewards">Rewards</th>'
for i in range(0,8):
str_html += f'<th class="runs_weekly"></th>'
str_html += f'</tr>\n'
for p in players:
# ------------ PLAYER and SCORE -----------
# Count Tier Items and Build a string
tier = p.get_tier_items()
# ----------------------------------
str_html += f'<tr class="player_row" onclick="highlightRow(this)">\n'
str_html += f'<td class="td_player" title="Last Update: {p.days_since_last_update()} days ago {tier}"><a href="{p.profile_url()}" target="_blank"><img src="{p.thumbnail_url()}" width="35" height="35" style="float:left"></a><p style="color:{p.class_color};padding:5px 0px 0px 3em;margin:0px;text-align:left;">{p.name}</p></td>\n'
str_html += f'<td class="td_ilvl"><span style="color: {p.class_color}">{round(float(p.ilvl),1)}</span></td>'
# --------- Show Left Instances -------
count = 0
for i in p._data[weekly]:
if i['mythic_level'] >= KEY_LEVEL_TO_GET_MYTH_GEAR:
count += 1
color = 'red'
if count >= 8:
color = 'green'
count = 8
str_html += f'<td class="td_twenty"><span style="color:{color}">{count-8}</span></td>\n'
# ---------- 0 / 0 / 0 Rewards -------
str_html += f'<td class="td_rewards">'
str_html += gen_rewards_html(p, weekly)
str_html += f'</td>'
# ------------- Instances ------
for i in range(0, 8):
if i == 0 or i == 3 or i == 7:
color = 'green'
else:
color = 'white'
if len(p._data[weekly]) > i:
stern = get_sterne(p._data[weekly][i]['num_keystone_upgrades'])
dt = datetime.strptime(p._data[weekly][i]['completed_at'], '%Y-%m-%dT%H:%M:%S.000Z')
dt = dt.replace(tzinfo=timezone.utc).astimezone(tz=None)
run_time = dt.strftime('%a %d.%m %H:%M')
## TODO Maybe we want to Add instance Picture to Weekly runs, too.
str_html += f'<td title="Points: {p._data[weekly][i]["score"]}\n{run_time}\n{runs_dict[p._data[weekly][i]["url"]]}"><span style="color:{color}">{p._data[weekly][i]["short_name"]} (<a href="{p._data[weekly][i]["url"]}" style="color:{rio.get_color(colors, p._data[weekly][i]["score"] * (len(inis)*2), high, len(inis))}">{p._data[weekly][i]["mythic_level"]}{stern}</a>)</span></td>\n'
else:
str_html += f'<td><span style="color:{color}">-</span></td>\n'
str_html += '</tr>\n'
str_html += '</table>\n'
return str_html
def gen_affixes_html(affixes):
affixes_html_table = '<table><tr><th class="tbl_affixe" spancol=5 style="font-size: 20px;">Affixes:</th></tr>\n{rows}</table>'
tweek_affixes_html = []
for a in affixes['this_week']:
affix_html = f'<td class=\"tbl_affixe\"><a class="icontiny" ' \
f'data-game="wow" data-type="affix" href="{a["wowhead_url"]}">' \
f'<span class="tinycontxt"> {a["name"]}</span></a></td>'
tweek_affixes_html.append(affix_html)
tweek_affixes_out = "<td class=\"tbl_affixe\">This Week:</td>" + ''.join(tweek_affixes_html)
if affixes['next_week'] is None:
affix_row = "<tr>" + tweek_affixes_out + "\n" + "</tr>"
return affixes_html_table.format(rows=affix_row)
nweek_affixes_html = []
for a in affixes['next_week']:
if a['id'] != -1:
affix_html = f'<td class=\"tbl_affixe\"><a class="icontiny" ' \
f'data-game="wow" data-type="affix" href="{a["wowhead_url"]}">' \
f'<span class="tinycontxt"> {a["name"]}</span></a></td>'
else:
affix_html = f'<td class="tbl_affixe"><span class"tinycontxt"> {a["name"]}</span></td>'
nweek_affixes_html.append(affix_html)
nweek_affixes_out = "<td class=\"tbl_affixe\">Next Week:</td>" + ''.join(nweek_affixes_html)
affix_rows = "<tr>" + tweek_affixes_out + "\n" + "</tr><tr>" + nweek_affixes_out + "</tr>"
return affixes_html_table.format(rows=affix_rows)
def gen_site(affixes, all_tables, season_name, season_end, version_string):
now = datetime.now()
now = now.strftime("%d.%m.%Y %H:%M:%S")
affixes_html = gen_affixes_html(affixes)
# Building Website !!
with open('./templates/main.html', 'r', encoding='utf8') as f:
myhtml = f.read()
myhtml = myhtml.replace('{% season_name %}', season_name)
myhtml = myhtml.replace('{% now %}', now)
myhtml = myhtml.replace('{% affixes %}', affixes_html)
myhtml = myhtml.replace('{% season_ends %}', season_end)
myhtml = myhtml.replace('{% general_content %}', all_tables['general'])
myhtml = myhtml.replace('{% main_tracker_content %}', all_tables['main_score'])
myhtml = myhtml.replace('{% main_weekly_content %}', all_tables['main_weekly'])
myhtml = myhtml.replace('{% alts_tracker_content %}', all_tables['alts_score'])
myhtml = myhtml.replace('{% alts_weekly_content %}', all_tables['alts_weekly'])
myhtml = myhtml.replace('{% main_prev_weekly_content %}', all_tables['main_pweek'])
myhtml = myhtml.replace('{% alts_prev_weekly_content %}', all_tables['alts_pweek'])
myhtml = myhtml.replace('{% version_string %}', version_string)
return myhtml