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

Method _get_metric_class

scenario_runner/metrics_manager.py:93–114  ·  view source on GitHub ↗

Function to extract the metrics class from the path given by the metrics argument. Returns the first class found that is a child of BasicMetric Args: metric_file (str): path to the metric's file.

(self, metric_file)

Source from the content-addressed store, hash-verified

91 return criteria_dict
92
93 def _get_metric_class(self, metric_file):
94 """
95 Function to extract the metrics class from the path given by the metrics
96 argument. Returns the first class found that is a child of BasicMetric
97
98 Args:
99 metric_file (str): path to the metric's file.
100 """
101 # Get their module
102 module_name = os.path.basename(metric_file).split('.')[0]
103 sys.path.insert(0, os.path.dirname(metric_file))
104 metric_module = importlib.import_module(module_name)
105
106 # And their members of type class
107 for member in inspect.getmembers(metric_module, inspect.isclass):
108 # Get the first one with parent BasicMetrics
109 member_parent = member[1].__bases__[0]
110 if 'BasicMetric' in str(member_parent):
111 return member[1]
112
113 print("No child class of BasicMetric was found ... Exiting")
114 sys.exit(-1)
115
116 def _get_recorder_map(self, recorder_str):
117 """

Callers 1

__init__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected