From c28e79b022cdba4aa2fc229658a5bbdefa424a9a Mon Sep 17 00:00:00 2001 From: nuluh Date: Sun, 16 Mar 2025 10:57:13 +0700 Subject: [PATCH] feat(convert): add prefix parameter to create_damage_files for customizable file naming Closes #31 --- data/QUGS/convert.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/data/QUGS/convert.py b/data/QUGS/convert.py index 9dc22c9..731cd38 100644 --- a/data/QUGS/convert.py +++ b/data/QUGS/convert.py @@ -3,7 +3,7 @@ import os import sys from colorama import Fore, Style, init -def create_damage_files(base_path, output_base): +def create_damage_files(base_path, output_base, prefix): # Initialize colorama init(autoreset=True) @@ -27,12 +27,12 @@ def create_damage_files(base_path, output_base): for damage, files in damage_scenarios.items(): for i, file_index in enumerate(files, start=1): # Load original data file - file_path = os.path.join(base_path, f'zzzAD{file_index}.TXT') + file_path = os.path.join(base_path, f'zzz{prefix}D{file_index}.TXT') df = pd.read_csv(file_path, sep='\t', skiprows=10) # Read with explicit column names top_sensor = columns[i-1] print(top_sensor, type(top_sensor)) - output_file_1 = os.path.join(output_base, f'DAMAGE_{damage}', f'DAMAGE_{damage}_TEST{i}_01.csv') + output_file_1 = os.path.join(output_base, f'DAMAGE_{damage}', f'DAMAGE{damage}_TEST{i}_01.csv') print(f"Creating {output_file_1} from taking zzzAD{file_index}.TXT") print("Taking datetime column on index 0...") print(f"Taking `{top_sensor}`...") @@ -40,7 +40,7 @@ def create_damage_files(base_path, output_base): print(Fore.GREEN + "Done") bottom_sensor = sensor_end_map[i] - output_file_2 = os.path.join(output_base, f'DAMAGE_{damage}', f'DAMAGE_{damage}_TEST{i}_02.csv') + output_file_2 = os.path.join(output_base, f'DAMAGE_{damage}', f'DAMAGE{damage}_TEST{i}_02.csv') print(f"Creating {output_file_2} from taking zzzAD{file_index}.TXT") print("Taking datetime column on index 0...") print(f"Taking `{bottom_sensor}`...") @@ -54,13 +54,14 @@ def main(): sys.exit(1) base_path = sys.argv[1] - output_base = sys.argv[2] # Define output directory + output_base = sys.argv[2] + prefix = sys.argv[3] # Define output directory # Create output folders if they don't exist for i in range(1, 5): os.makedirs(os.path.join(output_base, f'DAMAGE_{i}'), exist_ok=True) - create_damage_files(base_path, output_base) + create_damage_files(base_path, output_base, prefix) print(Fore.YELLOW + Style.BRIGHT + "All files have been created successfully.") if __name__ == "__main__":