From 2ed44d19d69e7071d84532f598af45a0323a929c Mon Sep 17 00:00:00 2001 From: kurilova Date: Wed, 21 May 2025 12:14:44 +0000 Subject: [PATCH 1/2] Calculate tests count for first page --- framework/python/src/common/testreport.py | 26 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/framework/python/src/common/testreport.py b/framework/python/src/common/testreport.py index 8118c5db9..02a45d83b 100644 --- a/framework/python/src/common/testreport.py +++ b/framework/python/src/common/testreport.py @@ -284,7 +284,9 @@ def to_html(self): module_reports = self._module_reports env_module = Environment(loader=BaseLoader()) - pages_num = self._pages_num(json_data) + tests_first_page = self._calculate_tests_first_page(json_data['device']['manufacturer'], json_data['device']['model']) + pages_num = self._pages_num(json_data, tests_first_page) + module_templates = [ env_module.from_string(s).render( name=current_test_pack.name, @@ -310,11 +312,25 @@ def to_html(self): steps_to_resolve=steps_to_resolve_, module_reports=module_reports, pages_num=pages_num, - tests_first_page=TESTS_FIRST_PAGE, + tests_first_page=tests_first_page, tests_per_page=TESTS_PER_PAGE, module_templates=module_templates )) + def _calculate_tests_first_page(self, device_manufacturer, device_model, average_chars_per_line=25, average_line_height_px=60, test_result_height_px=39, max_tests_on_full_page=TESTS_FIRST_PAGE): + full_text = f"{device_manufacturer} {device_model}" + text_length = len(full_text) + estimated_lines = (text_length // average_chars_per_line) + (1 if text_length % average_chars_per_line > 0 else 0) + estimated_device_info_height_px = estimated_lines * average_line_height_px + + available_space_px = 816 - estimated_device_info_height_px - 322 + + if available_space_px < test_result_height_px: + return 0 + + estimated_tests_first_page = int(available_space_px // test_result_height_px) + return min(estimated_tests_first_page, max_tests_on_full_page) + def _add_page_counter(self, html): # Add page nums and total page soup = BeautifulSoup(html, features='html5lib') @@ -324,18 +340,18 @@ def _add_page_counter(self, html): div.string = f'Page {index+1}/{total_pages}' return str(soup) - def _pages_num(self, json_data): + def _pages_num(self, json_data, tests_first_page=TESTS_FIRST_PAGE): # Calculate pages test_count = len(json_data['tests']['results']) # Multiple pages required - if test_count > TESTS_FIRST_PAGE: + if test_count > tests_first_page: # First page pages = 1 # Remaining testsgenerate - test_count -= TESTS_FIRST_PAGE + test_count -= tests_first_page pages += (int)(test_count / TESTS_PER_PAGE) pages = pages + 1 if test_count % TESTS_PER_PAGE > 0 else pages From 3f94dae23c058b4d20b0e2b69644edd81c5c8ea6 Mon Sep 17 00:00:00 2001 From: Aliaksandr Nikitsin Date: Wed, 21 May 2025 20:29:43 +0200 Subject: [PATCH 2/2] refactor first page calculation --- framework/python/src/common/testreport.py | 30 ++++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/framework/python/src/common/testreport.py b/framework/python/src/common/testreport.py index 02a45d83b..32d043234 100644 --- a/framework/python/src/common/testreport.py +++ b/framework/python/src/common/testreport.py @@ -284,7 +284,10 @@ def to_html(self): module_reports = self._module_reports env_module = Environment(loader=BaseLoader()) - tests_first_page = self._calculate_tests_first_page(json_data['device']['manufacturer'], json_data['device']['model']) + manufacturer_length = len(json_data['device']['manufacturer']) + device_name_length = len(json_data['device']['model']) + title_length = manufacturer_length + device_name_length +1 + tests_first_page = self._calculate_tests_first_page(title_length) pages_num = self._pages_num(json_data, tests_first_page) module_templates = [ @@ -317,19 +320,22 @@ def to_html(self): module_templates=module_templates )) - def _calculate_tests_first_page(self, device_manufacturer, device_model, average_chars_per_line=25, average_line_height_px=60, test_result_height_px=39, max_tests_on_full_page=TESTS_FIRST_PAGE): - full_text = f"{device_manufacturer} {device_model}" - text_length = len(full_text) - estimated_lines = (text_length // average_chars_per_line) + (1 if text_length % average_chars_per_line > 0 else 0) - estimated_device_info_height_px = estimated_lines * average_line_height_px + def _calculate_tests_first_page(self, title_length): + # Calculation of test results lines at first page - available_space_px = 816 - estimated_device_info_height_px - 322 + # Average chars per line is 25 + estimated_lines = title_length // 25 + if title_length % 25 > 0: + estimated_lines += 1 - if available_space_px < test_result_height_px: - return 0 - - estimated_tests_first_page = int(available_space_px // test_result_height_px) - return min(estimated_tests_first_page, max_tests_on_full_page) + if estimated_lines > 1: + # Line height is 60 px + title_px = (estimated_lines - 1) * 60 + available_space_px = 445 - title_px + estimated_tests_first_page = available_space_px // 39 + return min(estimated_tests_first_page, TESTS_FIRST_PAGE) + else: + return TESTS_FIRST_PAGE def _add_page_counter(self, html): # Add page nums and total page