fix: Enhance error handling and logging across multiple evaluators
- Added logging for file retrieval and error handling in file.py, improving robustness during file operations. - Implemented checks for file existence and parsing errors in general.py, enhancing reliability in JSON/YAML processing. - Improved table comparison logic in table.py with detailed error logging for sheet loading and cell value reading. - Enhanced metrics evaluation in slides.py with additional checks for paragraph and run counts, ensuring thorough comparison. - Updated utils.py to include file existence checks and detailed error logging during cell value reading.
This commit is contained in:
@@ -73,6 +73,9 @@ def check_image_stretch_and_center(modified_ppt, original_ppt):
|
||||
original_slide_images = [shape for shape in original_slide.shapes if shape.shape_type == 13]
|
||||
modified_slide_images = [shape for shape in modified_slide.shapes if shape.shape_type == 13]
|
||||
|
||||
if not original_slide_images:
|
||||
return 0.
|
||||
|
||||
the_image = original_slide_images[0]
|
||||
|
||||
the_modified_image = None
|
||||
@@ -395,12 +398,38 @@ def compare_pptx_files(file1_path, file2_path, **options):
|
||||
table2 = shape2.table
|
||||
if enable_debug:
|
||||
debug_logger.debug(f" Shape {shape_idx} - Comparing TABLE with {len(table1.rows)} rows and {len(table1.columns)} columns")
|
||||
debug_logger.debug(f" Shape {shape_idx} - Table2 has {len(table2.rows)} rows and {len(table2.columns)} columns")
|
||||
|
||||
# Check if tables have the same dimensions
|
||||
if len(table1.rows) != len(table2.rows) or len(table1.columns) != len(table2.columns):
|
||||
if enable_debug:
|
||||
debug_logger.debug(f" MISMATCH: Slide {slide_idx}, Shape {shape_idx} (TABLE) - Table dimensions differ:")
|
||||
debug_logger.debug(f" Table1: {len(table1.rows)} rows x {len(table1.columns)} columns")
|
||||
debug_logger.debug(f" Table2: {len(table2.rows)} rows x {len(table2.columns)} columns")
|
||||
return 0
|
||||
|
||||
for row_idx in range(len(table1.rows)):
|
||||
for col_idx in range(len(table1.columns)):
|
||||
cell1 = table1.cell(row_idx, col_idx)
|
||||
cell2 = table2.cell(row_idx, col_idx)
|
||||
|
||||
# Check if cells have the same number of paragraphs
|
||||
if len(cell1.text_frame.paragraphs) != len(cell2.text_frame.paragraphs):
|
||||
if enable_debug:
|
||||
debug_logger.debug(f" MISMATCH: Slide {slide_idx}, Shape {shape_idx} (TABLE) - Cell [{row_idx},{col_idx}] - Different number of paragraphs:")
|
||||
debug_logger.debug(f" Cell1 paragraphs: {len(cell1.text_frame.paragraphs)}")
|
||||
debug_logger.debug(f" Cell2 paragraphs: {len(cell2.text_frame.paragraphs)}")
|
||||
return 0
|
||||
|
||||
for para_idx, (para1, para2) in enumerate(zip(cell1.text_frame.paragraphs, cell2.text_frame.paragraphs)):
|
||||
# Check if paragraphs have the same number of runs
|
||||
if len(para1.runs) != len(para2.runs):
|
||||
if enable_debug:
|
||||
debug_logger.debug(f" MISMATCH: Slide {slide_idx}, Shape {shape_idx} (TABLE) - Cell [{row_idx},{col_idx}], Para {para_idx} - Different number of runs:")
|
||||
debug_logger.debug(f" Para1 runs: {len(para1.runs)}")
|
||||
debug_logger.debug(f" Para2 runs: {len(para2.runs)}")
|
||||
return 0
|
||||
|
||||
for run_idx, (run1, run2) in enumerate(zip(para1.runs, para2.runs)):
|
||||
# Check font color
|
||||
if hasattr(run1.font.color, "rgb") and hasattr(run2.font.color, "rgb"):
|
||||
@@ -451,6 +480,14 @@ def compare_pptx_files(file1_path, file2_path, **options):
|
||||
if shape1.text.strip() != shape2.text.strip() and examine_text:
|
||||
return 0
|
||||
|
||||
# check if the number of paragraphs are the same
|
||||
if len(shape1.text_frame.paragraphs) != len(shape2.text_frame.paragraphs):
|
||||
if enable_debug:
|
||||
debug_logger.debug(f" MISMATCH: Slide {slide_idx}, Shape {shape_idx} - Different number of paragraphs:")
|
||||
debug_logger.debug(f" Shape1 paragraphs: {len(shape1.text_frame.paragraphs)}")
|
||||
debug_logger.debug(f" Shape2 paragraphs: {len(shape2.text_frame.paragraphs)}")
|
||||
return 0
|
||||
|
||||
# check if the paragraphs are the same
|
||||
para_idx = 0
|
||||
for para1, para2 in zip(shape1.text_frame.paragraphs, shape2.text_frame.paragraphs):
|
||||
@@ -487,6 +524,14 @@ def compare_pptx_files(file1_path, file2_path, **options):
|
||||
if para1.level != para2.level and examine_indent:
|
||||
return 0
|
||||
|
||||
# check if the number of runs are the same
|
||||
if len(para1.runs) != len(para2.runs):
|
||||
if enable_debug:
|
||||
debug_logger.debug(f" MISMATCH: Slide {slide_idx}, Shape {shape_idx}, Para {para_idx} - Different number of runs:")
|
||||
debug_logger.debug(f" Para1 runs: {len(para1.runs)}")
|
||||
debug_logger.debug(f" Para2 runs: {len(para2.runs)}")
|
||||
return 0
|
||||
|
||||
for run1, run2 in zip(para1.runs, para2.runs):
|
||||
|
||||
# check if the font properties are the same
|
||||
@@ -634,6 +679,12 @@ def compare_pptx_files(file1_path, file2_path, **options):
|
||||
debug_logger.debug(f" MISMATCH: Text differs - '{tshape1.text.strip()}' vs '{tshape2.text.strip()}'")
|
||||
return 0
|
||||
|
||||
# Check if text shapes have the same number of paragraphs
|
||||
if len(tshape1.text_frame.paragraphs) != len(tshape2.text_frame.paragraphs):
|
||||
if enable_debug:
|
||||
debug_logger.debug(f" MISMATCH: Different number of paragraphs - {len(tshape1.text_frame.paragraphs)} vs {len(tshape2.text_frame.paragraphs)}")
|
||||
return 0
|
||||
|
||||
# Compare alignment of each paragraph
|
||||
for para_idx, (para1, para2) in enumerate(zip(tshape1.text_frame.paragraphs, tshape2.text_frame.paragraphs)):
|
||||
from pptx.enum.text import PP_ALIGN
|
||||
|
||||
Reference in New Issue
Block a user