| import os | |
| import pandas as pd | |
| def replace_empty_performance(directories, performance_column="performance"): | |
| for directory in directories: | |
| if not os.path.exists(directory): | |
| print(f"Directory {directory} does not exist, skipping...") | |
| continue | |
| csv_files = [f for f in os.listdir(directory) if f.endswith('.csv')] | |
| for file in csv_files: | |
| file_path = os.path.join(directory, file) | |
| try: | |
| print(f"Processing {file_path}...") | |
| opt_step = { | |
| 8: 0, | |
| 12: 1, | |
| 14: 2, | |
| 15: 3, | |
| 21: 4, | |
| 24: 5, | |
| 25: 6, | |
| 29: 7, | |
| 31: 8, | |
| 35: 9, | |
| } | |
| # Read CSV file | |
| df = pd.read_csv(file_path) | |
| def get_opt_step(config_id): | |
| remainder = config_id % 35 | |
| for key, value in opt_step.items(): | |
| if remainder < key: | |
| return value + (config_id // 35) * 10 | |
| assert False | |
| df["optimization_step"] = df["config_id"].map(get_opt_step) | |
| df.to_csv(file_path, index=False) | |
| print(f"Saved processed file: {file_path}\n") | |
| except Exception as e: | |
| print(f"Error processing {file_path}: {e}") | |
| if __name__ == "__main__": | |
| directories = ["smac_mf"] | |
| replace_empty_performance(directories) | |