Spaces:
Running
Running
Update updated_word.py
Browse files- updated_word.py +34 -17
updated_word.py
CHANGED
|
@@ -570,7 +570,7 @@ def handle_attendance_list_table_enhanced(table, flat_json):
|
|
| 570 |
return replacements_made
|
| 571 |
|
| 572 |
def fix_management_summary_details_column(table, flat_json):
|
| 573 |
-
"""
|
| 574 |
replacements_made = 0
|
| 575 |
print(f" π― FIX: Management Summary DETAILS column processing")
|
| 576 |
|
|
@@ -600,7 +600,7 @@ def fix_management_summary_details_column(table, flat_json):
|
|
| 600 |
for mgmt_type in mgmt_types:
|
| 601 |
print(f" β
Confirmed {mgmt_type} table processing")
|
| 602 |
|
| 603 |
-
#
|
| 604 |
mgmt_data = {}
|
| 605 |
|
| 606 |
# Look for flattened keys like "Mass Management Summary.Std 5. Verification"
|
|
@@ -617,29 +617,38 @@ def fix_management_summary_details_column(table, flat_json):
|
|
| 617 |
|
| 618 |
print(f" π Processing {mgmt_type} with standards: {list(mgmt_data.keys())}")
|
| 619 |
|
| 620 |
-
#
|
|
|
|
|
|
|
| 621 |
for row_idx, row in enumerate(table.rows):
|
| 622 |
if len(row.cells) >= 2:
|
| 623 |
standard_cell = row.cells[0]
|
| 624 |
details_cell = row.cells[1]
|
| 625 |
standard_text = get_clean_text(standard_cell).strip()
|
|
|
|
| 626 |
standard_text_lower = standard_text.lower()
|
| 627 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 628 |
# Skip header rows
|
| 629 |
if any(header in standard_text_lower for header in ["standard", "requirement", "details", "management"]):
|
|
|
|
| 630 |
continue
|
| 631 |
|
| 632 |
-
#
|
| 633 |
if not has_red_text(details_cell):
|
|
|
|
| 634 |
continue
|
| 635 |
|
| 636 |
-
print(f"
|
| 637 |
|
| 638 |
-
#
|
| 639 |
replacement_value = None
|
| 640 |
matched_std = None
|
| 641 |
|
| 642 |
-
# Strategy 1: Extract standard number and match
|
| 643 |
std_match = re.search(r'std\s*(\d+)', standard_text_lower)
|
| 644 |
if std_match:
|
| 645 |
std_num = std_match.group(1)
|
|
@@ -653,8 +662,9 @@ def fix_management_summary_details_column(table, flat_json):
|
|
| 653 |
print(f" β
Found match by std number: '{std_key}'")
|
| 654 |
break
|
| 655 |
|
| 656 |
-
#
|
| 657 |
if not replacement_value:
|
|
|
|
| 658 |
if "daily" in standard_text_lower and "check" in standard_text_lower:
|
| 659 |
replacement_value = find_best_standard_value(mgmt_data, ["Std 1. Daily Check", "Daily Check"])
|
| 660 |
matched_std = "Daily Check related"
|
|
@@ -664,17 +674,10 @@ def fix_management_summary_details_column(table, flat_json):
|
|
| 664 |
elif "internal review" in standard_text_lower:
|
| 665 |
replacement_value = find_best_standard_value(mgmt_data, ["Std 6. Internal Review", "Std 7. Internal Review", "Std 5. Internal Review", "Internal Review"])
|
| 666 |
matched_std = "Internal Review related"
|
| 667 |
-
elif "fault" in standard_text_lower and "recording" in standard_text_lower:
|
| 668 |
-
replacement_value = find_best_standard_value(mgmt_data, ["Std 2. Fault Recording", "Fault Recording"])
|
| 669 |
-
matched_std = "Fault Recording related"
|
| 670 |
-
elif "fault" in standard_text_lower and "repair" in standard_text_lower:
|
| 671 |
-
replacement_value = find_best_standard_value(mgmt_data, ["Std 3. Fault Repair", "Fault Repair"])
|
| 672 |
-
matched_std = "Fault Repair related"
|
| 673 |
|
| 674 |
-
#
|
| 675 |
if not replacement_value and mgmt_data:
|
| 676 |
-
print(f" π No specific match,
|
| 677 |
-
# Just take the first available standard for this row
|
| 678 |
for std_key, std_value in mgmt_data.items():
|
| 679 |
replacement_value = std_value
|
| 680 |
matched_std = std_key
|
|
@@ -693,17 +696,31 @@ def fix_management_summary_details_column(table, flat_json):
|
|
| 693 |
replacement_text = str(replacement_value)
|
| 694 |
|
| 695 |
print(f" π― About to replace red text with: '{replacement_text[:100]}...'")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 696 |
cell_replacements = replace_red_text_in_cell(details_cell, replacement_text)
|
| 697 |
replacements_made += cell_replacements
|
| 698 |
|
| 699 |
if cell_replacements > 0:
|
| 700 |
print(f" β
SUCCESSFULLY replaced '{standard_text}' details in {mgmt_type}")
|
| 701 |
print(f" π Used data from: '{matched_std}'")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 702 |
else:
|
| 703 |
print(f" β Failed to replace red text in cell")
|
|
|
|
| 704 |
else:
|
| 705 |
print(f" β οΈ No replacement found for '{standard_text}' in {mgmt_type}")
|
| 706 |
print(f" π Available standards: {list(mgmt_data.keys())}")
|
|
|
|
|
|
|
| 707 |
|
| 708 |
print(f" π Total management summary replacements: {replacements_made}")
|
| 709 |
return replacements_made
|
|
|
|
| 570 |
return replacements_made
|
| 571 |
|
| 572 |
def fix_management_summary_details_column(table, flat_json):
|
| 573 |
+
"""DEBUG VERSION: Enhanced management summary processing with detailed debugging - FIXED FOR FLATTENED JSON"""
|
| 574 |
replacements_made = 0
|
| 575 |
print(f" π― FIX: Management Summary DETAILS column processing")
|
| 576 |
|
|
|
|
| 600 |
for mgmt_type in mgmt_types:
|
| 601 |
print(f" β
Confirmed {mgmt_type} table processing")
|
| 602 |
|
| 603 |
+
# Build management data dict from flattened keys
|
| 604 |
mgmt_data = {}
|
| 605 |
|
| 606 |
# Look for flattened keys like "Mass Management Summary.Std 5. Verification"
|
|
|
|
| 617 |
|
| 618 |
print(f" π Processing {mgmt_type} with standards: {list(mgmt_data.keys())}")
|
| 619 |
|
| 620 |
+
# DEBUG: Check every row in the table
|
| 621 |
+
print(f" π Analyzing all {len(table.rows)} rows in table:")
|
| 622 |
+
|
| 623 |
for row_idx, row in enumerate(table.rows):
|
| 624 |
if len(row.cells) >= 2:
|
| 625 |
standard_cell = row.cells[0]
|
| 626 |
details_cell = row.cells[1]
|
| 627 |
standard_text = get_clean_text(standard_cell).strip()
|
| 628 |
+
details_text = get_clean_text(details_cell).strip()
|
| 629 |
standard_text_lower = standard_text.lower()
|
| 630 |
|
| 631 |
+
print(f" π Row {row_idx + 1}:")
|
| 632 |
+
print(f" π Standard: '{standard_text}'")
|
| 633 |
+
print(f" π Details: '{details_text[:50]}...' (length: {len(details_text)})")
|
| 634 |
+
print(f" π΄ Has red text: {has_red_text(details_cell)}")
|
| 635 |
+
|
| 636 |
# Skip header rows
|
| 637 |
if any(header in standard_text_lower for header in ["standard", "requirement", "details", "management"]):
|
| 638 |
+
print(f" βοΈ Skipping header row")
|
| 639 |
continue
|
| 640 |
|
| 641 |
+
# Check if this row has red text
|
| 642 |
if not has_red_text(details_cell):
|
| 643 |
+
print(f" βοΈ No red text found, skipping")
|
| 644 |
continue
|
| 645 |
|
| 646 |
+
print(f" π― PROCESSING row {row_idx + 1}: '{standard_text}'")
|
| 647 |
|
| 648 |
+
# Extract standard number and match
|
| 649 |
replacement_value = None
|
| 650 |
matched_std = None
|
| 651 |
|
|
|
|
| 652 |
std_match = re.search(r'std\s*(\d+)', standard_text_lower)
|
| 653 |
if std_match:
|
| 654 |
std_num = std_match.group(1)
|
|
|
|
| 662 |
print(f" β
Found match by std number: '{std_key}'")
|
| 663 |
break
|
| 664 |
|
| 665 |
+
# Keyword-based matching if std number doesn't work
|
| 666 |
if not replacement_value:
|
| 667 |
+
print(f" π No std number match, trying keyword matching...")
|
| 668 |
if "daily" in standard_text_lower and "check" in standard_text_lower:
|
| 669 |
replacement_value = find_best_standard_value(mgmt_data, ["Std 1. Daily Check", "Daily Check"])
|
| 670 |
matched_std = "Daily Check related"
|
|
|
|
| 674 |
elif "internal review" in standard_text_lower:
|
| 675 |
replacement_value = find_best_standard_value(mgmt_data, ["Std 6. Internal Review", "Std 7. Internal Review", "Std 5. Internal Review", "Internal Review"])
|
| 676 |
matched_std = "Internal Review related"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 677 |
|
| 678 |
+
# Last resort: use any available standard
|
| 679 |
if not replacement_value and mgmt_data:
|
| 680 |
+
print(f" π No specific match, using first available standard...")
|
|
|
|
| 681 |
for std_key, std_value in mgmt_data.items():
|
| 682 |
replacement_value = std_value
|
| 683 |
matched_std = std_key
|
|
|
|
| 696 |
replacement_text = str(replacement_value)
|
| 697 |
|
| 698 |
print(f" π― About to replace red text with: '{replacement_text[:100]}...'")
|
| 699 |
+
|
| 700 |
+
# DEBUG: Show red text segments before replacement
|
| 701 |
+
red_segments = extract_red_text_segments(details_cell)
|
| 702 |
+
print(f" π Found {len(red_segments)} red text segments:")
|
| 703 |
+
for i, segment in enumerate(red_segments):
|
| 704 |
+
print(f" Segment {i+1}: '{segment['text'][:50]}...'")
|
| 705 |
+
|
| 706 |
cell_replacements = replace_red_text_in_cell(details_cell, replacement_text)
|
| 707 |
replacements_made += cell_replacements
|
| 708 |
|
| 709 |
if cell_replacements > 0:
|
| 710 |
print(f" β
SUCCESSFULLY replaced '{standard_text}' details in {mgmt_type}")
|
| 711 |
print(f" π Used data from: '{matched_std}'")
|
| 712 |
+
|
| 713 |
+
# Verify the replacement worked
|
| 714 |
+
new_details_text = get_clean_text(details_cell).strip()
|
| 715 |
+
print(f" π New details text: '{new_details_text[:100]}...'")
|
| 716 |
else:
|
| 717 |
print(f" β Failed to replace red text in cell")
|
| 718 |
+
print(f" π Cell still contains: '{get_clean_text(details_cell)[:100]}...'")
|
| 719 |
else:
|
| 720 |
print(f" β οΈ No replacement found for '{standard_text}' in {mgmt_type}")
|
| 721 |
print(f" π Available standards: {list(mgmt_data.keys())}")
|
| 722 |
+
else:
|
| 723 |
+
print(f" β οΈ Row {row_idx + 1} has insufficient columns ({len(row.cells)})")
|
| 724 |
|
| 725 |
print(f" π Total management summary replacements: {replacements_made}")
|
| 726 |
return replacements_made
|