Merge branch 'zdy'
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
from .table import compare_table, compare_with_sparklines
|
||||
from .table import compare_table, compare_with_sparklines, compare_with_charts
|
||||
from .table import check_sheet_list, check_xlsx_freeze
|
||||
|
||||
@@ -6,8 +6,9 @@ from lxml.etree import _Element
|
||||
import xmltodict
|
||||
#import pylightxl
|
||||
import openpyxl
|
||||
#from openpyxl import Workbook
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.worksheet.worksheet import Worksheet
|
||||
from openpyxl.chart._chart import ChartBase
|
||||
|
||||
from typing import Dict, List
|
||||
from typing import Any
|
||||
@@ -69,6 +70,59 @@ def compare_with_sparklines(actual: str, expected: str) -> float:
|
||||
|
||||
return float(normal_content_metric and sparkline_metric)
|
||||
|
||||
def _load_charts(xlsx_file: str) -> Dict[str, Any]:
|
||||
"""
|
||||
Args:
|
||||
xlsx_file (str): path to xlsx
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: information of charts
|
||||
"""
|
||||
|
||||
workbook: Workbook = openpyxl.load_workbook(filename=xlsx_file)
|
||||
worksheet: Worksheet = workbook.active
|
||||
charts: List[ChartBase] = worksheet._charts
|
||||
|
||||
chart_set: Dict[str, Any] = {}
|
||||
for ch in charts:
|
||||
series: List[str] = []
|
||||
for ser in ch.series:
|
||||
value_num = ser.val.numRef.f\
|
||||
if hasattr(ser.val, "numRef") and hasattr(ser.val.numRef, "f")\
|
||||
else ""
|
||||
value_str = ser.val.strRef.f\
|
||||
if hasattr(ser.val, "strRef") and hasattr(ser.val.strRef, "f")\
|
||||
else ""
|
||||
categ_num = ser.cat.numRef.f\
|
||||
if hasattr(ser.cat, "numRef") and hasattr(ser.cat.numRef, "f")\
|
||||
else ""
|
||||
categ_str = ser.cat.strRef.f\
|
||||
if hasattr(ser.cat, "strRef") and hasattr(ser.cat.strRef, "f")\
|
||||
else ""
|
||||
series.append( "{:},{:},{:},{:}".format( value_num, value_str
|
||||
, categ_num, categ_str
|
||||
)
|
||||
)
|
||||
series: str = ";".join(series)
|
||||
|
||||
# TODO: maybe more aspects, like chart type
|
||||
info: Dict[str, Any] = {}
|
||||
chart_set[series] = info
|
||||
return chart_set
|
||||
|
||||
def compare_with_charts(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))
|
||||
|
||||
charts1 = _load_charts(actual)
|
||||
charts2 = _load_charts(expected)
|
||||
chart_metric: bool = charts1==charts2
|
||||
print("Chart Metric: {:}".format(chart_metric))
|
||||
|
||||
return float(normal_content_metric and chart_metric)
|
||||
|
||||
def check_sheet_list(result: str, rules: List[Dict[str, Any]]) -> float:
|
||||
#workbook: Workbook = openpyxl.load_workbook(filename=result)
|
||||
workbook = pd.ExcelFile(result)
|
||||
@@ -131,18 +185,42 @@ if __name__ == '__main__':
|
||||
#rule = {"position": "C6"}
|
||||
#print(check_xlsx_freeze(path1, rule))
|
||||
|
||||
path1 = "../../../../../任务数据/LibreOffice Calc/copy_sheet_insert_gold.xlsx"
|
||||
rule = [ { "type": "sheet_name"
|
||||
, "sheet_idx": 0
|
||||
, "sheet_name": "Sheet1"
|
||||
}
|
||||
, { "type": "sheet_data"
|
||||
, "sheet_idx0": "../../../../../任务数据/LibreOffice Calc/copy_sheet_insert.xlsx@0"
|
||||
, "sheet_idx1": 1
|
||||
}
|
||||
, { "type": "sheet_name"
|
||||
, "sheet_idx": 2
|
||||
, "sheet_name": "Sheet2"
|
||||
}
|
||||
]
|
||||
print(check_sheet_list(path1, rule))
|
||||
#path1 = "../../../../../任务数据/LibreOffice Calc/copy_sheet_insert_gold.xlsx"
|
||||
#rule = [ { "type": "sheet_name"
|
||||
#, "sheet_idx": 0
|
||||
#, "sheet_name": "Sheet1"
|
||||
#}
|
||||
#, { "type": "sheet_data"
|
||||
#, "sheet_idx0": "../../../../../任务数据/LibreOffice Calc/copy_sheet_insert.xlsx@0"
|
||||
#, "sheet_idx1": 1
|
||||
#}
|
||||
#, { "type": "sheet_name"
|
||||
#, "sheet_idx": 2
|
||||
#, "sheet_name": "Sheet2"
|
||||
#}
|
||||
#]
|
||||
#print(check_sheet_list(path1, rule))
|
||||
|
||||
path1 = "../../../../../任务数据/LibreOffice Calc/Create_column_charts_using_statistics_gold.xlsx"
|
||||
#workbook1: Workbook = openpyxl.load_workbook(filename=path1)
|
||||
#worksheet1: Worksheet = workbook1.active
|
||||
#charts: List[ChartBase] = worksheet1._charts
|
||||
#print(len(charts))
|
||||
#print(type(charts[0]))
|
||||
#
|
||||
#print(len(charts[0].series))
|
||||
#print(type(charts[0].series[0]))
|
||||
#print(type(charts[0].series[0].val))
|
||||
##print(charts[0].series[0].val)
|
||||
#print(charts[0].series[0].val.numRef.f)
|
||||
#
|
||||
#print(type(charts[0].series[0].cat))
|
||||
##print(charts[0].series[0].cat)
|
||||
#print(charts[0].series[0].cat.numRef)
|
||||
#print(charts[0].series[0].cat.strRef)
|
||||
#print(charts[0].series[0].cat.strRef.f)
|
||||
#
|
||||
#df1 = pd.read_excel(path1)
|
||||
#print(df1)
|
||||
path2 = "../../../../../任务数据/LibreOffice Calc/Create_column_charts_using_statistics_gold2.xlsx"
|
||||
print(compare_with_charts(path1, path2))
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
"libreoffice calc"
|
||||
],
|
||||
"evaluator": {
|
||||
"func": "compare_with_sparklines",
|
||||
"expected": {
|
||||
"type": "cloud_file",
|
||||
"path": "https://drive.usercontent.google.com/download?id=1KQJJLVPGtTL_7ArEWvwwbFbJSiA3cgSE&export=download&authuser=0&confirm=t&uuid=6b11c721-caad-439a-b369-4c13c7a485df&at=APZUnTV5-1isKrDKSHV9NeJ6TDeS:1703509054094",
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"id": "347ef137-7eeb-4c80-a3bb-0951f26a8aff",
|
||||
"snapshot": "libreoffice_calc",
|
||||
"instruction": "Could you create two column charts of per-month costs for me using statistics in the form?",
|
||||
"source": "https://www.youtube.com/watch?v=bgO40-CjYNY",
|
||||
"config": [
|
||||
{
|
||||
"type": "download",
|
||||
"parameters": {
|
||||
"files": [
|
||||
{
|
||||
"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": "Desktop/Create_column_charts_using_statistics.xlsx"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "open",
|
||||
"parameters": {
|
||||
"path": "Desktop/Create_column_charts_using_statistics.xlsx"
|
||||
}
|
||||
}
|
||||
],
|
||||
"trajectory": "trajectories/347ef137-7eeb-4c80-a3bb-0951f26a8aff",
|
||||
"related_apps": [
|
||||
"libreoffice_calc"
|
||||
],
|
||||
"evaluator": {
|
||||
"func": "compare_with_charts",
|
||||
"result": {
|
||||
"type": "vm_file",
|
||||
"path": "Desktop/Create_column_charts_using_statistics.xlsx",
|
||||
"dest": "Create_column_charts_using_statistics.xlsx"
|
||||
},
|
||||
"expected": {
|
||||
"type": "cloud_file",
|
||||
"path": "https://drive.usercontent.google.com/download?id=1yiTCGZvGccWET9u8K7looD3ybH7PO9gb&export=download&authuser=0&confirm=t&uuid=65f54a6f-bb2e-40c3-8a76-091d785a5aca&at=APZUnTVbeO6maMvzItLvSwdBEZoM:1703595892144",
|
||||
"dest": "Create_column_charts_using_statistics_gold.xlsx"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user