This repository has been archived by the owner on Nov 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
hotsbuildcheatsheets.py
218 lines (193 loc) · 7.14 KB
/
hotsbuildcheatsheets.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
import math
import doclib
from herolib.HeroParser import HeroParser
from herolib.TalentSorter import TalentSorter
DEBUG = False
# DEBUG = True
HEROES = [
"Abathur",
"Anub'arak",
"Artanis",
"Arthas",
"Azmodan",
"Brightwing",
"Chen",
"Cho",
"Chromie",
"Dehaka",
"Diablo",
"E.T.C.",
"Falstad",
"Gall",
"Gazlowe",
"Greymane",
"Illidan",
"Jaina",
"Johanna",
"Kael'thas",
"Kerrigan",
"Kharazim",
"Leoric",
"Li Li",
"Li-Ming",
"Lt. Morales",
"Lunara",
"Malfurion",
"Medivh",
"Muradin",
"Murky",
"Nazeebo",
"Nova",
"Raynor",
"Rehgar",
"Rexxar",
"Sgt. Hammer",
"Sonya",
"Stitches",
"Sylvanas",
"Tassadar",
"The Butcher",
"The Lost Vikings",
"Thrall",
"Tracer",
"Tychus",
"Tyrael",
"Tyrande",
"Uther",
"Valla",
"Xul",
"Zagara",
"Zeratul"
]
HERO_BASE_URL = 'https://www.hotslogs.com/Sitewide/HeroDetails?Hero='
TALENT_TABLE = '{:<6} | {:<6} | {:<9} | {}\n'
if DEBUG:
HEROES = ["Chen"]
def update_flat_files():
""" Human readable/consumable data """
wiki_file = open('wiki/Home.md', 'w')
wiki_file.write(doclib.NEWS[0])
wiki_file.write(doclib.INDEX[0])
for name in HEROES:
hero_file = open('wiki/' + name + '.md', 'w')
hero_file.write(doclib.NEWS[0])
hero_file.write('# ' + name + '\n\n')
wiki_file.write('\n\n# ' + name + '\n\n')
write_talent_table_header(wiki_file, name)
write_talent_table_header(hero_file, name)
top_hero_popularity_talents_by_position = top_popularity_talents_by_position[name]
top_hero_winning_talents_by_position = top_winning_talents_by_position[name]
found_top_talent_build = False
found_top_winning_build = False
highest_popularity_talents_note = '* Highest popularity talents, individually'
highest_win_percentage_talents_note = '* Highest win percentage talents, individually'
for top_build in heroes[name].top_builds:
heroes_fire_link = create_heroes_fire_link(name, top_build.build_by_talent_positions)
shorthand = format_talents_shorthand(top_build.build_by_talent_positions)
ranked_build_representation = '[{}]({})'.format(shorthand, heroes_fire_link)
note = ''
if top_build.build_by_talent_positions == top_hero_popularity_talents_by_position:
note += highest_popularity_talents_note
found_top_talent_build = True
if top_build.build_by_talent_positions == top_hero_winning_talents_by_position:
if note != '':
note += ' <br/>*'
note += highest_win_percentage_talents_note
found_top_winning_build = True
line = TALENT_TABLE.format(
top_build.games_played,
top_build.win_percentage,
ranked_build_representation, note
)
wiki_file.write(line)
hero_file.write(line)
if not found_top_talent_build:
append_other_top_build(name, wiki_file, top_hero_popularity_talents_by_position,
highest_popularity_talents_note)
append_other_top_build(name, hero_file, top_hero_popularity_talents_by_position,
highest_popularity_talents_note)
if not found_top_winning_build:
append_other_top_build(name, wiki_file, top_hero_winning_talents_by_position,
highest_win_percentage_talents_note)
append_other_top_build(name, hero_file, top_hero_winning_talents_by_position,
highest_win_percentage_talents_note)
wiki_file.write('\n\n')
wiki_file.write('\n\n'.join(doclib.INDEX[1:len(doclib.INDEX)]))
def append_other_top_build(name, file_handler, build, note):
heroes_fire_link = create_heroes_fire_link(name, build)
shorthand_format = format_talents_shorthand(build)
build_with_embedded_link = '[{}]({})'.format(shorthand_format, heroes_fire_link)
line = TALENT_TABLE.format(
'N/A',
'N/A',
build_with_embedded_link,
note
)
file_handler.write(line)
def format_talents_shorthand(build):
shorthand_build = ''
for tier, talentNum in enumerate(build):
if tier == 3:
shorthand_build += '-' + str(talentNum) + '-'
else:
shorthand_build += str(talentNum)
return shorthand_build
def create_heroes_fire_link(name, build):
if name == 'E.T.C.':
name = 'elite-tauren-chieftain'
if name == 'Sgt. Hammer':
name = 'sergeant-hammer'
if name == 'Lt. Morales':
name = 'lt-morales'
name = name.replace("'", "") \
.replace(" ", "-") \
.lower()
return 'http://www.heroesfire.com/hots/talent-calculator/' \
+ name + '#' \
+ format_talent_as_heroes_fire_hash(build)
def format_talent_as_heroes_fire_hash(build):
heroes_fire_hash_build = '1'
for tier, talentNum in enumerate(build):
heroes_fire_hash_build += str(talentNum)
residual = int(heroes_fire_hash_build)
alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'
radix_64 = ''
while True:
rixit = residual % len(alphabet)
radix_64 = alphabet[int(math.floor(rixit))] + radix_64
residual = math.floor(residual / len(alphabet))
if residual == 0:
break
return radix_64
def format_talents_verbose(build):
verbose_build = ''
for tier, talent in enumerate(build):
talent_position = str(talent.position)
verbose_build = verbose_build + talent_position + ', ' + talent.talent + '\n'
return verbose_build
def write_talent_table_header(file_handler, hero_name):
hots_url = HERO_BASE_URL + hero_name
counter_url = 'http://hotscounters.com/#/hero/' + hero_name
file_handler.write('Links: [{}]({}) | [{}]({})\n\n'.format(
'HOTS Logs Source', hots_url,
'HotS Counters', counter_url
))
file_handler.write(TALENT_TABLE.format('Games', 'Win %', 'Build', 'Note'))
file_handler.write(TALENT_TABLE.format('-----', '-----', '-----', '----'))
if __name__ == "__main__":
heroes = {}
top_popularity_talents = {}
top_popularity_talents_by_position = {}
top_winning_talents_by_position = {}
for hero in HEROES:
hero_url = HERO_BASE_URL + hero
current_hero = HeroParser(hero_url)
heroes[hero] = current_hero
top_popularity_talents[hero] = TalentSorter.sort(current_hero.talents, sort_key='popularity')
top_popularity_talents_by_position[hero] = TalentSorter.sort(current_hero.talents,
sort_key='popularity',
by_position=True)
top_winning_talents_by_position[hero] = TalentSorter.sort(current_hero.talents,
sort_key='win_percentage',
by_position=True)
update_flat_files()