-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSVExcelFormatter.py
295 lines (274 loc) · 19.7 KB
/
SVExcelFormatter.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
def DeckBreakdownToExcel(deck_breakdown_dict, jwriter, jworkbook):
# 1. Loop through fixed classes_order, create a new sheet for every deck archetype.
classes_order = ["Forestcraft", "Swordcraft", "Runecraft", "Dragoncraft", "Shadowcraft", "Bloodcraft", "Havencraft", "Portalcraft"]
for classes in classes_order:
for deck, stats_df in deck_breakdown_dict[classes].items():
stats_df.to_excel(jwriter, sheet_name=f"{deck}", index=True)
# 2. Set active sheet to newly added sheet.
jworksheet = jwriter.sheets[deck]
# 3. Beautify active sheet
decimal_fmt = jworkbook.add_format({'num_format': '0.00'})
jworksheet.set_column('C:E', 10, decimal_fmt) ## set descriptive stats to decimal format.
jworksheet.set_column('A:A', 30) ## set the width = 30 and bold for column A:A
jworksheet.freeze_panes(0, 5) ## Freeze left columns, Cards and descriptive stats.
# xlsxwriter requires format to be passed with .write(), which requires an input cell value too. Iterate through DataFrame.column
descstats_header_format = jworkbook.add_format({'bold': True, 'text_wrap': False, 'align': 'center', 'valign': 'vcenter', 'font_size': 15, 'rotation':0})
player_header_format = jworkbook.add_format({'bold': True, 'text_wrap': True, 'align': 'center', 'valign': 'vcenter', 'font_size': 12, 'rotation':90})
for col_num, value in enumerate(stats_df.columns.values): ## Write the column headers with the defined format.
if col_num+1 < 5:
jworksheet.write(0, col_num+1, value, descstats_header_format)
else:
jworksheet.write(0, col_num+1, value, player_header_format)
deck_header_format = jworkbook.add_format({'bold': True, 'text_wrap': True, 'align': 'center', 'valign': 'vcenter', 'font_size': 20, 'rotation':0, 'border':2})
jworksheet.write(0, 0, deck, deck_header_format) ## Formatting for deck at cell A1
# 4. Set tab colors
tabcolours = {'Forestcraft': 'green', 'Swordcraft': 'yellow', 'Runecraft': 'blue', 'Dragoncraft': 'orange', 'Shadowcraft': 'purple', 'Bloodcraft': 'red', 'Havencraft': 'silver', 'Portalcraft': 'cyan'}
for craft, colour in tabcolours.items():
if classes == craft:
jworksheet.set_tab_color(colour)
def SVOExcelFormatter(svowriter, svoworkbook, input_filename, df_5):
# 1. Set the color conditional formatting for classes and decks.
greenFill = svoworkbook.add_format({'bg_color': '#c6ffb3', 'font_color': '#000000'})
yellowFill = svoworkbook.add_format({'bg_color': '#ffffb3', 'font_color': '#000000'})
blueFill = svoworkbook.add_format({'bg_color': '#b3d9ff', 'font_color': '#000000'})
orangeFill = svoworkbook.add_format({'bg_color': '#ffd9b3', 'font_color': '#000000'})
purpleFill = svoworkbook.add_format({'bg_color': '#ecb3ff', 'font_color': '#000000'})
redFill = svoworkbook.add_format({'bg_color': '#ffb3b3', 'font_color': '#000000'})
greyFill = svoworkbook.add_format({'bg_color': '#e6e6e6', 'font_color': '#000000'})
tealFill = svoworkbook.add_format({'bg_color': '#b3ffff', 'font_color': '#000000'})
def ConditionFormatter(worksheet, lookuprange):
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Forest', 'format': greenFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Sword', 'format': yellowFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Rune', 'format': blueFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Dragon', 'format': orangeFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Shadow', 'format': purpleFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Blood', 'format': redFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Haven', 'format': greyFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Portal', 'format': tealFill})
# 2. Set active sheet and format accordingly.
col_widths = {"Name": 20,
"Player ID": 11,
"Deck_URL": 11,
"Deck": 20,
"Lineup": 55,
"C_Lineup": 38,
"Pos": 4,
"Count": 6,
"%ofPlayers": 10,
"Class": 18,
"Swiss Wins": 11,
"Xrounds": 16,
"outRound": 10,
"Xcount": 10,
"DecayLU": 20}
svoworksheet = svowriter.sheets["Wide"]
svoworksheet.set_column('A:A', col_widths["Name"]) ## Name
svoworksheet.set_column('B:B', col_widths["Player ID"]) ## Player ID
svoworksheet.set_column('C:E', col_widths["Deck_URL"]) ## Deck_URL
ConditionFormatter(svoworksheet, 'F1:H999') ## Deck
svoworksheet.set_column('F:H', col_widths["Deck"]) ## Deck
svoworksheet.set_column('I:I', col_widths["Lineup"]) ## Lineup
svoworksheet.set_column('J:J', col_widths["C_Lineup"]) ## C_Lineup
svoworksheet.set_column('K:K', col_widths["Swiss Wins"]) ## Swiss Wins
svoworksheet = svowriter.sheets["Tall"]
svoworksheet.set_column('B:B', col_widths["Name"]) ## Name
svoworksheet.set_column('A:A', col_widths["Player ID"]) ## Player ID
svoworksheet.set_column('C:C', col_widths["Deck_URL"]) ## Deck_URL
ConditionFormatter(svoworksheet, 'D1:E999') ## Deck, Class
svoworksheet.set_column('D:D', col_widths["Deck"]) ## Deck
svoworksheet.set_column('E:E', col_widths["Class"]) ## Class
# svoworksheet.set_column('F:F', col_widths["Pos"]) ## Pos
svoworksheet = svowriter.sheets["Summary"]
svoworksheet.set_column('A:A', col_widths["Deck"]) ## Deck
svoworksheet.set_column('B:B', col_widths["Class"]) ## Class
ConditionFormatter(svoworksheet, 'A2:B999') ## Deck, Class
svoworksheet.set_column('C:C', col_widths["Count"]) ## Count
svoworksheet.set_column('D:D', col_widths["%ofPlayers"], svoworkbook.add_format({'num_format': '0.00%'})) ## %ofPlayers
svoworksheet.set_column('E:E', 1) ## BLANK
svoworksheet.set_column('F:F', col_widths["Lineup"]) ## Lineup
svoworksheet.set_column('G:G', col_widths["Count"]) ## Count
svoworksheet.set_column('H:H', 10, svoworkbook.add_format({'num_format': '0.00%'})) ## %ofPlayers
svoworksheet.set_column('I:I', 1) ## BLANK
svoworksheet.set_column('J:J', col_widths["C_Lineup"]) ## C_Lineup
svoworksheet.set_column('K:K', col_widths["Count"]) ## Count
svoworksheet.set_column('L:L', col_widths["%ofPlayers"], svoworkbook.add_format({'num_format': '0.00%'})) ## %ofPlayers
merge_fmt = svoworkbook.add_format({'bold': 1, 'border': 1, 'align': 'center','valign': 'vcenter', 'font_size': 20})
# svoworksheet.merge_range('A1:L1', f'{input_filename} Summary - {rawdf_2.shape[0]} Players', merge_fmt)
svoworksheet.write(0, 0, f'{input_filename} Summary', merge_fmt)
svoworksheet = svowriter.sheets["DecayLU"]
svoworksheet.set_default_row(45)
svoworksheet.set_column('B:B', col_widths["Name"]) ## Name
svoworksheet.set_column('A:A', col_widths["Player ID"]) ## Player ID
svoworksheet.set_column('C:C', col_widths["Swiss Wins"]) ## Swiss Wins
svoworksheet.set_column('D:D', col_widths["outRound"]) ## outRound
svoworksheet.set_column('E:E', col_widths["Xcount"]) ## Xcount
svoworksheet.set_column('F:F', col_widths["Xrounds"]) ## Xrounds
right_border_wrap = svoworkbook.add_format({'border':0, 'text_wrap': True}) ## DecayLU
right_border_wrap.set_right(2)
svoworksheet.set_column('G:G', col_widths["DecayLU"], right_border_wrap) ## DecayLU
textwrap_format = svoworkbook.add_format({'text_wrap': True})
svoworksheet.set_column('H:N', col_widths["DecayLU"], textwrap_format) ## DecayLU
svoworksheet.set_row(0, 15)
svoworksheet = svowriter.sheets["DecayPlayer"]
svoworksheet.set_column('B:B', col_widths["Name"]) ## Name
svoworksheet.set_column('A:A', col_widths["Player ID"]) ## Player ID
svoworksheet.set_column('C:C', col_widths["Swiss Wins"]) ## Swiss Wins
svoworksheet.set_column('D:D', col_widths["outRound"]) ## outRound
svoworksheet.set_column('E:E', col_widths["Xcount"]) ## Xcount
svoworksheet.set_column('F:F', col_widths["Xrounds"]) ## Xrounds
svoworksheet.set_column('G:P', col_widths["Name"]) ## Name
right_border = svoworkbook.add_format({'border':0})
right_border.set_right(2)
svoworksheet.set_column('F:F', col_widths["Xrounds"], right_border) ## Xrounds
svoworksheet = svowriter.sheets["Matchup"]
svoworksheet.set_column('A:B', col_widths["Lineup"]) ## Lineup
svoworksheet.set_column('C:F', 10) ## Swiss Wins
svoworksheet.set_column('G:G', col_widths["Count"]) ## Count
svoworksheet.set_column('H:H', col_widths["%ofPlayers"], svoworkbook.add_format({'num_format': '0.00%'})) ## Spread
svoworksheet.set_column('J:K', col_widths["C_Lineup"]) ## C_Lineup
svoworksheet.set_column('L:O', 10) ## Swiss Wins
svoworksheet.set_column('P:P', col_widths["Count"]) ## Count
svoworksheet.set_column('Q:Q', col_widths["%ofPlayers"], svoworkbook.add_format({'num_format': '0.00%'})) ## Spread
merge_fmt = svoworkbook.add_format({'bold': 1, 'border': 1, 'align': 'center','valign': 'vcenter', 'font_size': 20})
svoworksheet.write(0, 0, f'Matchup Summary - {df_5.shape[0]} matches & {df_5.P1_Games.sum() + df_5.P2_Games.sum():n} games played', merge_fmt)
def JCGExcelFormatter(jwriter, jworkbook, jcg_name):
# 1. Set the color conditional formatting for classes and decks.
greenFill = jworkbook.add_format({'bg_color': '#c6ffb3', 'font_color': '#000000'})
yellowFill = jworkbook.add_format({'bg_color': '#ffffb3', 'font_color': '#000000'})
blueFill = jworkbook.add_format({'bg_color': '#b3d9ff', 'font_color': '#000000'})
orangeFill = jworkbook.add_format({'bg_color': '#ffd9b3', 'font_color': '#000000'})
purpleFill = jworkbook.add_format({'bg_color': '#ecb3ff', 'font_color': '#000000'})
redFill = jworkbook.add_format({'bg_color': '#ffb3b3', 'font_color': '#000000'})
greyFill = jworkbook.add_format({'bg_color': '#e6e6e6', 'font_color': '#000000'})
tealFill = jworkbook.add_format({'bg_color': '#b3ffff', 'font_color': '#000000'})
def ConditionFormatter(worksheet, lookuprange):
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Forest', 'format': greenFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Sword', 'format': yellowFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Rune', 'format': blueFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Dragon', 'format': orangeFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Shadow', 'format': purpleFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Blood', 'format': redFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Haven', 'format': greyFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Portal', 'format': tealFill})
# 2. Set active sheet and format accordingly.
col_widths = {"Player": 20,
"PlayerProfile": 11,
"Deck_URL": 11,
"Deck": 20,
"Lineup": 35,
"C_Lineup": 30,
"Pos": 4,
"Count": 6,
"%ofPlayers": 10,
"Class": 18}
jworksheet = jwriter.sheets["Wide"]
jworksheet.set_column('A:A', col_widths["PlayerProfile"]) ## PlayerProfile
jworksheet.set_column('B:B', col_widths["Player"]) ## Player
jworksheet.set_column('C:D', col_widths["Deck_URL"]) ## Deck_URL
ConditionFormatter(jworksheet, 'E1:F999') ## Deck
jworksheet.set_column('E:F', col_widths["Deck"]) ## Deck
jworksheet.set_column('G:G', col_widths["Lineup"]) ## Lineup
jworksheet.set_column('H:H', col_widths["C_Lineup"]) ## C_Lineup
jworksheet.set_column('I:I', col_widths["Pos"]) ## Pos
jworksheet = jwriter.sheets["Tall"]
jworksheet.set_column('A:A', col_widths["PlayerProfile"]) ## PlayerProfile
jworksheet.set_column('B:B', col_widths["Player"]) ## Player
jworksheet.set_column('C:C', col_widths["Deck_URL"]) ## Deck_URL
ConditionFormatter(jworksheet, 'D1:E999') ## Deck, Class
jworksheet.set_column('D:D', col_widths["Deck"]) ## Deck
jworksheet.set_column('E:E', col_widths["Class"]) ## Class
jworksheet.set_column('F:F', col_widths["Pos"]) ## Pos
jworksheet = jwriter.sheets["Summary"]
jworksheet.set_column('A:A', col_widths["Deck"]) ## Deck
jworksheet.set_column('B:B', col_widths["Class"]) ## Class
ConditionFormatter(jworksheet, 'A2:B999') ## Deck, Class
jworksheet.set_column('C:C', col_widths["Count"]) ## Count
jworksheet.set_column('D:D', col_widths["%ofPlayers"], jworkbook.add_format({'num_format': '0.00%'})) ## %ofPlayers
jworksheet.set_column('E:E', 1) ## BLANK
jworksheet.set_column('F:F', col_widths["Lineup"]) ## Lineup
jworksheet.set_column('G:G', col_widths["Count"]) ## Count
jworksheet.set_column('H:H', 10, jworkbook.add_format({'num_format': '0.00%'})) ## %ofPlayers
jworksheet.set_column('I:I', 1) ## BLANK
jworksheet.set_column('J:J', col_widths["C_Lineup"]) ## C_Lineup
jworksheet.set_column('K:K', col_widths["Count"]) ## Count
jworksheet.set_column('L:L', col_widths["%ofPlayers"], jworkbook.add_format({'num_format': '0.00%'})) ## %ofPlayers
merge_fmt = jworkbook.add_format({'bold': 1, 'border': 1, 'align': 'center','valign': 'vcenter', 'font_size': 20})
jworksheet.merge_range('A1:L1', f'{jcg_name.split(" ロ")[0]} Summary', merge_fmt)
jworksheet = jwriter.sheets["Matchup"]
jworksheet.merge_range('A1:H1', 'Class Matchup', merge_fmt)
jworksheet.merge_range('J1:Q1', 'Deck Matchup', merge_fmt)
jworksheet.set_column('A:A', col_widths["C_Lineup"]) ## C_Lineup
jworksheet.set_column('B:B', col_widths["C_Lineup"]) ## C_Lineup
jworksheet.set_column('J:J', col_widths["Lineup"]) ## Lineup
jworksheet.set_column('K:K', col_widths["Lineup"]) ## Lineup
jworksheet.set_column('H:H', col_widths["%ofPlayers"], jworkbook.add_format({'num_format': '0.00%'})) ## %
jworksheet.set_column('Q:Q', col_widths["%ofPlayers"], jworkbook.add_format({'num_format': '0.00%'})) ## %
def BattlefyExcelFormatter(svowriter, svoworkbook, input_filename):
# 1. Set the color conditional formatting for classes and decks.
greenFill = svoworkbook.add_format({'bg_color': '#c6ffb3', 'font_color': '#000000'})
yellowFill = svoworkbook.add_format({'bg_color': '#ffffb3', 'font_color': '#000000'})
blueFill = svoworkbook.add_format({'bg_color': '#b3d9ff', 'font_color': '#000000'})
orangeFill = svoworkbook.add_format({'bg_color': '#ffd9b3', 'font_color': '#000000'})
purpleFill = svoworkbook.add_format({'bg_color': '#ecb3ff', 'font_color': '#000000'})
redFill = svoworkbook.add_format({'bg_color': '#ffb3b3', 'font_color': '#000000'})
greyFill = svoworkbook.add_format({'bg_color': '#e6e6e6', 'font_color': '#000000'})
tealFill = svoworkbook.add_format({'bg_color': '#b3ffff', 'font_color': '#000000'})
def ConditionFormatter(worksheet, lookuprange):
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Forest', 'format': greenFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Sword', 'format': yellowFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Rune', 'format': blueFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Dragon', 'format': orangeFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Shadow', 'format': purpleFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Blood', 'format': redFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Haven', 'format': greyFill})
worksheet.conditional_format(lookuprange, {'type': 'text', 'criteria': 'containing', 'value': 'Portal', 'format': tealFill})
# 2. Set active sheet and format accordingly.
col_widths = {"Name": 20,
"Player ID": 11,
"Deck_URL": 11,
"Deck": 20,
"Lineup": 55,
"C_Lineup": 38,
"Pos": 4,
"Count": 6,
"%ofPlayers": 10,
"Class": 18,
"Swiss Wins": 11,
"Xrounds": 16,
"outRound": 10,
"Xcount": 10,
"DecayLU": 20}
svoworksheet = svowriter.sheets["Wide"]
svoworksheet.set_column('A:A', col_widths["Name"]) ## Name
svoworksheet.set_column('B:B', col_widths["Player ID"]) ## Player ID
svoworksheet.set_column('C:E', col_widths["Deck_URL"]) ## Deck_URL
ConditionFormatter(svoworksheet, 'F1:H999') ## Deck
svoworksheet.set_column('F:H', col_widths["Deck"]) ## Deck
svoworksheet.set_column('I:I', col_widths["Lineup"]) ## Lineup
svoworksheet.set_column('J:J', col_widths["C_Lineup"]) ## C_Lineup
svoworksheet.set_column('K:K', col_widths["Swiss Wins"]) ## Swiss Wins
svoworksheet = svowriter.sheets["Tall"]
svoworksheet.set_column('B:B', col_widths["Name"]) ## Name
svoworksheet.set_column('A:A', col_widths["Player ID"]) ## Player ID
svoworksheet.set_column('C:C', col_widths["Deck_URL"]) ## Deck_URL
ConditionFormatter(svoworksheet, 'D1:E999') ## Deck, Class
svoworksheet.set_column('D:D', col_widths["Deck"]) ## Deck
svoworksheet.set_column('E:E', col_widths["Class"]) ## Class
# svoworksheet.set_column('F:F', col_widths["Pos"]) ## Pos
svoworksheet = svowriter.sheets["Summary"]
svoworksheet.set_column('A:A', col_widths["Deck"]) ## Deck
svoworksheet.set_column('B:B', col_widths["Class"]) ## Class
ConditionFormatter(svoworksheet, 'A2:B999') ## Deck, Class
svoworksheet.set_column('C:C', col_widths["Count"]) ## Count
svoworksheet.set_column('D:D', col_widths["%ofPlayers"], svoworkbook.add_format({'num_format': '0.00%'})) ## %ofPlayers
svoworksheet.set_column('E:E', 1) ## BLANK
svoworksheet.set_column('F:F', col_widths["Lineup"]) ## Lineup
svoworksheet.set_column('G:G', col_widths["Count"]) ## Count
svoworksheet.set_column('H:H', 10, svoworkbook.add_format({'num_format': '0.00%'})) ## %ofPlayers
svoworksheet.set_column('I:I', 1) ## BLANK
svoworksheet.set_column('J:J', col_widths["C_Lineup"]) ## C_Lineup
svoworksheet.set_column('K:K', col_widths["Count"]) ## Count
svoworksheet.set_column('L:L', col_widths["%ofPlayers"], svoworkbook.add_format({'num_format': '0.00%'})) ## %ofPlayers
merge_fmt = svoworkbook.add_format({'bold': 1, 'border': 1, 'align': 'center','valign': 'vcenter', 'font_size': 20})
# svoworksheet.merge_range('A1:L1', f'{input_filename} Summary - {rawdf_2.shape[0]} Players', merge_fmt)
svoworksheet.write(0, 0, f'{input_filename} Summary', merge_fmt)