ver Jan2nd

calc metrics are prapared by and large
This commit is contained in:
David Chang
2024-01-02 21:03:57 +08:00
parent d41c674a91
commit 6e6ef03bc9
9 changed files with 208 additions and 10 deletions

View File

@@ -1,3 +1,5 @@
from .table import compare_table
from .table import check_sheet_list, check_xlsx_freeze, check_zoom
from .table import check_sheet_list, check_xlsx_freeze, check_xlsx_zoom
from .docs import find_default_font, contains_page_break, compare_docx_files
from .pdf import check_pdf_pages
from .libreoffice import check_libre_locale

View File

@@ -0,0 +1,37 @@
import lxml.cssselect
from lxml.etree import _Element as Element
import lxml.etree
import fnmatch
from typing import Dict, List
_libconf_namespaces = [("oor", "http://openoffice.org/2001/registry")]
_libconf_ns_mapping = dict(_libconf_namespaces)
_setup_locale_selector = lxml.cssselect.CSSSelector( 'item[oor|path$=L10N]>prop[oor|name=ooSetupSystemLocale]>value'
, namespaces=_libconf_ns_mapping
)
_locale_selector = lxml.cssselect.CSSSelector( 'item[oor|path$=L10N]>prop[oor|name=ooLocale]>value'
, namespaces=_libconf_ns_mapping
)
def check_libre_locale(config_file: str, rules: Dict[str, List[str]]) -> float:
config: Element = lxml.etree.parse(config_file).getroot()
setup_locale_setting: List[Element] = _setup_locale_selector(config)
locale_setting: List[Element] = _locale_selector(config)
setup_locale_setting: str = setup_locale_setting[0].text\
if len(setup_locale_setting)>0\
else locale_setting[0].text
return float( any( fnmatch.fnmatchcase(setup_locale_setting, ptn)\
for ptn in rules["locale_set"]
)
)
if __name__ == "__main__":
path1 = "../../任务数据/LibreOffice Calc/registrymodifications.ru.xcu"
print( check_libre_locale( path1, { "locale_set": [ "ru-*", "de-*", "fr-*"
, "pt-*", "es-*", "it-*"
]
}
)
)

View File

@@ -0,0 +1,13 @@
from pypdf import PdfReader
import operator
from typing import Dict
from typing import Any
def check_pdf_pages(pdf_file: str, rules: Dict[str, Any]) -> float:
reader = PdfReader(pdf_file)
nb_pages: int = len(reader.pages)
return float( getattr(operator, rules["relation"])( nb_pages
, rules["ref_value"]
)
)

View File

