-
Notifications
You must be signed in to change notification settings - Fork 0
/
SiteGen.py
69 lines (52 loc) · 1.62 KB
/
SiteGen.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
#!/usr/bin/python
import jinja2
from datetime import datetime
class SiteGen:
def __init__(self, globalVars):
templateLoader = jinja2.FileSystemLoader( searchpath="./template")
self.env = jinja2.Environment(loader = templateLoader, trim_blocks = True)
self.env.globals.update(globalVars);
def winTable(self, ranking, count):
lb = [r[0] for r in ranking.ranking()][:count]
table = [["WIN%"] + lb]
for t1 in lb:
row = [t1]
for t2 in lb:
if t1 == t2:
row.append('-')
else:
row.append(ranking.winChance(t1, t2) * 100)
table.append(row)
return table
def genWinTablePage(self, ranking):
template = self.env.get_template("winTable.html")
wt = self.winTable(ranking, 25)
example = {
"winner" : wt[4][0],
"loser" : wt[0][5],
"chance" : wt[4][5]
}
templateVars = {
"curMap" : ranking.name,
"numGames" : ranking.gameCount,
"genTime" : datetime.utcnow(),
"winTable" : wt,
"example" : example,
"curPage" : "win"
}
return template.render(templateVars)
def genRankingTablePage(self, ranking):
template = self.env.get_template("ranking.html")
rk = ranking.ranking()
templateVars = {
"curMap" : ranking.name,
"numGames" : ranking.gameCount,
"genTime" : datetime.utcnow(),
"rankingTable" : rk,
"curPage" : "rank"
}
return template.render(templateVars)
def test(self, ranking):
f = open("html/test.html", 'w')
f.write(self.genWinTablePage(ranking))
f.close();