Skip to content

first try of count_lit_ref #564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/main/check_packs/pack_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
["theme_in_report_check"],
['key_words_report_check'],
["empty_task_page_check"],
["references_in_chapter_check"],
]

DEFAULT_TYPE = 'pres'
Expand Down
1 change: 1 addition & 0 deletions app/main/checks/report_checks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
from .template_name import ReportTemplateNameCheck
from .key_words_check import KeyWordsReportCheck
from .empty_task_page_check import EmptyTaskPageCheck
from .lit_ref_in_spec_chapter import LitRefInChapter
84 changes: 84 additions & 0 deletions app/main/checks/report_checks/lit_ref_in_spec_chapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import re
from .style_check_settings import StyleCheckSettings
from ..base_check import BaseReportCriterion, answer


class LitRefInChapter(BaseReportCriterion):
label = "Проверка количества ссылок на источники в определенном разделе"
description = ''
id = 'references_in_chapter_check'

def __init__(self, file_info, min_ref_value=0, max_ref_value=0, headers_map = None):
super().__init__(file_info)
self.chapters_for_lit_ref = {}
self.lit_ref_count = {}
self.min_ref_value = min_ref_value
self.max_ref_value = max_ref_value
if headers_map:
self.config = headers_map
else:
self.config = 'VKR_HEADERS' if (self.file_type['report_type'] == 'VKR') else 'LR_HEADERS'

def late_init(self):
self.chapters = self.file.make_chapters(self.file_type['report_type'])
self.headers_main = self.file.get_main_headers(self.file_type['report_type'])
if self.headers_main in StyleCheckSettings.CONFIGS.get(self.config):
self.chapters_for_lit_ref = StyleCheckSettings.CONFIGS.get(self.config)[self.headers_main]['chapters_for_lit_ref']
else:
if 'any_header' in StyleCheckSettings.CONFIGS.get(self.config):
self.chapters_for_lit_ref= StyleCheckSettings.CONFIGS.get(self.config)['any_header']['chapters_for_lit_ref']

def check(self):
if self.file.page_counter() < 4:
return answer(False, "В отчете недостаточно страниц. Нечего проверять.")
self.late_init()
if not self.chapters_for_lit_ref:
return answer(True, 'Для загруженной работы данная проверка не предусмотрена.')
result = []
result_str = f'Пройдена!'
currant_head = ''
chapter_for_check = 0
for chapter in self.chapters:
if chapter['style'] == "heading 2":
header = chapter["text"].lower()
if currant_head:
self.lit_ref_count[currant_head].append(chapter['number'])
if currant_head in self.chapters_for_lit_ref:
chapter_for_check += 1
ref_count = len(self.search_references(self.lit_ref_count[currant_head][0], self.lit_ref_count[currant_head][1]))
if ref_count > self.chapters_for_lit_ref[currant_head][1] or ref_count < self.chapters_for_lit_ref[currant_head][0]:
result.append(f'«{currant_head[0].upper() + currant_head[1:]}» : {ref_count}')
self.lit_ref_count[header] = [chapter['number'],]
currant_head = header
if result:
ref_value = round((chapter_for_check-len(result))/chapter_for_check, 2)
result_str = (f'Доля соответствия количества ссылок необходимому в требуемых разделах равна {ref_value}'
f'<br><b>Количество ссылок на источники не удовлетворяет допустимому в следующих разделах:</b> <br> {"<br>".join(res for res in result)}'
f'<br><b> Допустимые пороги количества ссылок:</b> <br>'
f'{"<br>".join(f"«{chapter.capitalize()}»: от {limit[0]} до {limit[1]}" for chapter, limit in self.chapters_for_lit_ref.items())}')
if ref_value >= self.max_ref_value:
return answer(1, f'Пройдена!')
elif ref_value >= self.min_ref_value:
return answer(ref_value, f'Частично пройдена! {result_str}')
else:
return answer(0, f'Не пройдена! {result_str}')
else:
return answer(1, result_str)

def search_references(self, start_par, end_par):
array_of_references = []
for i in range(start_par, end_par):
if isinstance(self.file.paragraphs[i], str):
detected_references = re.findall(r'\[[\d \-,]+\]', self.file.paragraphs[i])
else:
detected_references = re.findall(r'\[[\d \-,]+\]', self.file.paragraphs[i].paragraph_text)
if detected_references:
for reference in detected_references:
for one_part in re.split(r'[\[\],]', reference):
if re.match(r'\d+[ \-]+\d+', one_part):
start, end = re.split(r'[ -]+', one_part)
for k in range(int(start), int(end) + 1):
array_of_references.append((k))
elif one_part != '':
array_of_references.append(int(one_part))
return array_of_references
8 changes: 8 additions & 0 deletions app/main/checks/report_checks/style_check_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class StyleCheckSettings:
"style": HEADER_1_STYLE,
"docx_style": ["heading 1"],
"headers": ["Исходный код программы"],
"chapters_for_lit_ref": {},
"unify_regex": APPENDIX_UNIFY_REGEX,
"regex": APPENDIX_REGEX,
"banned_words": STD_BANNED_WORDS,
Expand All @@ -104,6 +105,7 @@ class StyleCheckSettings:
"style": HEADER_2_STYLE,
"docx_style": ["heading 2"],
"headers": ["Цель работы", "Выполнение работы", "Выводы"],
"chapters_for_lit_ref": {},
"unify_regex": None,
"regex": HEADER_1_REGEX,
}
Expand All @@ -115,6 +117,8 @@ class StyleCheckSettings:
"style": HEADER_1_STYLE,
"docx_style": ["heading 2"],
"headers": ["ВВЕДЕНИЕ", "ЗАКЛЮЧЕНИЕ", "СПИСОК ИСПОЛЬЗОВАННЫХ ИСТОЧНИКОВ"],
"chapters_for_lit_ref":{},
# { 'введение': [0, 1], 'определения, обозначения и сокращения': [2, 5], 'заключение': [1, 5] },
"unify_regex": None,
"regex": HEADER_REGEX,
"banned_words": STD_BANNED_WORDS,
Expand Down Expand Up @@ -163,6 +167,7 @@ class StyleCheckSettings:
"Методы обоснования",
"Статья",
],
"chapters_for_lit_ref": {},
"header_for_report_section_component": "Поставленная цель и задачи",
"unify_regex": None,
"regex": HEADER_REGEX,
Expand All @@ -178,6 +183,7 @@ class StyleCheckSettings:
"Характеристика выводов",
"Статья",
],
"chapters_for_lit_ref": {},
"header_for_report_section_component": "",
"unify_regex": None,
"regex": HEADER_REGEX,
Expand All @@ -197,6 +203,7 @@ class StyleCheckSettings:
"Выводы по итогам сравнения",
"Выбор метода решения",
],
"chapters_for_lit_ref": {},
"unify_regex": None,
"regex": HEADER_REGEX,
"banned_words": ['аттач', 'билдить', 'бинарник', 'валидный', 'дебаг', 'деплоить', 'десктопное', 'железо',
Expand All @@ -220,6 +227,7 @@ class StyleCheckSettings:
"Заключение",
"Список литературы"
],
"chapters_for_lit_ref": {},
"unify_regex": None,
"regex": HEADER_REGEX,
"banned_words": ['оптимально', 'оптимальный', 'надежный', 'интуитивный'],
Expand Down