ver Jan18th
completed all the incomplete tasks stored under libreoffice_calc before added metric check_data_validations
This commit is contained in:
@@ -10,8 +10,10 @@ import openpyxl
|
||||
import pandas as pd
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.worksheet.worksheet import Worksheet
|
||||
#from openpyxl.worksheet.cell_range import MultiCellRange
|
||||
from openpyxl.worksheet.datavalidation import DataValidation
|
||||
|
||||
from .utils import load_charts, load_sparklines
|
||||
from .utils import load_charts, load_sparklines, _match_value_to_rule
|
||||
|
||||
logger = logging.getLogger("desktopenv.metric.table")
|
||||
|
||||
@@ -27,7 +29,7 @@ def compare_table(actual: str, expected: str, **options) -> float:
|
||||
* sparkline
|
||||
* chart
|
||||
* number_format
|
||||
"chart_props": list of str, giving the converned chart properties
|
||||
"chart_props": list of str, giving the concerned chart properties
|
||||
"as_shown": bool, TODO
|
||||
}
|
||||
|
||||
@@ -164,6 +166,57 @@ def check_xlsx_zoom(result: str, rules: Dict[str, Union[str, Number]]) -> float:
|
||||
)
|
||||
)
|
||||
|
||||
def check_data_validations(result: str, rules: List[Dict[str, Dict[str, Any]]]) -> float:
|
||||
"""
|
||||
Args:
|
||||
result (str): path to the concerned xlsx file
|
||||
rules (List[Dict[str, Dict[str, Any]]]): list of dict like
|
||||
{
|
||||
<str as attribute>: {
|
||||
"method": str
|
||||
"ref": something
|
||||
}
|
||||
}
|
||||
Available attributes:
|
||||
* ranges
|
||||
* type
|
||||
* formula1
|
||||
* formula2
|
||||
* operator
|
||||
* allowBlank
|
||||
* showDropDown
|
||||
* showInputMessage
|
||||
* showErrorMessage
|
||||
* error
|
||||
* errorTitle
|
||||
* errorStyle
|
||||
* prompt
|
||||
* promptTitle
|
||||
* imeMode
|
||||
|
||||
Returns:
|
||||
float
|
||||
"""
|
||||
|
||||
workbook: Workbook = openpyxl.load_workbook(result)
|
||||
worksheet: Worksheet = workbook.active
|
||||
data_validators: List[DataValidation] = worksheet.data_validations.dataValidation
|
||||
|
||||
total_metric = True
|
||||
for dat_vldt in data_validators:
|
||||
metric = False
|
||||
for r in rules:
|
||||
metric = metric or all( _match_value_to_rule( getattr(dat_vldt, attrbt)
|
||||
, mr
|
||||
)\
|
||||
for attrbt, mr in r.items()
|
||||
)
|
||||
if metric:
|
||||
break
|
||||
total_metric = total_metric and metric
|
||||
if not total_metric:
|
||||
break
|
||||
return float(total_metric)
|
||||
|
||||
if __name__ == '__main__':
|
||||
# path1 = ""
|
||||
@@ -247,8 +300,31 @@ if __name__ == '__main__':
|
||||
# print(check_zoom(path1, {"relation": "lt", "ref_value": 100}))
|
||||
# print(check_zoom(path2, {"relation": "lt", "ref_value": 100}))
|
||||
|
||||
path1 = "../../任务数据/LibreOffice Calc/Customers_New_7digit_Id.xlsx"
|
||||
path2 = "../../任务数据/LibreOffice Calc/Customers_New_7digit_Id_gold.xlsx"
|
||||
#path1 = "../../任务数据/LibreOffice Calc/Customers_New_7digit_Id.xlsx"
|
||||
#path2 = "../../任务数据/LibreOffice Calc/Customers_New_7digit_Id_gold.xlsx"
|
||||
#data_frame: pd.DataFrame = pd.read_excel(path1)
|
||||
#print(data_frame)
|
||||
print(compare_table(path1, path2, as_shown=True))
|
||||
#print(compare_table(path1, path2, as_shown=True))
|
||||
|
||||
#from openpyxl.worksheet.cell_range import MultiCellRange
|
||||
|
||||
path = "../../任务数据/LibreOffice Calc/Order_Id_Mark_Pass_Fail_gold.xlsx"
|
||||
#worksheet: Worksheet = openpyxl.load_workbook(filename=path).active
|
||||
##print(worksheet.data_validations)
|
||||
#print(type(worksheet.data_validations.dataValidation))
|
||||
#for dat_vldt in worksheet.data_validations.dataValidation:
|
||||
#print(dat_vldt.sqref)
|
||||
#print(all(r in MultiCellRange("D2:D30 B1:B60") for r in dat_vldt.sqref))
|
||||
print( check_data_validations( path, [ { "ranges": { "method": "spreadsheet_range"
|
||||
, "ref": ["D2:D29", "D2:D1048576"]
|
||||
}
|
||||
, "type": { "method": "eq"
|
||||
, "ref": "list"
|
||||
}
|
||||
, "formula1": { "method": "str_set_eq"
|
||||
, "ref": ["Pass", "Fail", "Held"]
|
||||
}
|
||||
}
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user