Skip to content

Commit

Permalink
docx2
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariiiii committed Jul 3, 2024
1 parent 702377a commit 43343fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
53 changes: 26 additions & 27 deletions app/main/checks/report_checks/main_character_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self, file_info):
self.headers = []
self.first_check_list = ReportMainPageSetting.FIRST_TABLE
self.second_check_list = ReportMainPageSetting.SECOND_TABLE
self.tables_count_to_verify = 8


def late_init(self):
Expand All @@ -21,17 +22,24 @@ def late_init(self):
def check(self):
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()
result_str = ""
pages = []
for header in self.headers:
if header["marker"] and header["main_character"]:
pages.append(header["page"])
for table in self.file.tables:
if "таблица" in self.get_text_before_table(table):
break
self.check_table(self.first_check_list, table)
self.check_table(self.second_check_list, table)
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)
links = self.format_page_link(pages)
for res in self.first_check_list + self.second_check_list:
if res["found_key"] > 1 and res["key"] == "Консультант":
Expand All @@ -49,43 +57,34 @@ def check(self):
f'<br>Для бакалавров: <a href="https://drive.google.com/drive/folders/1pvv9HJIUB0VZUXteGqtLcVq6zIgZ6rbZ">Формы бланков для бакалавров</a>.' \
f'<br>Для магистров: <a href="https://drive.google.com/drive/folders/1KOoXzKv4Wf-XyGzOf1X8gN256sgame1D">Формы бланков для магистров</a>.'
return answer(False, result_str)

def get_text_before_table(self, table):
element = table._element.getprevious()
while element is not None:
if element.text and element.text.strip() != "":
return element.text.strip().lower()
element = element.getprevious()

def extract_table_contents(self, 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
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

def calculate_find_value(self, lines, index):
count = int((len(lines) - index - 2) / 2)
def calculate_find_value(self, table, index):
count = int((len(table) - index - 2) / 2)
if count >= 0:
return count
return 0

def check_table(self, check_list, table):
lines = self.extract_table_contents(table)
for item in check_list:
flag = False
for i, line in enumerate(lines):
for i, line in enumerate(table):
if item["key"] in line:
flag = True
item["found_key"]+=1
if item["key"] == "Консультант":
if item["found_key"] == 1:
item["find"] += self.calculate_find_value(lines, i)
item["find"] += self.calculate_find_value(table, i)
else:
flag = False
if flag:
Expand Down
2 changes: 1 addition & 1 deletion app/main/checks/report_checks/main_page_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ReportMainfound_valueSetting:
class ReportMainPageSetting:
FIRST_TABLE = [
{
"key": "Направление",
Expand Down

0 comments on commit 43343fa

Please sign in to comment.