ver Dec29th

metric compare_with_formats
This commit is contained in:
David Chang
2023-12-29 21:19:52 +08:00
parent 5a14cf40db
commit e4fac09945
7 changed files with 88 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
import pandas as pd
import openpyxl
from openpyxl import Workbook
from openpyxl.worksheet.worksheet import Worksheet
from .utils import load_charts, load_sparklines
@@ -51,6 +52,28 @@ def compare_with_charts(actual: str, expected: str, **options) -> float:
return float(normal_content_metric and chart_metric)
def compare_with_formats(actual: str, expected: str) -> float:
df1 = pd.read_excel(actual)
df2 = pd.read_excel(expected)
normal_content_metric: bool = df1.equals(df2)
print("Normal Contents Metric: {:}".format(normal_content_metric))
workbook1: Workbook = openpyxl.load_workbook(actual)
number_formats1: List[str] = [ c.number_format.lower()\
for col in workbook1.active.iter_cols()\
for c in col\
if c.data_type=="n"
]
workbook2: Workbook = openpyxl.load_workbook(expected)
number_formats2: List[str] = [ c.number_format.lower()\
for col in workbook2.active.iter_cols()\
for c in col\
if c.data_type=="n"
]
number_format_metric: bool = number_formats1==number_formats2
print("Number Format Metric: {:}".format(number_format_metric))
return float(normal_content_metric & number_format_metric)
def check_sheet_list(result: str, rules: List[Dict[str, Any]]) -> float:
# workbook: Workbook = openpyxl.load_workbook(filename=result)
@@ -132,6 +155,21 @@ if __name__ == '__main__':
# ]
# print(check_sheet_list(path1, rule))
path1 = "../../../../../任务数据/LibreOffice Calc/Create_column_charts_using_statistics_gold.xlsx"
path2 = "../../../../../任务数据/LibreOffice Calc/Create_column_charts_using_statistics_gold2.xlsx"
print(compare_with_charts(path1, path2, chart_props=["type", "direction"]))
#path1 = "../../../../../任务数据/LibreOffice Calc/Create_column_charts_using_statistics_gold.xlsx"
#path2 = "../../../../../任务数据/LibreOffice Calc/Create_column_charts_using_statistics_gold2.xlsx"
#print(compare_with_charts(path1, path2, chart_props=["type", "direction"]))
path1 = "../../任务数据/LibreOffice Calc/Represent_in_millions_billions_gold.xlsx"
path2 = "../../任务数据/LibreOffice Calc/Represent_in_millions_billions_gold3.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)
#):
#position: str = "{:}{:d}".format(col, r)
#print(worksheet1[position])
#print(worksheet1[position].value)
#print(worksheet1[position].number_format)
print(compare_with_formats(path1, path2))