From c98c6a091b570379bf5f89df8601065eb977c294 Mon Sep 17 00:00:00 2001 From: nuluh Date: Thu, 26 Jun 2025 10:51:29 +0700 Subject: [PATCH] refactor(data): update generate_df_tuples function for improved readibility code --- data/QUGS/convert.py | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/data/QUGS/convert.py b/data/QUGS/convert.py index c86e34c..17af789 100644 --- a/data/QUGS/convert.py +++ b/data/QUGS/convert.py @@ -26,7 +26,7 @@ class DamageFilesIndices(TypedDict): files: List[str] -def generate_df_tuples(total_dfs=30, group_size=5, prefix="zzzAD", ext="TXT", first_col_start=1, last_col_offset=25, +def generate_df_tuples(total_dfs=30, group_size=5, prefix="zzzAD", extension="TXT", first_col_start=1, last_col_offset=25, special_groups=None, group=True): """ Generate a structured list of tuples containing DataFrame references and column indices. @@ -54,30 +54,18 @@ def generate_df_tuples(total_dfs=30, group_size=5, prefix="zzzAD", ext="TXT", fi list List of tuples, where each tuple contains (df_name, [first_col, last_col]) """ - tuples = [] - # Add regular groups - for i in range(1, total_dfs + 1): - # for _ in range(group_size): # group tuple - # temporary list to hold tuples for this group - # list = [] - # Calculate the position within the group (1 to group_size) - position_in_group = ((i - 1) % group_size) + 1 - - # Calculate column indices based on position in group - first_col = first_col_start + position_in_group - 1 - last_col = first_col + last_col_offset - - # Create the tuple with DataFrame reference and column indices - df_name = f"{prefix}{i}.{ext}" - tuples.append((df_name, [first_col, last_col])) - + result = [] if group: # Group tuples into sublists of group_size - grouped_tuples = [] - for i in range(0, len(tuples), group_size): - grouped_tuples.append(tuples[i:i + group_size]) - tuples = grouped_tuples - # tuples.append(list) + for g in range(6): # TODO: shouldnt be hardcoded + group = [] + for i in range(1, 6): # TODO: shouldnt be hardcoded + n = g * 5 + i + bottom = i # 1, 2, 3, 4, 5 + b = a + 25 # 26, 27, 28, 29, 30 # TODO: shouldnt be hardcoded + group.append((f"{prefix}{n}.{extension}", [a, b])) + result.append(group) + # Add special groups at specified positions (other than beginning) if special_groups: for group in special_groups: