-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
120 lines (97 loc) · 3.54 KB
/
utils.py
File metadata and controls
120 lines (97 loc) · 3.54 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
import json
import os
from subprocess import Popen, PIPE
import sys
from collections import OrderedDict
from datetime import datetime
table_template = """
<div class="table100-head">
<table>
<thead>
<tr class="row100 head">
<th class="cell100 column1">Username</th>
<th class="cell100 column2">Time (s)</th>
<th class="cell100 column3">Perf (Gpts/s)</th>
<th class="cell100 column4">𝚫 err</th>
<th class="cell100 column5">Hash</th>
</tr>
</thead>
</table>
</div>
<div class="table100-body js-pscroll">
<table>
<tbody>
{0}
</tbody>
</table>
</div>
"""
row_acoustic_template = """
<tr class="row100 body">
<td class="cell100 column1">{0}</td>
<td class="cell100 column2">{1}</td>
<td class="cell100 column3">{2}</td>
<td class="cell100 column4">{3}</td>
<td class="cell100 column5">{4}</td>
</tr>
"""
row_tti_template = """
<tr class="row100 body">
<td class="cell100 column1">{0}</td>
<td class="cell100 column2">{1}</td>
<td class="cell100 column3">{2}</td>
<td class="cell100 column4">{3}</td>
<td class="cell100 column4">{4}</td>
</tr>
"""
def get_commit_hash(user):
os.chdir(user)
output = Popen("git rev-parse --short HEAD".split(), stdout=PIPE).communicate()[0]
output = output.decode("utf-8").strip()
os.chdir("../")
return output
def json_to_table(data, type):
table = table_template
sorted_items = sorted(data.items(), key=lambda x: x[1][type]['time'])
content = ''
for row in sorted_items:
user = row[0]
git_hash = get_commit_hash(user)
mapper = data[user][type]
# time == 0 means that the user didn't run this case
if type == 'acoustic' and mapper['time'] > 0:
content = content + row_acoustic_template.format(
user,
mapper['time'],
mapper['perf'],
'None' if not mapper['err'] else ('(rec = %s ; u = %s)' %
(str(mapper['err']['rec'][2]),
str(mapper['err']['u'][2]))),
git_hash
)
elif type == 'tti' and mapper['time'] > 0:
content = content + row_tti_template.format(
user,
mapper['time'],
mapper['perf'],
'None' if not mapper['err'] else ('(rec = %s ; u = %s ; v = %s)' %
(str(mapper['err']['rec'][2]),
str(mapper['err']['u'][2]),
str(mapper['err']['v'][2]))),
git_hash)
return table.format(content)
def generate_score_html(data):
acoustic = json_to_table(data, 'acoustic')
tti = json_to_table(data, 'tti')
# datetime object containing current date and time
now = datetime.now()
# dd/mm/YY H:M:S
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
with open('score_template.html') as file_template:
template = str(file_template.read())
template = template.replace("_acoustic_table_", acoustic)
template = template.replace("_tti_table_", tti)
template = template.replace("_current_time_", dt_string)
output_file = open("DevitoHack-oghpc2020.github.io/index.html", 'w')
output_file.write(template)
output_file.close()