Reverting Back to Working Branch

This commit is contained in:
brotoskyj
2025-08-25 12:14:58 -04:00
4 changed files with 65 additions and 36 deletions
+28
View File
@@ -57,9 +57,12 @@ def filepathInitialGroup(df: pd.DataFrame):
break
return join_parts(prefix)
<<<<<<< HEAD
<<<<<<< HEAD
# Step 6: Group directories by shared prefix
=======
=======
>>>>>>> b187d8cd79c04d364185a4e366d0432841a3372a
# Step 6: Group directories by shared prefix using custom logic
"""
Loop through each directory path
@@ -67,7 +70,10 @@ def filepathInitialGroup(df: pd.DataFrame):
groups: will hold lists of grouped directories.
used: tracks which directories have already been grouped.
"""
<<<<<<< HEAD
>>>>>>> ccbf716 (Zar-Branch (#6))
=======
>>>>>>> b187d8cd79c04d364185a4e366d0432841a3372a
directories = df["directory"].tolist()
groups = []
used = set()
@@ -85,6 +91,7 @@ def filepathInitialGroup(df: pd.DataFrame):
group = [path]
parts_i = get_parts(path)
<<<<<<< HEAD
<<<<<<< HEAD
for j in range(i + 1, len(directories)):
parts_j = get_parts(directories[j])
@@ -107,6 +114,23 @@ def filepathInitialGroup(df: pd.DataFrame):
common = os.path.commonprefix([parts_i, parts_j])
#Apply grouping rules
>>>>>>> ccbf716 (Zar-Branch (#6))
=======
#Compare with all other directories: For each other directory, split it into parts and find the common prefix (shared folder structure).
"""
Logic:
If the directory is deep (>3 parts) and shares at least 3 parts → group it.
If it's exactly 3 parts long and shares at least 2 → group it.
Or, if it shares all but one part and is deep → group it.
These rules are designed to:
Group directories that are closely related in structure.
Avoid grouping unrelated paths that just happen to start similarly.
"""
for j in range(i + 1, len(directories)):
parts_j = get_parts(directories[j])
common = os.path.commonprefix([parts_i, parts_j])
#Apply grouping rules
>>>>>>> b187d8cd79c04d364185a4e366d0432841a3372a
if (len(parts_i) > 3 and len(common) >= 3) or (len(parts_i) == 3 and len(common) >= 2):
group.append(directories[j])
used.add(directories[j])
@@ -134,11 +158,15 @@ def filepathInitialGroup(df: pd.DataFrame):
path_eligible = grouped_df[grouped_df["depth"] > 2].drop(columns=["depth"])
path_ineligible = grouped_df[grouped_df["depth"] <= 2].drop(columns=["depth"])
<<<<<<< HEAD
<<<<<<< HEAD
# Step 10: Move entries from eligible to ineligible if grouped_directory contains excluded directories
=======
# Step 10: Move entries from eligible to ineligible if grouped_directory contains 'C:\Users' or 'c$\Users'
>>>>>>> ccbf716 (Zar-Branch (#6))
=======
# Step 10: Move entries from eligible to ineligible if grouped_directory contains 'C:\Users' or 'c$\Users'
>>>>>>> b187d8cd79c04d364185a4e366d0432841a3372a
mask = path_eligible["grouped_directory"].str.contains(r"(?i)(?:\\Users|\\c\$\\Users|inetpub\\wwwroot|windows\\temp)", na=False)
move_to_ineligible = path_eligible[mask]
path_eligible = path_eligible[~mask]