-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateReport.py
76 lines (58 loc) · 2.35 KB
/
generateReport.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
import csv
import json
import os
import subprocess
out_dir = "generated"
if not os.path.exists(out_dir):
os.makedirs(out_dir)
in_log_filename = "log.csv"
out_log_filename ="generated/remarks.tex"
log_fields = ["time", "category", "description"]
with open(out_log_filename, "w") as outfile:
with open(in_log_filename, "r") as infile:
reader = csv.DictReader(infile, fieldnames=log_fields, restkey="details")
for row in reader:
time=row["time"].strip()
timestamp = time[:-2] + ":" + time[-2:]
category = "\\"+row["category"].lower()
description = row["description"]
good_details = []
for detail in row["details"]:
if len(detail) > 0:
good_details.append(detail)
if len(good_details) == 0:
pass
elif len(good_details) == 1:
description += " ("+good_details[0]+")"
else:
description += "\\begin{itemize}"
for detail in good_details:
description+= "\\item "+ detail
description += "\\end{itemize}"
formatted = "\\logremark{" +timestamp+ "}{"+category+"}{"+description+"}\n"
outfile.write(formatted)
in_tips_filename = "tips.json"
out_tips_filename ="generated/tips.tex"
with open(out_tips_filename, "w") as outfile:
with open(in_tips_filename, "r") as infile:
tip_data = json.load(infile)
highlight_tip = "\\tipssection{\n"+ tip_data["highlight"]+"\n}\n{\n"
outfile.write(highlight_tip)
for i in range(len(tip_data["tips"])):
tip ="\\item "+tip_data["tips"][i]+"\n"
outfile.write(tip)
outfile.write("}\n\n")
in_data_filename = "data.json"
out_data_filename ="generated/data.tex"
with open(out_data_filename, "w") as outfile:
with open(in_data_filename, "r") as infile:
data = json.load(infile)
outfile.write("\\newcommand{\matchid}{"+str(data["id"])+"}\n")
outfile.write("\\newcommand{\hero}{"+data["hero"]+"}\n")
outfile.write("\\newcommand{\matchdate}{"+data["date"]+"}\n")
outfile.write("\\newcommand{\player}{"+data["player"]+"}\n")
make_args = ("make", "-f", "../Makefile")
popen = subprocess.Popen(make_args, stdout=subprocess.PIPE)
popen.wait()
output = popen.stdout.read()
print output