MCPcopy Create free account
hub / github.com/OpenDriveLab/TCP / MetricsManager

Class MetricsManager

scenario_runner/metrics_manager.py:31–124  ·  view source on GitHub ↗

Main class of the metrics module. Handles the parsing and execution of the metrics.

Source from the content-addressed store, hash-verified

29
30
31class MetricsManager(object):
32 """
33 Main class of the metrics module. Handles the parsing and execution of
34 the metrics.
35 """
36
37 def __init__(self, args):
38 """
39 Initialization of the metrics manager. This creates the client, needed to parse
40 the information from the recorder, extract the metrics class, and runs it
41 """
42 self._args = args
43
44 # Parse the arguments
45 recorder_str = self._get_recorder(self._args.log)
46 criteria_dict = self._get_criteria(self._args.criteria)
47
48 # Get the correct world and load it
49 map_name = self._get_recorder_map(recorder_str)
50 world = self._client.load_world(map_name)
51 town_map = world.get_map()
52
53 # Instanciate the MetricsLog, used to querry the needed information
54 log = MetricsLog(recorder_str)
55
56 # Read and run the metric class
57 metric_class = self._get_metric_class(self._args.metric)
58 metric_class(town_map, log, criteria_dict)
59
60 def _get_recorder(self, log):
61 """
62 Parses the log argument into readable information
63 """
64
65 # Get the log information.
66 self._client = carla.Client(self._args.host, self._args.port)
67 recorder_file = "{}/{}".format(os.getenv('SCENARIO_RUNNER_ROOT', "./"), log)
68
69 # Check that the file is correct
70 if recorder_file[-4:] != '.log':
71 print("ERROR: The log argument has to point to a .log file")
72 sys.exit(-1)
73 if not os.path.exists(recorder_file):
74 print("ERROR: The specified log file does not exist")
75 sys.exit(-1)
76
77 recorder_str = self._client.show_recorder_file_info(recorder_file, True)
78
79 return recorder_str
80
81 def _get_criteria(self, criteria_file):
82 """
83 Parses the criteria argument into a dictionary
84 """
85 if criteria_file:
86 with open(criteria_file) as fd:
87 criteria_dict = json.load(fd)
88 else:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected