-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdisplayCompetition.py
More file actions
854 lines (781 loc) · 31.4 KB
/
displayCompetition.py
File metadata and controls
854 lines (781 loc) · 31.4 KB
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
import os
import webbrowser
import sys
from HTMLParser import HTMLParser
from random import randint
def listdir_nohidden(path):
for f in os.listdir(path):
if not f.startswith('.'):
yield f
class RoundDisplayHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
print "Encountered a start tag:", tag
def handle_endtag(self, tag):
print "Encountered an end tag :", tag
def handle_data(self, data):
print "Encountered some data :", data
class DisplayCompetition(object):
submissionsDir = 'submissions/'
tournamentResultsDir = 'tournamentResults/'
leaguesDir = tournamentResultsDir + '0/'
quarterFinalsDir = tournamentResultsDir + '1/'
semiFinalsDir = tournamentResultsDir + '2/'
finalDir = tournamentResultsDir + '3/'
quarterFinalsRound = 1
semiFinalsRound = 2
finalRound = 4
numberOfLeagues = 4
gamesPerMatch = 10
players2Bots = {}
leaguesMaps = []
quarterFinalsMaps = []
semiFinalsMaps = []
finalMaps = []
allPlayers = []
leaguesPlayers = []
quarterFinalsPlayers = []
quarterFinalsWinners = []
semiFinalsPlayers = []
semiFinalsWinners = []
finalPlayers = []
scores = {}
finalScores = {}
drawFlag = False
drawMaps = []
fakeFlag = False
fakeMaps = []
def __init__(self):
self.initPlayers2Bots()
self.doLeagues()
self.initScoreRounds()
self.generateLeaguesCover()
self.generateLeaguesDisplay()
self.resetScores()
self.doQuarterFinals()
self.generateQuarterFinalsCover()
self.generateQuarterFinalsDisplay()
self.resetScores()
self.doSemiFinals()
self.generateSemiFinalsCover()
self.generateSemiFinalsDisplay()
self.resetScores()
self.doFinal()
self.initScoreFinal()
self.generateFinalCover()
self.generateFinalDisplay()
# self.generateChampionDisplay()
def initPlayers2Bots(self):
for d in listdir_nohidden(self.submissionsDir):
f = open(self.submissionsDir + d + '/bot.txt', 'r')
self.players2Bots[d] = f.readline()
self.scores[d.split('group')[1]] = 0
print self.players2Bots
def doLeagues(self):
for league in range(1, self.numberOfLeagues + 1):
leaguePlayers = set()
for match in listdir_nohidden(self.leaguesDir + str(league)):
leaguePlayers.add(match.split('-')[0])
leaguePlayers.add(match.split('-')[1])
matchDir = self.leaguesDir + str(league) + '/' + match
matchWinner = self.getMatchWinner(matchDir)
maxSizeRoundFile = self.getMapToDisplay(matchDir, matchWinner)
if maxSizeRoundFile:
self.leaguesMaps.append(matchDir + '/' + maxSizeRoundFile + '/generated.htm')
self.leaguesPlayers.append(list(leaguePlayers))
def initScoreRounds(self):
for league in self.leaguesPlayers:
for player in league:
self.scores[player] = 0
def initScoreFinal(self):
self.finalScores['0'] = 0
for player in self.finalPlayers:
self.finalScores[player] = 0
def getMatchWinner(self, matchDir):
match = matchDir.split('/')[-1]
playerA = match.split('-')[0]
playerAWins = 0
playerB = match.split('-')[1]
playerBWins = 0
if 'draw' in listdir_nohidden(matchDir):
matchDir = matchDir + '/draw/'
for rnd in listdir_nohidden(matchDir):
if rnd.split('.')[-1] != "txt":
continue
winner = rnd.split('_')[0][1:]
if winner == playerA:
playerAWins += 1
elif winner == playerB:
playerBWins += 1
elif winner == '0':
playerAWins += 1
playerBWins += 1
else:
print "ERROR SOLVING MATCH"
matchWinner = ''
matchLooser = ''
if playerAWins > playerBWins:
matchWinner = playerA
matchLooser = playerB
elif playerBWins > playerAWins:
matchWinner = playerB
matchLooser = playerA
else:
print "Draw game!"
matchWinner = playerA
matchLooser = playerB
self.drawFlag = True
#print "Group {} wins against group {}".format(matchWinner, matchLooser)
return matchWinner
def getMatchesWinners(self, matchDir):
winnerSequence = []
match = matchDir.split('/')[-1]
playerA = match.split('-')[0]
playerAWins = 0
playerB = match.split('-')[1]
playerBWins = 0
for rnd in listdir_nohidden(matchDir):
winner = -1
if not rnd.endswith('.txt') and rnd != 'draw':
if os.path.isdir(self.semiFinalsDir + match + '/draw/') and rnd in listdir_nohidden(self.semiFinalsDir + match + '/draw/'):
winner = 0
else:
winner = rnd.split('_')[0][1:]
winnerSequence.append(winner)
return winnerSequence
def earlyWinner(self, players):
for p in players:
if self.scores[p] == self.gamesPerMatch/2 + 1:
return True
return False
def getMapToDisplay(self, matchDir, matchWinner):
wonRoundFiles = [rnd for rnd in listdir_nohidden(matchDir) if rnd.split('_')[0] == 'w' + matchWinner and rnd.split('.')[-1] != 'txt']
if len(wonRoundFiles) == 0:
self.fakeFlag = True
wonRoundFiles = [rnd.split('.')[0] for rnd in listdir_nohidden(matchDir) if rnd.split('_')[0] == 'w' + matchWinner]
# Probably all draws, select random map
if len(wonRoundFiles) == 0:
wonRoundFiles = [rnd for rnd in listdir_nohidden(matchDir) if rnd.split('.')[-1] != 'txt']
randomPointer = randint(0,len(wonRoundFiles)-1)
selectedMap = wonRoundFiles[randomPointer]
if self.drawFlag:
self.drawMaps.append(matchDir + '/' + selectedMap + '/generated.htm')
self.drawFlag = False
if self.fakeFlag:
self.fakeMaps.append(selectedMap)
self.fakeFlag = False
return selectedMap
def resetScores(self):
for x,y in self.scores.iteritems():
self.scores[x] = 0
def generateLeaguesDisplay(self):
#roundDisplayParser = RoundDisplayHTMLParser()
#roundDisplayParser.feed()
n = len(self.leaguesPlayers[0]) - 1 if self.numberOfLeagues > 0 else 0
m = len(self.leaguesPlayers[1]) - 1 if self.numberOfLeagues > 0 else 0
maxMatchesLargestLeague = (n * (n + 1))/2
maxMatchesRegularLeagues = (m * (m + 1))/2
for x in range(maxMatchesLargestLeague):
htmlLeagueDisplayFile = open('leagueDisplay' + str(x) + '.html', 'w')
fileContents = """
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="js/jquery.tablesorter.js"></script>
<script src="js/competition.js"></script>
<title>
PlanetWars Tournament
</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="next"><a href='resultsDisplay""" + str(x) + """.html'><img src="imgs/next.png" height="16px" width="16px"></img></a></div>
<iframe src='""" + self.leaguesMaps[x + 0] + """' height=1000 width=900 frameborder=0></iframe>
"""
print self.leaguesMaps
if x < maxMatchesRegularLeagues:
fileContents += """
<iframe src='""" + self.leaguesMaps[x + 6] + """' height=1000 width=900 frameborder=0></iframe>
<iframe src='""" + self.leaguesMaps[x + 12] + """' height=1000 width=900 frameborder=0></iframe>
<iframe src='""" + self.leaguesMaps[x + 18] + """' height=1000 width=900 frameborder=0></iframe>
"""
fileContents += """
</body>
</html>
"""
htmlLeagueDisplayFile.write(fileContents)
htmlLeagueDisplayFile.close()
winner1 = self.leaguesMaps[x].split('/')[-2].split('_')[0][1:]
if x < maxMatchesRegularLeagues:
winner2 = self.leaguesMaps[x+6].split('/')[-2].split('_')[0][1:]
winner3 = self.leaguesMaps[x+12].split('/')[-2].split('_')[0][1:]
winner4 = self.leaguesMaps[x+18].split('/')[-2].split('_')[0][1:]
if self.leaguesMaps[x] not in self.drawMaps:
self.scores[winner1] += 3
else:
onePlayer = self.leaguesMaps[x].split('/')[-2].split('_')[1].split('-')[0]
otherPlayer = self.leaguesMaps[x].split('/')[-2].split('_')[1].split('-')[1]
self.scores[onePlayer] += 1
self.scores[otherPlayer] += 1
if self.leaguesMaps[x+6] not in self.drawMaps:
self.scores[winner2] += 3
else:
onePlayer = self.leaguesMaps[x+6].split('/')[-2].split('_')[1].split('-')[0]
otherPlayer = self.leaguesMaps[x+6].split('/')[-2].split('_')[1].split('-')[1]
self.scores[onePlayer] += 1
self.scores[otherPlayer] += 1
if self.leaguesMaps[x+12] not in self.drawMaps:
self.scores[winner3] += 3
else:
onePlayer = self.leaguesMaps[x+12].split('/')[-2].split('_')[1].split('-')[0]
otherPlayer = self.leaguesMaps[x+12].split('/')[-2].split('_')[1].split('-')[1]
self.scores[onePlayer] += 1
self.scores[otherPlayer] += 1
if x < 10:
if self.leaguesMaps[x+18] not in self.drawMaps:
self.scores[winner4] += 3
else:
onePlayer = self.leaguesMaps[x+18].split('/')[-2].split('_')[1].split('-')[0]
otherPlayer = self.leaguesMaps[x+18].split('/')[-2].split('_')[1].split('-')[1]
self.scores[onePlayer] += 1
self.scores[otherPlayer] += 1
htmlResultsDisplayFile = open('resultsDisplay' + str(x) + '.html', 'w')
fileContents = """
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="js/jquery.tablesorter.js"></script>
<script src="js/competition.js"></script>
<title>
PlanetWars Tournament
</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="next"><a href='"""
if x < maxMatchesLargestLeague - 1:
fileContents += """leagueDisplay""" + str(x + 1) + """.html"""
else:
fileContents += """quarterFinalsDisplayCover.html"""
fileContents += """
'><img src="imgs/next.png" height="16px" width="16px"></img></a></div>
<div align='center' style='width:900px; margin:20px auto;'>
<div style='float:center'>
"""
leagueId = 1
for league in self.leaguesPlayers:
fileContents += """
<table class="tablesorter"><thead><tr><th align="left">Group Stage """ + str(leagueId) + """</th><th> </th></tr></thead><tbody>
"""
for player in league:
fileContents += """
<tr>
<td>""" + self.players2Bots['group' + player] + """</td><td>""" + str(self.scores[player]) + """</td>
</tr>
"""
fileContents += """
</tbody></table>
"""
leagueId += 1
fileContents += """
</div>
</div>
</body>
</html>
"""
htmlResultsDisplayFile.write(fileContents)
htmlResultsDisplayFile.close()
def generateLeaguesCover(self):
htmlCoverPage = open('leagueDisplayCover.html', 'w')
nextPage = 'leagueDisplay0.html' if self.numberOfLeagues > 0 else 'quarterFinalsDisplayCover.html'
fileContents = """
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="js/jquery.tablesorter.js"></script>
<script src="js/competition.js"></script>
<title>
PlanetWars Tournament
</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="next"><a href=""" + nextPage + """><img src="imgs/next.png" height="16px" width="16px"></img></a></div>
<div style='float:center'>
"""
leagueId = 1
for league in self.leaguesPlayers:
fileContents += """
<table class="tablesorter"><thead><tr><th align="left">Group Stage """ + str(leagueId) + """</th><th> </th></tr></thead><tbody>
"""
for player in league:
fileContents += """
<tr>
<td>""" + self.players2Bots['group' + player] + """</td><td>""" + str(self.scores[player]) + """</td>
</tr>
"""
fileContents += """
</tbody></table>
"""
leagueId += 1
fileContents += """
</div>
</div>
</body>
</html>
"""
htmlCoverPage.write(fileContents)
htmlCoverPage.close()
def doQuarterFinals(self):
print "Doing quarter finals"
for match in listdir_nohidden(self.quarterFinalsDir):
quarterPlayers = set()
quarterPlayers.add(match.split('-')[0])
quarterPlayers.add(match.split('-')[1])
matchDir = self.quarterFinalsDir + match
matchesWinners = self.getMatchesWinners(matchDir)
self.quarterFinalsWinners.append(matchesWinners)
#maxSizeRoundFile = self.getMapToDisplay(matchDir, matchWinner)
quarterMaps = []
for rnd in listdir_nohidden(self.quarterFinalsDir + match):
if not rnd.endswith('.txt') and rnd != 'draw':
if os.path.isdir(self.quarterFinalsDir + match + '/draw/') and rnd in listdir_nohidden(self.quarterFinalsDir + match + '/draw/'):
quarterMaps.append(matchDir + '/draw/' + rnd + '/generated.htm')
else:
quarterMaps.append(matchDir + '/' + rnd + '/generated.htm')
self.quarterFinalsMaps.append(quarterMaps)
self.quarterFinalsPlayers.append(list(quarterPlayers))
print self.quarterFinalsPlayers
print self.quarterFinalsMaps
print self.quarterFinalsWinners
def generateQuarterFinalsDisplay(self):
print "Generating quarter finals display"
indexPager = 0
maxQuarterFinalsMatches = 0
for qmap in self.quarterFinalsMaps:
if len(qmap) > maxQuarterFinalsMatches:
maxQuarterFinalsMatches = len(qmap)
print maxQuarterFinalsMatches
for x in range(maxQuarterFinalsMatches):
htmlQuarterFinalsDisplay = open('quarterFinalsDisplay' + str(indexPager) + '.html', 'w')
fileContents = """
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="js/jquery.tablesorter.js"></script>
<script src="js/competition.js"></script>
<title>
PlanetWars Tournament
</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="next"><a href='resultsQuarterFinalsDisplay""" + str(x) + """.html'><img src="imgs/next.png" height="16px" width="16px"></img></a></div>"""
print self.quarterFinalsWinners
if not self.earlyWinner(self.quarterFinalsPlayers[0]) and x < len(self.quarterFinalsMaps[0]):
fileContents += """
<iframe src='""" + self.quarterFinalsMaps[0][x] + """' height=1000 width=900 frameborder=0></iframe>"""
if not self.earlyWinner(self.quarterFinalsPlayers[1]) and x < len(self.quarterFinalsMaps[1]):
fileContents += """
<iframe src='""" + self.quarterFinalsMaps[1][x] + """' height=1000 width=900 frameborder=0></iframe>"""
if not self.earlyWinner(self.quarterFinalsPlayers[2]) and x < len(self.quarterFinalsMaps[2]):
fileContents += """
<iframe src='""" + self.quarterFinalsMaps[2][x] + """' height=1000 width=900 frameborder=0></iframe>"""
if not self.earlyWinner(self.quarterFinalsPlayers[3]) and x < len(self.quarterFinalsMaps[3]):
fileContents += """
<iframe src='""" + self.quarterFinalsMaps[3][x] + """' height=1000 width=900 frameborder=0></iframe>"""
fileContents += """
</body>
</html>
"""
htmlQuarterFinalsDisplay.write(fileContents)
htmlQuarterFinalsDisplay.close()
indexPager += 1
htmlResultsDisplayFile = open('resultsQuarterFinalsDisplay' + str(x) + '.html', 'w')
fileContents = """
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="js/jquery.tablesorter.js"></script>
<script src="js/competition.js"></script>
<title>
PlanetWars Tournament
</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
"""
if x < maxQuarterFinalsMatches - 1:
fileContents +="""
<div class="next"><a href='quarterFinalsDisplay""" + str(x + 1) + """.html'>
"""
else:
fileContents +="""
<div class="next"><a href='semiFinalsDisplayCover.html'>
"""
fileContents +="""
<img src="imgs/next.png" height="16px" width="16px"></img></a></div>
<div style='float:center'>
"""
quarterFinalId = 1;
for quarter in self.quarterFinalsPlayers:
fileContents += """
<table class="tablesorter"><thead><tr><th align="left">Quarter Final """ + str(quarterFinalId) + """</th><th> </th></tr></thead><tbody>
"""
for player in quarter:
if x < len(self.quarterFinalsWinners[quarterFinalId-1]) and player == self.quarterFinalsWinners[quarterFinalId-1][x] and not self.earlyWinner(quarter):
self.scores[player] += 1
fileContents += """
<tr>
<td>""" + self.players2Bots['group' + player] + """</td><td>""" + str(self.scores[player]) + """</td>
</tr>
"""
quarterFinalId += 1
fileContents += """
</tbody></table>
"""
fileContents += """
</div>
</div>
</body>
</html>
"""
htmlResultsDisplayFile.write(fileContents)
htmlResultsDisplayFile.close()
def generateQuarterFinalsCover(self):
htmlCoverQuarterFinalsPage = open('quarterFinalsDisplayCover.html', 'w')
fileContents = """
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="js/jquery.tablesorter.js"></script>
<script src="js/competition.js"></script>
<title>
PlanetWars Tournament
</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="next"><a href='quarterFinalsDisplay0.html'><img src="imgs/next.png" height="16px" width="16px"></img></a></div>
<div style='float:center'>
"""
quarterFinalId = 1
for quarter in self.quarterFinalsPlayers:
fileContents += """
<table class="tablesorter"><thead><tr><th align="left">Quarter Final """ + str(quarterFinalId) + """</th><th> </th></tr></thead><tbody>
"""
for player in quarter:
fileContents += """
<tr>
<td>""" + self.players2Bots['group' + player] + """</td><td>""" + str(self.scores[player]) + """</td>
</tr>
"""
fileContents += """
</tbody></table>
"""
quarterFinalId += 1
fileContents += """
</div>
</div>
</body>
</html>
"""
htmlCoverQuarterFinalsPage.write(fileContents)
htmlCoverQuarterFinalsPage.close()
def doSemiFinals(self):
print "Doing semi finals"
for match in listdir_nohidden(self.semiFinalsDir):
semiPlayers = set()
semiPlayers.add(match.split('-')[0])
semiPlayers.add(match.split('-')[1])
matchDir = self.semiFinalsDir + match
matchesWinners = self.getMatchesWinners(matchDir)
self.semiFinalsWinners.append(matchesWinners)
#maxSizeRoundFile = self.getMapToDisplay(matchDir, matchWinner)
semiMaps = []
for rnd in listdir_nohidden(self.semiFinalsDir + match):
if not rnd.endswith('.txt') and rnd != 'draw':
if os.path.isdir(self.semiFinalsDir + match + '/draw/') and rnd in listdir_nohidden(self.semiFinalsDir + match + '/draw/'):
semiMaps.append(matchDir + '/draw/' + rnd + '/generated.htm')
else:
semiMaps.append(matchDir + '/' + rnd + '/generated.htm')
self.semiFinalsMaps.append(semiMaps)
self.semiFinalsPlayers.append(list(semiPlayers))
print self.semiFinalsMaps
print self.semiFinalsPlayers
def generateSemiFinalsDisplay(self):
print "Generating semi finals display"
indexPager = 0
maxSemiFinalsMatches = 0
for smap in self.semiFinalsMaps:
if len(smap) > maxSemiFinalsMatches:
maxSemiFinalsMatches = len(smap)
print maxSemiFinalsMatches
for x in range(maxSemiFinalsMatches):
htmlSemiFinalsDisplay = open('semiFinalsDisplay' + str(indexPager) + '.html', 'w')
fileContents = """
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="js/jquery.tablesorter.js"></script>
<script src="js/competition.js"></script>
<title>
PlanetWars Tournament
</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="next"><a href='resultsSemiFinalsDisplay""" + str(x) + """.html'><img src="imgs/next.png" height="16px" width="16px"></img></a></div>"""
if not self.earlyWinner(self.semiFinalsPlayers[0]) and x < len(self.semiFinalsMaps[0]):
fileContents += """
<iframe src='""" + self.semiFinalsMaps[0][x] + """' height=1000 width=900 frameborder=0></iframe>"""
if not self.earlyWinner(self.semiFinalsPlayers[1]) and x < len(self.semiFinalsMaps[1]):
fileContents += """
<iframe src='""" + self.semiFinalsMaps[1][x] + """' height=1000 width=900 frameborder=0></iframe>"""
fileContents += """
</body>
</html>
"""
htmlSemiFinalsDisplay.write(fileContents)
htmlSemiFinalsDisplay.close()
indexPager += 1
htmlResultsDisplayFile = open('resultsSemiFinalsDisplay' + str(x) + '.html', 'w')
fileContents = """
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="js/jquery.tablesorter.js"></script>
<script src="js/competition.js"></script>
<title>
PlanetWars Tournament
</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
"""
if x < maxSemiFinalsMatches - 1:
fileContents +="""
<div class="next"><a href='semiFinalsDisplay""" + str(x + 1) + """.html'>
"""
else:
fileContents +="""
<div class="next"><a href='finalDisplayCover.html'>
"""
fileContents +="""
<img src="imgs/next.png" height="16px" width="16px"></img></a></div>
<div style='float:center'>
"""
semiFinalId = 1;
print self.semiFinalsWinners
for semi in self.semiFinalsPlayers:
fileContents += """
<table class="tablesorter"><thead><tr><th align="left">Semi Final """ + str(semiFinalId) + """</th><th> </th></tr></thead><tbody>
"""
for player in semi:
if x < len(self.semiFinalsWinners[semiFinalId-1]) and player == self.semiFinalsWinners[semiFinalId-1][x] and not self.earlyWinner(semi):
self.scores[player] += 1
fileContents += """
<tr>
<td>""" + self.players2Bots['group' + player] + """</td><td>""" + str(self.scores[player]) + """</td>
</tr>
"""
semiFinalId += 1
fileContents += """
</tbody></table>
"""
fileContents += """
</div>
</div>
</body>
</html>
"""
htmlResultsDisplayFile.write(fileContents)
htmlResultsDisplayFile.close()
def generateSemiFinalsCover(self):
htmlCoverSemiFinalsPage = open('semiFinalsDisplayCover.html', 'w')
fileContents = """
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="js/jquery.tablesorter.js"></script>
<script src="js/competition.js"></script>
<title>
PlanetWars Tournament
</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="next"><a href='semiFinalsDisplay0.html'><img src="imgs/next.png" height="16px" width="16px"></img></a></div>
<div style='float:center'>
"""
semiFinalId = 1
for semi in self.semiFinalsPlayers:
fileContents += """
<table class="tablesorter"><thead><tr><th align="left">Semi Final """ + str(semiFinalId) + """</th><th> </th></tr></thead><tbody>
"""
for player in semi:
fileContents += """
<tr>
<td>""" + self.players2Bots['group' + player] + """</td><td>""" + str(self.scores[player]) + """</td>
</tr>
"""
fileContents += """
</tbody></table>
"""
semiFinalId += 1
fileContents += """
</div>
</div>
</body>
</html>
"""
htmlCoverSemiFinalsPage.write(fileContents)
htmlCoverSemiFinalsPage.close()
def doFinal(self):
print "Doing final"
for match in listdir_nohidden(self.finalDir):
matchDir = self.finalDir + match
self.finalPlayers.append(match.split('-')[0])
self.finalPlayers.append(match.split('-')[1])
for rnd in listdir_nohidden(matchDir):
if not rnd.endswith('.txt'):
self.finalMaps.append(matchDir + '/' + rnd + '/generated.htm')
print self.finalMaps
def generateFinalDisplay(self):
print "Generating final display"
for x in range(len(self.finalMaps)):
htmlFinalDisplay = open('finalDisplay' + str(x) + '.html', 'w')
fileContents = """
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="js/jquery.tablesorter.js"></script>
<script src="js/competition.js"></script>
<title>
PlanetWars Tournament
</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="next"><a href='resultsFinalDisplay""" + str(x) + """.html'><img src="imgs/next.png" height="16px" width="16px"></img></a></div>
<iframe src='""" + self.finalMaps[x] + """' height=1000 width=900 frameborder=0></iframe>
</body>
</html>
"""
htmlFinalDisplay.write(fileContents)
htmlFinalDisplay.close()
self.finalScores[self.finalMaps[x].split('/')[-2].split('_')[0][1:]] += 1
htmlResultsDisplayFile = open('resultsFinalDisplay' + str(x) + '.html', 'w')
if x < len(self.finalMaps) - 1 and self.finalScores[self.finalPlayers[0]] < len(self.finalMaps)/2 + 1 and self.finalScores[self.finalPlayers[1]] < len(self.finalMaps)/2 + 1:
fileContents = """
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="js/jquery.tablesorter.js"></script>
<script src="js/competition.js"></script>
<title>
PlanetWars Tournament
</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="next"><a href='finalDisplay""" + str(x + 1) + """.html'><img src="imgs/next.png" height="16px" width="16px"></img></a></div>
<div align='center' style='width:900px; margin:20px auto;'>
<table class="tablesorter"><thead><tr><th align="left">Final</th><th> </th></tr></thead><tbody>
<tr>
<td>""" + self.players2Bots['group' + self.finalPlayers[0]] + """</td><td>""" + str(self.finalScores[self.finalPlayers[0]]) + """</td>
</tr>
<tr>
<td>""" + self.players2Bots['group' + self.finalPlayers[1]] + """</td><td>""" + str(self.finalScores[self.finalPlayers[1]]) + """</td>
</tr>
</tbody></table>
</div>
</body>
</html>
"""
else:
fileContents = """
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="js/jquery.tablesorter.js"></script>
<script src="js/competition.js"></script>
<title>
PlanetWars Tournament
</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div align='center' style='width:900px; margin:20px auto;'>
<img src="imgs/winnertext.png"></img><br>
<img src="imgs/marvin.jpg"></img><br>
<table class="tablesorter"><thead><tr><th align="left">Final</th><th> </th></tr></thead><tbody>
<tr>
<td>""" + self.players2Bots['group' + self.finalPlayers[0]] + """</td><td>""" + str(self.finalScores[self.finalPlayers[0]]) + """</td>
</tr>
<tr>
<td>""" + self.players2Bots['group' + self.finalPlayers[1]] + """</td><td>""" + str(self.finalScores[self.finalPlayers[1]]) + """</td>
</tr>
</tbody></table>
</div>
</body>
</html>
"""
htmlResultsDisplayFile.write(fileContents)
htmlResultsDisplayFile.close()
def generateFinalCover(self):
htmlCoverFinalPage = open('finalDisplayCover.html', 'w')
fileContents = """
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="js/jquery.tablesorter.js"></script>
<script src="js/competition.js"></script>
<title>
PlanetWars Tournament
</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="next"><a href='finalDisplay0.html'><img src="imgs/next.png" height="16px" width="16px"></img></a></div>
<div align='center' style='width:900px; margin:20px auto;'>
<table class="tablesorter"><thead><tr><th align="left">Final</th><th> </th></tr></thead><tbody>
<tr>
<td>""" + self.players2Bots['group' + self.finalPlayers[0]] + """</td><td>0</td>
</tr>
<tr>
<td>""" + self.players2Bots['group' + self.finalPlayers[1]] + """</td><td>0</td>
</tr>
</tbody></table>
</div>
</body>
</html>
"""
htmlCoverFinalPage.write(fileContents)
htmlCoverFinalPage.close()
def generateChampionDisplay(self):
maxScore = 0
for player,score in self.finalScores.iteritems():
if score > maxScore:
champion = player
maxScore = score
htmlChampionPage = open('championDisplay.html', 'w')
fileContents = """
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="js/jquery.tablesorter.js"></script>
<script src="js/competition.js"></script>
<title>
PlanetWars Tournament
</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>PlanetWars Champion!</h1>
<h2>""" + self.players2Bots['group' + champion] + """</h2>
</body>
</html>
"""
htmlChampionPage.write(fileContents)
htmlChampionPage.close()
dc = DisplayCompetition()