Skip to content

Commit 9e8b6a6

Browse files
Merge remote-tracking branch 'origin/549_paragraphs_count_check' into dev
2 parents 6000fde + e19f0ee commit 9e8b6a6

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

app/main/check_packs/pack_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
["image_share_check"],
3131
["headers_at_page_top_check", {"headers": ["Приложение А Исходный код программы"]}],
3232
["headers_at_page_top_check"],
33+
["paragraphs_count_check"],
3334
["lr_sections_check"],
3435
["style_check"],
3536
["short_sections_check"],

app/main/checks/report_checks/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@
3232
from .sw_section_size import SWSectionSizeCheck
3333
from .sw_keywords_check import SWKeywordsCheck
3434
from .task_tracker import ReportTaskTracker
35+
from .paragraphs_count_check import ReportParagraphsCountCheck
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import re
2+
from .style_check_settings import StyleCheckSettings
3+
from ..base_check import BaseReportCriterion, answer
4+
5+
class ReportParagraphsCountCheck(BaseReportCriterion):
6+
label = "Проверка количества абзацев в главах и их подразделах"
7+
description = ""
8+
id = "paragraphs_count_check"
9+
10+
def __init__(self, file_info, min_paragraphs_in_unnumbered_section=5, min_paragraphs_in_section=10,
11+
min_paragraphs_in_subsection=5, min_paragraphs_in_subsubsection=1):
12+
super().__init__(file_info)
13+
self.min_count_paragraphs = {
14+
"unnumbered_section": min_paragraphs_in_unnumbered_section,
15+
"section": min_paragraphs_in_section,
16+
"subsection": min_paragraphs_in_subsection,
17+
"subsubsection": min_paragraphs_in_subsubsection
18+
}
19+
self.heading_styles = []
20+
self.paragraphs_count = []
21+
self.headers = []
22+
23+
def late_init(self):
24+
self.headers = self.file.make_chapters(self.file_type['report_type'])
25+
26+
def check(self):
27+
if self.file.page_counter() < 4:
28+
return answer(False, "В отчете недостаточно страниц. Нечего проверять.")
29+
30+
self.late_init()
31+
result = True
32+
result_str = ""
33+
34+
if not self.headers:
35+
return answer(False, "Не найдено ни одного заголовка.<br><br>Проверьте корректность использования стилей.")
36+
37+
for item in StyleCheckSettings.VKR_CONFIG:
38+
self.heading_styles.append(item["docx_style"])
39+
40+
self.find_paragraphs_count()
41+
42+
for obj in self.paragraphs_count:
43+
if obj["paragraphs"] < obj["min"]:
44+
result = False
45+
result_str += (f'Раздел "{obj["name"]}" содержит {obj["paragraphs"]} абзацев '
46+
f'(не считая рисунки и таблицы), что меньше минимальной рекомендуемой '
47+
f'длины раздела в {obj["min"]} абзацев.<br>')
48+
return answer(result, result_str if result_str else "Пройдена!")
49+
50+
def find_paragraphs_count(self):
51+
i = 0
52+
while i < len(self.headers):
53+
if "ПРИЛОЖЕНИЕ" in self.headers[i]["text"]:
54+
break
55+
56+
if self.headers[i]["style"] == self.heading_styles[0][0] and not re.search(r'\d', self.headers[i]["text"]):
57+
count_lists_section, ignored_paragraphs = self.find_lists_and_captions(self.headers[i]["child"])
58+
self.paragraphs_count.append({
59+
"name": self.headers[i]["text"],
60+
"min": self.min_count_paragraphs["unnumbered_section"],
61+
"paragraphs": len(self.headers[i]["child"]) - ignored_paragraphs + count_lists_section,
62+
"lists": count_lists_section
63+
})
64+
65+
elif self.headers[i]["style"] == self.heading_styles[1][0]:
66+
count_lists_section, ignored_paragraphs = self.find_lists_and_captions(self.headers[i]["child"])
67+
section_count = len(self.headers[i]["child"]) - ignored_paragraphs + count_lists_section
68+
69+
j = i + 1
70+
while j < len(self.headers) and self.headers[j]["style"] == self.heading_styles[1][1]:
71+
count_lists_subsection, ignored_paragraphs = self.find_lists_and_captions(self.headers[j]["child"])
72+
subsection_count = len(self.headers[j]["child"]) - ignored_paragraphs + count_lists_subsection
73+
74+
k = j + 1
75+
while k < len(self.headers) and self.headers[k]["style"] == self.heading_styles[1][2]:
76+
count_lists_subsubsection, ignored_paragraphs = self.find_lists_and_captions(self.headers[k]["child"])
77+
subsubsection_count = len(self.headers[k]["child"]) - ignored_paragraphs + count_lists_subsubsection
78+
subsection_count += subsubsection_count
79+
count_lists_subsection += count_lists_subsubsection
80+
81+
self.paragraphs_count.append({
82+
"name": self.headers[k]["text"],
83+
"min": self.min_count_paragraphs["subsubsection"],
84+
"paragraphs": subsubsection_count,
85+
"lists": count_lists_subsubsection
86+
})
87+
k += 1
88+
89+
section_count += subsection_count
90+
count_lists_section += count_lists_subsection
91+
92+
self.paragraphs_count.append({
93+
"name": self.headers[j]["text"],
94+
"min": self.min_count_paragraphs["subsection"],
95+
"paragraphs": subsection_count,
96+
"lists": count_lists_subsection
97+
})
98+
j = k
99+
100+
self.paragraphs_count.append({
101+
"name": self.headers[i]["text"],
102+
"min": self.min_count_paragraphs["section"],
103+
"paragraphs": section_count,
104+
"lists": count_lists_section
105+
})
106+
i = j - 1
107+
108+
i += 1
109+
110+
def find_lists_and_captions(self, paragraphs):
111+
ignored_paragraphs = 0
112+
count_lists = 0
113+
for paragraph in paragraphs:
114+
if paragraph["style"].find("вкр_подпись") != -1:
115+
ignored_paragraphs += 1
116+
# necessary search lists
117+
return count_lists, ignored_paragraphs

0 commit comments

Comments
 (0)