diff --git a/clear.py b/clear.py deleted file mode 100644 index c12b90f..0000000 --- a/clear.py +++ /dev/null @@ -1,55 +0,0 @@ -import os -import ast -from concurrent.futures import ThreadPoolExecutor, as_completed - -def find_py_files(root_dir): - py_files = [] - for root, dirs, files in os.walk(root_dir): - for file in files: - if file.endswith('.py'): - py_files.append(os.path.join(root, file)) - return py_files - -def analyze_file(file_path): - with open(file_path, "r", encoding='utf-8') as file: - file_content = file.read() - tree = ast.parse(file_content) - - classes = [node.name for node in ast.walk(tree) if isinstance(node, ast.ClassDef)] - functions = [node.name for node in ast.walk(tree) if isinstance(node, ast.FunctionDef)] - return file_path, classes, functions - -def analyze_projects(root_dir): - py_files = find_py_files(root_dir) - results = [] - - with ThreadPoolExecutor(max_workers=4) as executor: - future_to_file = {executor.submit(analyze_file, file_path): file_path for file_path in py_files} - for future in as_completed(future_to_file): - file_path = future_to_file[future] - try: - results.append(future.result()) - except Exception as exc: - print(f'{file_path} generated an exception: {exc}') - return results - -root_dir = "./" -results = analyze_projects(root_dir) - -result_dict = {} - -for file_path, classes, functions in results: - print(f"File: {file_path}") - print(f"Classes: {classes}") - print(f"Functions: {functions}") - result_dict[file_path] = {} - result_dict[file_path][classes] = 0 - result_dict[file_path][functions] = 0 - result_dict[file_path][functions] = 0 - result_dict[file_path]['count'] = 0 - -import json - -out_file = open("myfile.json", "w") -json.dump(result_dict, out_file, indent = 4) -out_file.close() \ No newline at end of file diff --git a/team_code/uniad_b2d_agent.py b/team_code/uniad_b2d_agent.py index caddd33..97a3d40 100644 --- a/team_code/uniad_b2d_agent.py +++ b/team_code/uniad_b2d_agent.py @@ -186,8 +186,7 @@ def equations(vars): self._route_planner = RoutePlanner(4.0, 50.0, lat_ref=self.lat_ref, lon_ref=self.lon_ref) self._route_planner.set_route(self._global_plan, True) self.initialized = True - - + self.metric_info = {} def sensors(self): sensors =[ @@ -393,7 +392,9 @@ def run_step(self, input_data, timestamp): self.pid_metadata['throttle_traj'] = float(throttle_traj) self.pid_metadata['brake_traj'] = float(brake_traj) self.pid_metadata['plan'] = out_truck.tolist() - if SAVE_PATH is not None and self.step % 10 == 0: + metric_info = self.get_metric_info() + self.metric_info[self.step] = metric_info + if SAVE_PATH is not None and self.step % 1 == 0: self.save(tick_data) self.prev_control = control return control @@ -411,6 +412,11 @@ def save(self, tick_data): json.dump(self.pid_metadata, outfile, indent=4) outfile.close() + # metric info + outfile = open(self.save_path / 'metric_info.json', 'w') + json.dump(self.metric_info, outfile, indent=4) + outfile.close() + def destroy(self): del self.model torch.cuda.empty_cache() diff --git a/team_code/vad_b2d_agent.py b/team_code/vad_b2d_agent.py index a05c807..012b802 100644 --- a/team_code/vad_b2d_agent.py +++ b/team_code/vad_b2d_agent.py @@ -189,6 +189,7 @@ def equations(vars): self._route_planner = RoutePlanner(4.0, 50.0, lat_ref=self.lat_ref, lon_ref=self.lon_ref) self._route_planner.set_route(self._global_plan, True) self.initialized = True + self.metric_info = {} @@ -412,7 +413,9 @@ def run_step(self, input_data, timestamp): self.pid_metadata['command'] = command self.pid_metadata['all_plan'] = all_out_truck.tolist() - if SAVE_PATH is not None and self.step % 10 == 0: + metric_info = self.get_metric_info() + self.metric_info[self.step] = metric_info + if SAVE_PATH is not None and self.step % 1 == 0: self.save(tick_data) self.prev_control = control @@ -437,6 +440,11 @@ def save(self, tick_data): json.dump(self.pid_metadata, outfile, indent=4) outfile.close() + # metric info + outfile = open(self.save_path / 'metric_info.json', 'w') + json.dump(self.metric_info, outfile, indent=4) + outfile.close() + def destroy(self): del self.model torch.cuda.empty_cache()