refactor(data): update generate_df_tuples function for improved readibility code

This commit is contained in:
nuluh
2025-06-26 10:51:29 +07:00
parent 9921d7663b
commit c98c6a091b

View File

@@ -26,7 +26,7 @@ class DamageFilesIndices(TypedDict):
files: List[str] 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): special_groups=None, group=True):
""" """
Generate a structured list of tuples containing DataFrame references and column indices. 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
List of tuples, where each tuple contains (df_name, [first_col, last_col]) List of tuples, where each tuple contains (df_name, [first_col, last_col])
""" """
tuples = [] result = []
# 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]))
if group: if group:
# Group tuples into sublists of group_size # Group tuples into sublists of group_size
grouped_tuples = [] for g in range(6): # TODO: shouldnt be hardcoded
for i in range(0, len(tuples), group_size): group = []
grouped_tuples.append(tuples[i:i + group_size]) for i in range(1, 6): # TODO: shouldnt be hardcoded
tuples = grouped_tuples n = g * 5 + i
# tuples.append(list) 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) # Add special groups at specified positions (other than beginning)
if special_groups: if special_groups:
for group in special_groups: for group in special_groups: