patch: minor bug fixes for evaluator and task configurations, documentation update (#121)

* fix: /cursor_position api return format fix

* chore: update README.md to remove deprecated command

* fix: add base score for evaluators and minor bug fixes

* fix: add base score for setup configurations

---------

Co-authored-by: Jiaqi Deng <jiaqideng@Jiaqis-MacBook-Pro.local>
This commit is contained in:
MillanK
2025-01-18 22:25:18 +08:00
committed by GitHub
parent 89426951c9
commit 983283a86a
13 changed files with 115 additions and 20 deletions

View File

@@ -167,9 +167,20 @@ def compare_pptx_files(file1_path, file2_path, **options):
slide_idx += 1
def get_slide_background_color(slide):
background = slide.background
if background.fill.background():
return background.fill.fore_color.rgb
# background = slide.background
# if background.fill.background():
# return background.fill.fore_color.rgb
# else:
# return None
fill = slide.background.fill
if fill.type == 1:
return fill.fore_color.rgb
elif fill.type == 5:
master_fill = slide.slide_layout.slide_master.background.fill
if master_fill.type == 1:
return master_fill.fore_color.rgb
else:
return None
else:
return None
@@ -185,6 +196,11 @@ def compare_pptx_files(file1_path, file2_path, **options):
if get_slide_notes(slide1).strip() != get_slide_notes(slide2).strip() and examine_note:
return 0
# check if the number of slides is the same
if len(slide1.shapes) != len(slide2.shapes):
return 0
# check if the shapes are the same
for shape1, shape2 in zip(slide1.shapes, slide2.shapes):
if examine_title_bottom_position:
@@ -363,11 +379,22 @@ def check_slide_orientation_Portrait(pptx_path):
def evaluate_presentation_fill_to_rgb_distance(pptx_file, rules):
rgb = rules["rgb"]
def slide_fill_distance_to_rgb(_slide, _rgb):
try:
original_rgb = rules["original_rgb"]
except:
original_rgb = None
def slide_fill_distance_to_rgb(_slide, _rgb, _original_rgb):
fill = _slide.background.fill
if fill.type == 1:
r1, g1, b1 = fill.fore_color.rgb
r2, g2, b2 = _rgb
if _original_rgb is not None:
r3, g3, b3 = _original_rgb
if r1 == r3 and g1 == g3 and b1 == b3:
return 1
return sqrt((r1 - r2) ** 2 + (g1 - g2) ** 2 + (b1 - b2) ** 2) / sqrt(255 ** 2 + 255 ** 2 + 255 ** 2)
elif fill.type == 5:
master_fill = _slide.slide_layout.slide_master.background.fill
@@ -376,12 +403,18 @@ def evaluate_presentation_fill_to_rgb_distance(pptx_file, rules):
else:
return 1
r2, g2, b2 = _rgb
if _original_rgb is not None:
r3, g3, b3 = _original_rgb
if r1 == r3 and g1 == g3 and b1 == b3:
return 1
return sqrt((r1 - r2) ** 2 + (g1 - g2) ** 2 + (b1 - b2) ** 2) / sqrt(255 ** 2 + 255 ** 2 + 255 ** 2)
return 1
prs = Presentation(pptx_file)
similarity = 1 - sum(slide_fill_distance_to_rgb(slide, rgb) for slide in prs.slides) / len(prs.slides)
similarity = 1 - sum(slide_fill_distance_to_rgb(slide, rgb, original_rgb) for slide in prs.slides) / len(prs.slides)
return similarity