Skip to content

Commit

Permalink
docx 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariiiii committed Jul 3, 2024
1 parent 43343fa commit c2b1d54
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions app/main/checks/report_checks/main_character_check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from ..base_check import BaseReportCriterion, answer
from .main_page_settings import ReportMainPageSetting
import re
import copy


class ReportMainCharacterCheck(BaseReportCriterion):
label = "Проверка составляющих титульного листа, задания и календарного плана"
Expand All @@ -11,19 +13,18 @@ class ReportMainCharacterCheck(BaseReportCriterion):
def __init__(self, file_info):
super().__init__(file_info)
self.headers = []
self.first_check_list = ReportMainPageSetting.FIRST_TABLE
self.second_check_list = ReportMainPageSetting.SECOND_TABLE
self.first_check_list = None
self.second_check_list = None
self.tables_count_to_verify = 8


def late_init(self):
self.headers = self.file.make_headers(self.file_type['report_type'])

def check(self):
self.first_check_list = copy.deepcopy(ReportMainPageSetting.FIRST_TABLE)
self.second_check_list = copy.deepcopy(ReportMainPageSetting.SECOND_TABLE)
if self.file.page_counter() < 4:
return answer(False, "В отчете недостаточно страниц. Нечего проверять.")
if len(self.file.styled_paragraphs) == 0:
self.file.parse()
if self.tables_count_to_verify > len(self.file.tables):
return answer(False, f"Количество таблиц на страницах титульного листа, задания и календарного плана должно быть не меньше {self.tables_count_to_verify}")
self.late_init()
Expand All @@ -34,9 +35,6 @@ def check(self):
pages.append(header["page"])
for i in range(self.tables_count_to_verify):
table = self.file.tables[i]
print("table",table)
print(type(table))
print(table.__dict__)
extract_table = self.extract_table_contents(table)
self.check_table(self.first_check_list, extract_table)
self.check_table(self.second_check_list, extract_table)
Expand All @@ -45,7 +43,7 @@ def check(self):
if res["found_key"] > 1 and res["key"] == "Консультант":
links = self.format_page_link(pages[1:])
result_str += f"На страницах {links} не нужно указывать консультантов.<br>"
elif res["found_key"] < res["find"]:
elif res["found_key"] < res["find"] and res["key"] != "Консультант":
result_str += f"Поле '{res['key']}' не найдено на страницах {links}. Его удалось обнаружить {res['found_key']} из {res['find']} раз. Проверьте корректность всех вхождений.<br>"
elif res["found_value"] < res["find"]:
links = self.format_page_link(pages)
Expand All @@ -59,15 +57,16 @@ def check(self):
return answer(False, result_str)

def extract_table_contents(self, table):
collected_table = []
for cell in table.table_cells:
collected_line = []
for item in cell:
if item.cell_text not in collected_line:
collected_line.append(item.cell_text)
collected_table.append(' '.join(collected_line))
print("УСпех"*10)
return collected_table
contents = []
processed_cells = set()
for row in table.rows:
row_text = []
for cell in row.cells:
if cell not in processed_cells:
row_text.append(cell.text.strip())
processed_cells.add(cell)
contents.append(' '.join(row_text))
return contents

def calculate_find_value(self, table, index):
count = int((len(table) - index - 2) / 2)
Expand All @@ -81,7 +80,7 @@ def check_table(self, check_list, table):
for i, line in enumerate(table):
if item["key"] in line:
flag = True
item["found_key"]+=1
item["found_key"] += 1
if item["key"] == "Консультант":
if item["found_key"] == 1:
item["find"] += self.calculate_find_value(table, i)
Expand All @@ -91,6 +90,6 @@ def check_table(self, check_list, table):
for value in item["value"]:
if re.search(value, line):
item["found_value"] += 1
if item["key"] != "Консультант":
flag = False
break
break
if item["key"] != "Зав. кафедрой" and item["key"] != "Консультант":
flag = False

0 comments on commit c2b1d54

Please sign in to comment.