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))

View File

@@ -9,8 +9,8 @@
"parameters": {
"files": [
{
"path": "/home/david/copy_sheet_insert.xlsx"
"url": "https://drive.usercontent.google.com/download?id=1ejNXBNOZtn64ugmvXot21pOEjx5xa-I5&export=download&authuser=0&confirm=t&uuid=61aa93e2-03f7-4b28-8e4a-cdff16a642f7&at=APZUnTVgPAHHfXaEjfKau5CDY1_K:1703509323791",
"path": "/home/david/copy_sheet_insert.xlsx"
}
]
}

View File

@@ -0,0 +1,42 @@
{
"id": "21df9241-f8d7-4509-b7f1-37e501a823f7",
"snapshot": "libreoffice_calc",
"instruction": "Change the representation of colum \"Parameter\" and show in Millions (M) and Billions (B). Keep one decimal and place a white space between the digits and the unit.",
"source": "https://www.youtube.com/watch?v=p5C4V_AO1UU",
"config": [
{
"type": "download",
"parameters": {
"file": [
{
"url": "",
"path": "/home/david/Represent_in_millions_billions.xlsx"
}
]
}
},
{
"type": "open",
"parameters": {
"path": "/home/david/Represent_in_millions_billions.xlsx"
}
}
],
"trajectory": "trajectories/21df9241-f8d7-4509-b7f1-37e501a823f7",
"related_apps": [
"libreoffice_calc"
],
"evaluator": {
"func": "compare_with_formats",
"result": {
"type": "vm_file",
"path": "/home/david/Represent_in_millions_billions.xlsx",
"dest": "Represent_in_millions_billions.xlsx"
},
"expected": {
"type": "cloud_file",
"path": "",
"dest": "Represent_in_millions_billions_gold.xlsx"
}
}
}

View File

@@ -9,8 +9,8 @@
"parameters": {
"files": [
{
"path": "/home/david/OrderId_Month_Chart.xlsx"
"url": "https://drive.usercontent.google.com/download?id=1uywX5XWMvesnb4-8LPKEzr2HFU7HmoIu&export=download&authuser=0&confirm=t&uuid=267bfe49-a861-4272-ae7c-39c95df35e84&at=APZUnTUbs-FF06hSMv3yWfdXc02l:1703508870351",
"path": "/home/david/OrderId_Month_Chart.xlsx"
}
]
}

View File

@@ -9,8 +9,8 @@
"parameters": {
"files": [
{
"path": "/home/david/Create_column_charts_using_statistics.xlsx"
"url": "https://drive.usercontent.google.com/download?id=1GOEacGTLP4EfGS8YwO9aGmmPgud5EavT&export=download&authuser=0&confirm=t&uuid=3971675c-3a76-4f89-863f-7f8afa59c3c5&at=APZUnTWaQ4_l1IiXsAR8VbjKf4uZ:1703595929357",
"path": "/home/david/Create_column_charts_using_statistics.xlsx"
}
]
}

View File

@@ -9,8 +9,8 @@
"parameters": {
"files": [
{
"path": "/home/david/Freeze_row_column.xlsx"
"url": "https://drive.usercontent.google.com/download?id=1ZhGLDKOden_oxzuN2xN9-jNQSHtCX6GE&export=download&authuser=0&confirm=t&uuid=2c097276-a610-4a9f-b6e4-5b54296c1555&at=APZUnTWc7zKPY_ykygn0mO1SAs4s:1703580957447",
"path": "/home/david/Freeze_row_column.xlsx"
}
]
}

View File

@@ -9,8 +9,8 @@
"parameters": {
"files": [
{
"path": "/home/david/Quarterly_Product_Sales_by_Zone.xlsx"
"url": "https://drive.usercontent.google.com/download?id=1rwhniaClEkF8XFzdfaNUA6GmAiy4syMZ&export=download&authuser=0&confirm=t&uuid=6fdd5b04-85f4-45e1-ad74-368f8f2a82ab&at=APZUnTUP-JxPxLfNls6jXWghblQ5:1701766091851",
"path": "/home/david/Quarterly_Product_Sales_by_Zone.xlsx"
}
]
}