Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
report_evaluation.py
Go to the documentation of this file.
1#!/usr/bin/python3
2import yaml
3import sys
4import os
5
6
7def main(path):
8 with open(path) as f:
9 report = yaml.full_load(f)
10 success = evaluate(report)
11 output(report, success, os.path.splitext(path)[0])
12 return success
13
14
15def evaluate(report: dict):
16 if "report" not in report.keys():
17 raise RuntimeError(
18 "The specified report does not follow the standard formatting")
19 report_contents = report["report"]
20 if "status" not in report_contents.keys():
21 raise RuntimeError(
22 "The specified report does not have a status associated")
23 status = report_contents["status"]
24 if "success" not in status:
25 raise RuntimeError(
26 "The specified report does not provide success information")
27 return bool(status["success"])
28
29
30def output(report, success, file_path):
31 report = report["report"]
32 f = open(file_path + ".txt", "w+")
33
34 if "discipline" in report["status"]:
35 f.write(f"Discipline: {report['status']['discipline']}\n")
36 if "track_file" in report:
37 f.write(f"Track: {report['track_file']}\n")
38 f.write(f"Success: {':white_check_mark:' if success else ':x:'}\n")
39 if "final_time_raw" in report['status']:
40 f.write(f"Driven Time: {report['status']['final_time_raw']}\n")
41
42 penalty_time = 0
43 for penalty in report["penalties"]:
44 if penalty["penalty"]["time"]:
45 penalty_time += penalty["penalty"]["time"]
46
47 f.write(f"Penalty time: {penalty_time}")
48
49
50if __name__ == "__main__":
51 try:
52 path = str(sys.argv[1])
53 main(path)
54 except IndexError:
55 raise IndexError(
56 "Path to the report file not specified, expected call: report_evaluation.py {path}")
Definition main.py:1
output(report, success, file_path)