From 11737a937a9fd98447afa6dbcafd2c443fef0fff Mon Sep 17 00:00:00 2001 From: baydakov-georgiy Date: Thu, 14 Aug 2025 16:48:40 +0500 Subject: [PATCH 1/5] added criteria for aspect ratio (433) --- .../presentation_checks/aspect_ratio_check.py | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 app/main/checks/presentation_checks/aspect_ratio_check.py diff --git a/app/main/checks/presentation_checks/aspect_ratio_check.py b/app/main/checks/presentation_checks/aspect_ratio_check.py new file mode 100644 index 00000000..4230c637 --- /dev/null +++ b/app/main/checks/presentation_checks/aspect_ratio_check.py @@ -0,0 +1,52 @@ +import math + +from ..base_check import BasePresCriterion, answer + + +class Ratio(): + ASPECT_RATIO_EPSILON = 0.01 + + def __init__(self, width, height): + self.width = width + self.height = height + if height == 0: + self.value = 0 + else: + self.value = width / height + + def __eq__(self, other): + return math.isclose(self.value, other.value, rel_tol=self.ASPECT_RATIO_EPSILON) + + def __str__(self): + gcd_value = math.gcd(self.width, self.height) + if gcd_value == 0: + return "0:0" + simplified_width = self.width // gcd_value + simplified_height = self.height // gcd_value + return f'{simplified_width}:{simplified_height}' + + +class PresAspectRatioCheck(BasePresCriterion): + label = "Проверка соотношения сторон слайда" + description = "" + id = 'pres_aspect_ratio_check' + + def __init__(self, file_info, correct_ratios=[Ratio(4, 3), Ratio(16, 9)]): + super().__init__(file_info) + self.correct_ratios = correct_ratios + + def _is_correct_ratio(self, aspect_ratio: Ratio): + return any(aspect_ratio == ratio for ratio in self.correct_ratios) + + def check(self): + width = self.file.prs.slide_width + height = self.file.prs.slide_height + + aspect_ratio = Ratio(width, height) + + if self._is_correct_ratio(aspect_ratio): + return answer(True, f"Соотношение сторон слайдов ({aspect_ratio}) соответствует стандарту.") + + correct_ratios_str = ", ".join(map(str, self.correct_ratios)) + return answer(False, + f'Соотношение сторон слайдов ({aspect_ratio}) не соответствует стандарту ({correct_ratios_str}).') \ No newline at end of file From 3b52a70f79336235963b0c49038dc06776e314ca Mon Sep 17 00:00:00 2001 From: baydakov-georgiy Date: Tue, 14 Oct 2025 19:39:01 +0300 Subject: [PATCH 2/5] changed correct_ratios param --- .../checks/presentation_checks/aspect_ratio_check.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/main/checks/presentation_checks/aspect_ratio_check.py b/app/main/checks/presentation_checks/aspect_ratio_check.py index 4230c637..fc22ac74 100644 --- a/app/main/checks/presentation_checks/aspect_ratio_check.py +++ b/app/main/checks/presentation_checks/aspect_ratio_check.py @@ -2,8 +2,7 @@ from ..base_check import BasePresCriterion, answer - -class Ratio(): +class Ratio: ASPECT_RATIO_EPSILON = 0.01 def __init__(self, width, height): @@ -31,11 +30,11 @@ class PresAspectRatioCheck(BasePresCriterion): description = "" id = 'pres_aspect_ratio_check' - def __init__(self, file_info, correct_ratios=[Ratio(4, 3), Ratio(16, 9)]): + def __init__(self, file_info, correct_ratios=["4:3", "16:9"]): super().__init__(file_info) - self.correct_ratios = correct_ratios + self.correct_ratios = [Ratio(*map(int, x.split(':'))) for x in correct_ratios] - def _is_correct_ratio(self, aspect_ratio: Ratio): + def __is_correct_ratio(self, aspect_ratio: Ratio): return any(aspect_ratio == ratio for ratio in self.correct_ratios) def check(self): @@ -44,7 +43,7 @@ def check(self): aspect_ratio = Ratio(width, height) - if self._is_correct_ratio(aspect_ratio): + if self.__is_correct_ratio(aspect_ratio): return answer(True, f"Соотношение сторон слайдов ({aspect_ratio}) соответствует стандарту.") correct_ratios_str = ", ".join(map(str, self.correct_ratios)) From db29e5f211a86cfe8a95236f28a48e7f22b27495 Mon Sep 17 00:00:00 2001 From: baydakov-georgiy Date: Fri, 30 Jan 2026 00:29:57 +0300 Subject: [PATCH 3/5] added usage set for ratios --- app/main/checks/presentation_checks/__init__.py | 1 + .../presentation_checks/aspect_ratio_check.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/main/checks/presentation_checks/__init__.py b/app/main/checks/presentation_checks/__init__.py index 52bd5f73..e738355d 100644 --- a/app/main/checks/presentation_checks/__init__.py +++ b/app/main/checks/presentation_checks/__init__.py @@ -17,3 +17,4 @@ from .name_of_image_check import PresImageCaptureCheck from .task_tracker import TaskTracker from .overview_in_tasks import OverviewInTasks +from .aspect_ratio_check import PresAspectRatioCheck \ No newline at end of file diff --git a/app/main/checks/presentation_checks/aspect_ratio_check.py b/app/main/checks/presentation_checks/aspect_ratio_check.py index fc22ac74..ac1fa7fd 100644 --- a/app/main/checks/presentation_checks/aspect_ratio_check.py +++ b/app/main/checks/presentation_checks/aspect_ratio_check.py @@ -3,7 +3,7 @@ from ..base_check import BasePresCriterion, answer class Ratio: - ASPECT_RATIO_EPSILON = 0.01 + ASCPECT_RATIO_PRECISION = 2 def __init__(self, width, height): self.width = width @@ -11,10 +11,13 @@ def __init__(self, width, height): if height == 0: self.value = 0 else: - self.value = width / height + self.value = round(width / height, self.ASCPECT_RATIO_PRECISION) def __eq__(self, other): - return math.isclose(self.value, other.value, rel_tol=self.ASPECT_RATIO_EPSILON) + return self.value == other.value + + def __hash__(self): + return hash(self.value) def __str__(self): gcd_value = math.gcd(self.width, self.height) @@ -30,12 +33,12 @@ class PresAspectRatioCheck(BasePresCriterion): description = "" id = 'pres_aspect_ratio_check' - def __init__(self, file_info, correct_ratios=["4:3", "16:9"]): + def __init__(self, file_info, correct_ratios=("16:9", "4:3")): super().__init__(file_info) - self.correct_ratios = [Ratio(*map(int, x.split(':'))) for x in correct_ratios] + self.correct_ratios = set(Ratio(*map(int, x.split(':'))) for x in correct_ratios) def __is_correct_ratio(self, aspect_ratio: Ratio): - return any(aspect_ratio == ratio for ratio in self.correct_ratios) + return aspect_ratio in self.correct_ratios def check(self): width = self.file.prs.slide_width From 96adc7cc1b2c498f6386c23e55008f7dcea5d16e Mon Sep 17 00:00:00 2001 From: baydakov-georgiy Date: Wed, 25 Mar 2026 17:49:07 +0300 Subject: [PATCH 4/5] fixed hint for aspect ratio check --- app/main/check_packs/pack_config.py | 1 + .../presentation_checks/aspect_ratio_check.py | 36 ++++++++++++++----- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/app/main/check_packs/pack_config.py b/app/main/check_packs/pack_config.py index d2579f6d..31c6e52a 100644 --- a/app/main/check_packs/pack_config.py +++ b/app/main/check_packs/pack_config.py @@ -22,6 +22,7 @@ ['pres_image_capture'], ['task_tracker'], ['overview_in_tasks'], + ['pres_aspect_ratio_check'], ] BASE_REPORT_CRITERION = [ ["simple_check"], diff --git a/app/main/checks/presentation_checks/aspect_ratio_check.py b/app/main/checks/presentation_checks/aspect_ratio_check.py index ac1fa7fd..c9defdca 100644 --- a/app/main/checks/presentation_checks/aspect_ratio_check.py +++ b/app/main/checks/presentation_checks/aspect_ratio_check.py @@ -2,6 +2,7 @@ from ..base_check import BasePresCriterion, answer + class Ratio: ASCPECT_RATIO_PRECISION = 2 @@ -25,21 +26,35 @@ def __str__(self): return "0:0" simplified_width = self.width // gcd_value simplified_height = self.height // gcd_value - return f'{simplified_width}:{simplified_height}' + return f"{simplified_width}:{simplified_height}" class PresAspectRatioCheck(BasePresCriterion): label = "Проверка соотношения сторон слайда" - description = "" - id = 'pres_aspect_ratio_check' + id = "pres_aspect_ratio_check" def __init__(self, file_info, correct_ratios=("16:9", "4:3")): super().__init__(file_info) - self.correct_ratios = set(Ratio(*map(int, x.split(':'))) for x in correct_ratios) + self.correct_ratios = set( + Ratio(*map(int, x.split(":"))) for x in correct_ratios + ) def __is_correct_ratio(self, aspect_ratio: Ratio): return aspect_ratio in self.correct_ratios + def __convert_size_to_pixels(self, size, dpi=96): + return math.trunc(size.inches * dpi) + + def __get_correct_instruction(self, aspect_ratio): + correct_ratios_str = ", ".join(map(str, self.correct_ratios)) + width = self.__convert_size_to_pixels(aspect_ratio.width) + height = self.__convert_size_to_pixels(aspect_ratio.height) + return ( + f"Соотношение сторон слайдов ({width}x{height}) не соответствует стандарту
" + "Рекомендации по исправлению:
" + f"Измените соотношение сторон презентации на одно из доступных ({correct_ratios_str})" + ) + def check(self): width = self.file.prs.slide_width height = self.file.prs.slide_height @@ -47,8 +62,13 @@ def check(self): aspect_ratio = Ratio(width, height) if self.__is_correct_ratio(aspect_ratio): - return answer(True, f"Соотношение сторон слайдов ({aspect_ratio}) соответствует стандарту.") + return answer( + True, + f"Соотношение сторон слайдов ({aspect_ratio}) соответствует стандарту.", + ) + + return answer( + False, + self.__get_correct_instruction(aspect_ratio) + ) - correct_ratios_str = ", ".join(map(str, self.correct_ratios)) - return answer(False, - f'Соотношение сторон слайдов ({aspect_ratio}) не соответствует стандарту ({correct_ratios_str}).') \ No newline at end of file From ddad5f646d7563f3bee545216c8415b26a3d509d Mon Sep 17 00:00:00 2001 From: baydakov-georgiy Date: Wed, 25 Mar 2026 17:55:58 +0300 Subject: [PATCH 5/5] formatted code --- .../presentation_checks/aspect_ratio_check.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/main/checks/presentation_checks/aspect_ratio_check.py b/app/main/checks/presentation_checks/aspect_ratio_check.py index c9defdca..f097b511 100644 --- a/app/main/checks/presentation_checks/aspect_ratio_check.py +++ b/app/main/checks/presentation_checks/aspect_ratio_check.py @@ -50,9 +50,13 @@ def __get_correct_instruction(self, aspect_ratio): width = self.__convert_size_to_pixels(aspect_ratio.width) height = self.__convert_size_to_pixels(aspect_ratio.height) return ( - f"Соотношение сторон слайдов ({width}x{height}) не соответствует стандарту
" + f"Соотношение сторон слайдов ({width}x{ + height + }) не соответствует стандарту
" "Рекомендации по исправлению:
" - f"Измените соотношение сторон презентации на одно из доступных ({correct_ratios_str})" + f"Измените соотношение сторон презентации на одно из доступных ({ + correct_ratios_str + })" ) def check(self): @@ -67,8 +71,4 @@ def check(self): f"Соотношение сторон слайдов ({aspect_ratio}) соответствует стандарту.", ) - return answer( - False, - self.__get_correct_instruction(aspect_ratio) - ) - + return answer(False, self.__get_correct_instruction(aspect_ratio))