Skip to content

Commit 98fce79

Browse files
committed
fix
1 parent 3b18e0f commit 98fce79

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

app/main/check_packs/pack_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
["literature_references"],
3939
["image_references"],
4040
["table_references"],
41-
["table_percentage"],
41+
["report_table_percentage_check"],
4242
["first_pages_check"],
4343
["main_character_check"],
4444
["needed_headers_check"],

app/main/checks/report_checks/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .literature_references import ReferencesToLiteratureCheck
99
from .image_references import ImageReferences
1010
from .table_references import TableReferences
11-
from .table_percentage import TablePercentage
11+
from .table_percentage import ReportTablePercentageCheck
1212
from .main_text_check import ReportMainTextCheck
1313
from .needed_headers_check import ReportNeededHeadersCheck
1414
from .page_counter import ReportPageCounter

app/main/checks/report_checks/table_percentage.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
chars_per_line: int = 20 # Примерное кол-во символов в строке ячейки
88
cell_padding = 5 # Примерный размер отступов от границ ячейки
99
row_padding = 2 # Примерное расстояние между строками таблиц
10-
1110
#С данными значениями погрешность 4-5 процентов
1211

13-
class TablePercentage(BaseReportCriterion):
14-
label = "Проверка процентного соотношения таблиц в документе"
15-
description = "Проверяет, что таблицы занимают не более установленного процента площади документа"
16-
id = 'table_percentage'
12+
13+
class ReportTablePercentageCheck(BaseReportCriterion):
14+
label = 'Проверка процентного соотношения таблиц в документе'
15+
description = 'Проверяет, что таблицы занимают не более установленного процента площади документа'
16+
id = 'report_table_percentage_check'
1717

1818

19-
def __init__(self, file_info, hasApplication = True,max_percentage = 30):
19+
def __init__(self, file_info, has_application=True, max_percentage=15):
2020
super().__init__(file_info)
2121
self._max_percentage = max_percentage
22-
self._hasApplication = hasApplication
22+
self._hasApplication = has_application
2323

2424
def get_font_size(self, run, paragraph) -> float:
2525
"""Функция получения размера шрифта"""
@@ -32,7 +32,7 @@ def get_font_size(self, run, paragraph) -> float:
3232
else:
3333
return default_font_size
3434

35-
def heightCell(self, cell) -> float:
35+
def height_cell(self, cell) -> float:
3636
"""Функция получения высоты ячейки"""
3737
total_height = 0
3838

@@ -62,7 +62,7 @@ def heightCell(self, cell) -> float:
6262

6363
return total_height
6464

65-
def heightTable(self, table) -> float:
65+
def height_table(self, table) -> float:
6666
"""Функция получения высоты таблицы"""
6767
total_height = 0
6868
for row in table.rows:
@@ -71,14 +71,14 @@ def heightTable(self, table) -> float:
7171
else:
7272
heights = []
7373
for cell in row.cells:
74-
heights.append(self.heightCell(cell))
74+
heights.append(self.height_cell(cell))
7575
total_height += max(heights) if heights else 0
7676

7777
total_height += row_padding
7878

7979
return total_height
8080

81-
def getPercentOfTables(self) -> float:
81+
def get_percent_of_tables(self) -> float:
8282
"""Функция получение процента таблиц в документе"""
8383
doc_docx = self.file.file
8484

@@ -103,7 +103,7 @@ def getPercentOfTables(self) -> float:
103103

104104
for table_index, table in enumerate(doc_docx.tables):
105105
if table_index < end_index:
106-
table_height = self.heightTable(table)
106+
table_height = self.height_table(table)
107107
tables_height += table_height
108108

109109
percentage = (tables_height / total_height) * 100
@@ -127,38 +127,42 @@ def find_table_index_after_text(self, target_text: str) -> int | None:
127127

128128
return None
129129

130-
def find_tables_indexs_between_text(self,start_text: str, end_text: str | None = None):
130+
def find_tables_indexes_between_text(self,start_text: str, end_text: str | None = None):
131131
"""Функция нахождения индексов начала и конца таблиц между двумя текстами"""
132132
start_index = self.find_table_index_after_text(start_text)
133133
end_index = self.find_table_index_after_text(end_text)
134134

135-
return (start_index, end_index)
135+
return start_index, end_index
136136

137137
def check(self):
138138
try:
139139
if self.file.page_counter() < 4:
140140
return answer(False, "В отчете недостаточно страниц. Нечего проверять.")
141141

142-
percent_tables = self.getPercentOfTables()
142+
percent_tables = self.get_percent_of_tables()
143143

144144
if percent_tables <= self._max_percentage:
145145
return answer(
146146
True,
147147
"Пройдена!"
148148
)
149149
else:
150+
message = (
151+
f'Таблицы занимают {percent_tables:.1f}% документа, '
152+
f'что превышает допустимые {self._max_percentage}%. '
153+
'Рекомендации: \n'
154+
'<ul>\n'
155+
' <li>Уменьшите количество таблиц в основном тексте документа;</li>\n'
156+
' <li>Перенесите вспомогательные таблицы в приложения;</li>\n'
157+
' <li>Сократите объем данных в таблицах, оставив только самую важную информацию.</li>\n'
158+
'</ul>'
159+
)
160+
150161
return answer(
151162
False,
152-
f'''
153-
Таблицы занимают {percent_tables:.1f}% документа, что превышает допустимые {self._max_percentage}%.
154-
Рекомендации:
155-
<ul>
156-
<li>Уменьшите количество таблиц в основном тексте документа;</li>
157-
<li>Перенесите вспомогательные таблицы в приложения;</li>
158-
<li>Сократите объем данных в таблицах, оставив только самую важную информацию.</li>
159-
</ul>
160-
'''
163+
message
161164
)
165+
162166
except Exception as e:
163167
return answer(False, f"Ошибка при проверке процентного соотношения таблиц: {str(e)}")
164168

0 commit comments

Comments
 (0)