From 50be9631eee73e40bd6502888d73934c60aad351 Mon Sep 17 00:00:00 2001 From: Dariiiii Date: Thu, 4 Jul 2024 18:23:40 +0300 Subject: [PATCH] v1.1 --- app/main/check_packs/pack_config.py | 1 + .../checks/presentation_checks/__init__.py | 1 + .../slide_text_volume_check.py | 69 +++++++++++++++++-- 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/app/main/check_packs/pack_config.py b/app/main/check_packs/pack_config.py index 598c3cc2..0e3c3bde 100644 --- a/app/main/check_packs/pack_config.py +++ b/app/main/check_packs/pack_config.py @@ -18,6 +18,7 @@ ['pres_empty_slide'], ['theme_in_pres_check'], ['verify_git_link'], + ['slide_text_volume_check'], ] BASE_REPORT_CRITERION = [ ["simple_check"], diff --git a/app/main/checks/presentation_checks/__init__.py b/app/main/checks/presentation_checks/__init__.py index d605c1d3..f26e20b9 100644 --- a/app/main/checks/presentation_checks/__init__.py +++ b/app/main/checks/presentation_checks/__init__.py @@ -13,3 +13,4 @@ from .find_theme_in_pres import FindThemeInPres from .verify_git_link import PresVerifyGitLinkCheck from .empty_slide_check import PresEmptySlideCheck +from .slide_text_volume_check import SlideTextVolumeCheck \ No newline at end of file diff --git a/app/main/checks/presentation_checks/slide_text_volume_check.py b/app/main/checks/presentation_checks/slide_text_volume_check.py index 049e029f..450b60b3 100644 --- a/app/main/checks/presentation_checks/slide_text_volume_check.py +++ b/app/main/checks/presentation_checks/slide_text_volume_check.py @@ -2,15 +2,15 @@ class SlideTextVolumeCheck(BasePresCriterion): - label = 'Заголовки слайдов не дублируются' - description = 'Проверка на дублируемость заголовков слайдов' + label = 'Проверка объема текста на каждом слайде' + description = 'Объем текста на каждом слайде (за исключением титульного и запасных) должен соответсвовать критериям.' id = 'slide_text_volume_check' - def __init__(self, file_info, min_count_words_on_slide=40, - min_count_paragraphs=2, min_count_words_in_paragraph=20, + def __init__(self, file_info, min_count_words_on_slide=30, + min_count_paragraphs=2, min_count_words_in_paragraph=10, max_count_words_on_slide=100, max_count_paragraphs=5, max_count_words_in_paragraph=50, - slides_with_required_list=["Цели и задачи", "Заключение"]): + slides_with_required_list=["Цель и задачи", "Заключение"]): super().__init__(file_info) self.min_count_words_on_slide = min_count_words_on_slide self.min_count_paragraphs = min_count_paragraphs @@ -22,7 +22,64 @@ def __init__(self, file_info, min_count_words_on_slide=40, def check(self): result_str = '' + text_from_slides = self.file.get_text_from_slides() + titles = self.file.get_titles() + slides_info = [] + if len(titles) == 0 or len(text_from_slides) == 0: + return answer(False, 'Презентация пуста или заголовки не найдены.') + for i in range(len(titles)): + if "Санкт-Петербургский государственный" in titles[i]: + continue + if "Запасные слайды" in titles[i]: + break + required_list = False + if titles[i] in self.slides_with_required_list: + required_list = True + slides_info.append(self.slide_text_analysis(i + 1, text_from_slides[i], required_list)) + for slide_info in slides_info: + res = '' + link = self.format_page_link([slide_info['page']]) + if slide_info['count_words_on_slide'] < self.min_count_words_on_slide: + res += f'Количество слов на слайде: {slide_info["count_words_on_slide"]};
' + elif slide_info['count_words_on_slide'] > self.max_count_words_on_slide: + res += f'Количество слов на слайде: {slide_info["count_words_on_slide"]};
' + if slide_info['count_paragraphs'] < self.min_count_paragraphs: + res += f'Количество абзацев на слайде: {slide_info["count_paragraphs"]};
' + if slide_info['count_paragraphs'] > self.max_count_paragraphs: + res += f'Количество абзацев на слайде: {slide_info["count_paragraphs"]};
' + paragraphs = slide_info['paragraphs'] + for i in range(len(paragraphs)): + if paragraphs[i] < self.min_count_words_in_paragraph: + res += f'Количество слов в абзаце № {i + 1}: {paragraphs[i]};
' + if paragraphs[i] > self.max_count_words_in_paragraph: + res += f'Количество слов в абзаце № {i + 1}: {paragraphs[i]};
' + if slide_info['required_list'] and not slide_info['has_list']: + res += f'На данном слайде наличие списка является обязательным;' + if res: + result_str = result_str + f'Слайд {link}:
' + res + if not result_str: return answer(True, 'Пройдена!') else: - return answer(False, result_str) \ No newline at end of file + result_str += f'Количество слов на слайде должно быть больше {self.min_count_words_on_slide} и меньше {self.max_count_words_on_slide};
' \ + f'Количество абзацев на слайде должно быть больше {self.min_count_paragraphs} и меньше {self.max_count_paragraphs};
' \ + f'Количество слов в абзаце должно быть больше {self.min_count_words_in_paragraph} и меньше {self.max_count_words_in_paragraph};
' + return answer(False, result_str) + + def slide_text_analysis(self, page, text, required_list): + if text is None: + text = '' + paragraphs = [p for p in text.split('\n') if p.strip()] + slide_info = { + 'page': page, + 'required_list': required_list, + 'paragraphs': [], + 'count_paragraphs': len(paragraphs), + 'count_words_on_slide': 0, + 'has_list': False + } + for paragraph in paragraphs: + slide_info['paragraphs'].append(len(paragraph.split())) + # has_list??? + slide_info['count_words_on_slide'] = sum(slide_info['paragraphs']) + return slide_info \ No newline at end of file