@@ -110,7 +110,7 @@ def check_xlsx_freeze(result: str, rules: Dict[str, str]) -> float:
worksheet: Worksheet = openpyxl.load_workbook(filename=result).active
return float(worksheet.freeze_panes == rules["position"])
def check_zoom(result: str, rules: Dict[str, Union[str, Number]]) -> float:
def check_xlsx_zoom(result: str, rules: Dict[str, Union[str, Number]]) -> float:
worksheet = openpyxl.load_workbook(filename=result).active
zoom_scale: Number = worksheet.sheet_view.zoomScale or 100.
return float( getattr(operator, rules["relation"])( zoom_scale
@@ -160,21 +160,31 @@ if __name__ == '__main__':
#path1 = "../../任务数据/LibreOffice Calc/Represent_in_millions_billions_gold.xlsx"
#path2 = "../../任务数据/LibreOffice Calc/Represent_in_millions_billions_gold3.xlsx"
#path1 = "../../任务数据/LibreOffice Calc/Set_Decimal_Separator_Dot.xlsx"
#path2 = "../../任务数据/LibreOffice Calc/Set_Decimal_Separator_Dot_gold.xlsx"
#workbook1: Workbook = openpyxl.load_workbook(filename=path1)
#worksheet1: Worksheet = workbook1.active
#
#import itertools
#for col, r in itertools.product( ['A', 'B', 'C']
#, range(1, 9)
#for col, r in itertools.product( ['A', 'B']
#, range(1, 20)
#):
#position: str = "{:}{:d}".format(col, r)
#print(worksheet1[position])
#print(worksheet1[position].value)
#print(worksheet1[position].number_format)
#workbook2: Workbook = openpyxl.load_workbook(filename=path2)
#worksheet2: Worksheet = workbook2.active
#for col, r in itertools.product( ['A', 'B']
#, range(1, 20)
#):
#position: str = "{:}{:d}".format(col, r)
#print(worksheet2[position])
#print(worksheet2[position].value)
#print(worksheet2[position].number_format)
#print(compare_table(path1, path2, features=["number_format"]))
path1 = "../../任务数据/LibreOffice Calc/Zoom_Out_Oversized_Cells_gold.xlsx"
path2 = "../../任务数据/LibreOffice Calc/Zoom_Out_Oversized_Cells.xlsx"
#path1 = "../../任务数据/LibreOffice Calc/Zoom_Out_Oversized_Cells_gold.xlsx"
#path2 = "../../任务数据/LibreOffice Calc/Zoom_Out_Oversized_Cells.xlsx"
#workbook1: Workbook = openpyxl.load_workbook(filename=path1)
#worksheet1: Worksheet = workbook1.active
#print(worksheet1.sheet_view.zoomScale)
@@ -187,5 +197,9 @@ if __name__ == '__main__':
#):
#path = os.path.join("../../任务数据/LibreOffice Calc/", wb)
#print(wb, openpyxl.load_workbook(filename=path).active.sheet_view.zoomScale)
print(check_zoom(path1, {"relation": "lt", "ref_value": 100}))
print(check_zoom(path2, {"relation": "lt", "ref_value": 100}))
#print(check_zoom(path1, {"relation": "lt", "ref_value": 100}))
#print(check_zoom(path2, {"relation": "lt", "ref_value": 100}))
path1 = "../../任务数据/LibreOffice Calc/Padding_Decimals_In_Formular_gold.xlsx"
data_frame: pd.DataFrame = pd.read_excel(path1)
print(data_frame)

View File

@@ -27,7 +27,7 @@
"libreoffice_calc"
],
"evaluator": {
"func": "check_zoom",
"func": "check_xlsx_zoom",
"result": {
"type": "vm_file",
"path": "/home/david/Zoom_Out_Oversized_Cells.xlsx",

View File

@@ -0,0 +1,42 @@
{
"id": "4f07fbe9-70de-4927-a4d5-bb28bc12c52c",
"snapshot": "libreoffice_calc",
"instruction": "Could you help me padding numbers to three decimals when used within formula?",
"source": "https://superuser.com/questions/1081048/libreoffice-calc-how-to-pad-number-to-fixed-decimals-when-used-within-formula",
"config": [
{
"type": "download",
"parameters": {
"file": [
{
"url": "https://drive.usercontent.google.com/download?id=1LHxVvEpLI7kp0Iiy8K74gwkoGiwcLeYP&export=download&authuser=0&confirm=t&uuid=690287ee-d413-46e7-9b01-c56c12e445ff&at=APZUnTVCSd_ajhMGWpEgLHiExfbf:1704199487820",
"path": "/home/david/Padding_Decimals_In_Formular.xlsx"
}
]
}
},
{
"type": "open",
"parameters": {
"path": "/home/david/Padding_Decimals_In_Formular.xlsx"
}
}
],
"trajectory": "trajectories/4f07fbe9-70de-4927-a4d5-bb28bc12c52c",
"related_apps": [
"libreoffice_calc"
],
"evaluator": {
"func": "compare_table",
"result": {
"type": "vm_file",
"path": "/home/david/Padding_Decimals_In_Formular_gold.xlsx",
"dest": "Padding_Decimals_In_Formular.xlsx"
},
"expected": {
"type": "cloud_file",
"path": "https://drive.usercontent.google.com/download?id=1DJTBic8_DREPhcau1GUkISfRm-L6xbBv&export=download&authuser=0&confirm=t&uuid=18e7d364-37fb-4e7f-baf1-9444ae5813ba&at=APZUnTXYuAaQ-Aa-2yqTn_2MXe0u:1704200380362",
"dest": "Padding_Decimals_In_Formular_gold.xlsx"
}
}
}

View File

@@ -0,0 +1,44 @@
{
"id": "a01fbce3-2793-461f-ab86-43680ccbae25",
"snapshot": "libreoffice_calc",
"instruction": "Could you help me setting decimal separator as a dot (.)?",
"source": "https://superuser.com/questions/1250677/how-to-set-decimal-separator-in-libre-office-calc",
"config": [
{
"type": "download",
"parameters": {
"file": [
{
"url": "https://drive.usercontent.google.com/download?id=1uT0axjo9lwkKu6hYVnsAL2FCrdH0DLUv&export=download&authuser=0&confirm=t&uuid=e7da6304-9c7a-4862-8a30-9f2284b843da&at=APZUnTVNHThpAZJmF6IuPckFvslw:1704187618838",
"path": "/home/david/Set_Decimal_Separator_Dot.xlsx"
}
]
}
}
],
"trajectory": "trajectories/a01fbce3-2793-461f-ab86-43680ccbae25",
"related_apps": [
"libreoffice_calc"
],
"evaluator": {
"func": "check_libre_locale",
"result": {
"type": "vm_file",
"path": "/home/david/.config/libreoffice/4/user/registrymodifications.xcu",
"dest": "registrymodifications.xcu"
},
"expected": {
"type": "rule",
"rules": {
"locale_set": [
"ru-*",
"de-*",
"fr-*",
"pt-*",
"es-*",
"it-*"
]
}
}
}
}

View File

@@ -0,0 +1,44 @@
{
"id": "aa3a8974-2e85-438b-b29e-a64df44deb4b",
"snapshot": "libreoffice_calc",
"instruction": "Could you help me resizing cells in the sheet so that they fit into just one page and export as pdf file?",
"source": "https://www.quora.com/Libre-Office-Calc-How-do-I-resize-all-cells-in-a-sheet-to-make-them-fit-to-1-page-for-printing-and-exporting-as-PDF",
"config": [
{
"type": "download",
"parameters": {
"file": [
{
"url": "https://drive.usercontent.google.com/download?id=1O4bw7jEsVdFGeGeSX8hDjsvIbozV38sd&export=download&authuser=0&confirm=t&uuid=b6ceade0-e9c3-47bf-8c40-fef77b5ea1f1&at=APZUnTUUYaEx0Y_lAESeK1DfQZw6:1704179724348",
"path": "/home/david/Resize_Cells_Fit_Page.xlsx"
}
]
}
},
{
"type": "open",
"parameters": {
"path": "/home/david/Resize_Cells_Fit_Page.xlsx"
}
}
],
"trajectory": "trajectories/aa3a8974-2e85-438b-b29e-a64df44deb4b",
"related_apps": [
"libreoffice_calc"
],
"evaluator": {
"func": "check_pdf_pages",
"result": {
"type": "vm_file",
"path": "/home/david/Resize_Cells_Fit_Page.xlsx",
"dest": "Resize_Cells_Fit_Page.xlsx"
},
"expected": {
"type": "rule",
"rules": {
"relation": "eq",
"ref_value": 1
}
}
}
}

View File

@@ -19,3 +19,5 @@ lxml
cssselect
xmltodict
openpyxl
python-docx
pypdf