From e4fac099458118faa3180626b20e49de148dedf5 Mon Sep 17 00:00:00 2001 From: David Chang Date: Fri, 29 Dec 2023 21:19:52 +0800 Subject: [PATCH 1/4] ver Dec29th metric compare_with_formats --- desktop_env/evaluators/metrics/table.py | 44 +++++++++++++++++-- .../0cecd4f3-74de-457b-ba94-29ad6b5dafb6.json | 2 +- .../21df9241-f8d7-4509-b7f1-37e501a823f7.json | 42 ++++++++++++++++++ .../2bd59342-0664-4ccb-ba87-79379096cc08.json | 2 +- .../347ef137-7eeb-4c80-a3bb-0951f26a8aff.json | 2 +- .../4188d3a4-077d-46b7-9c86-23e1a036f6c1.json | 2 +- .../f9584479-3d0d-4c79-affa-9ad7afdd8850.json | 2 +- 7 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 evaluation_examples/examples/libreoffice_calc/21df9241-f8d7-4509-b7f1-37e501a823f7.json diff --git a/desktop_env/evaluators/metrics/table.py b/desktop_env/evaluators/metrics/table.py index 4591b82..878db8a 100644 --- a/desktop_env/evaluators/metrics/table.py +++ b/desktop_env/evaluators/metrics/table.py @@ -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)) diff --git a/evaluation_examples/examples/libreoffice_calc/0cecd4f3-74de-457b-ba94-29ad6b5dafb6.json b/evaluation_examples/examples/libreoffice_calc/0cecd4f3-74de-457b-ba94-29ad6b5dafb6.json index 8ef2461..c10de54 100644 --- a/evaluation_examples/examples/libreoffice_calc/0cecd4f3-74de-457b-ba94-29ad6b5dafb6.json +++ b/evaluation_examples/examples/libreoffice_calc/0cecd4f3-74de-457b-ba94-29ad6b5dafb6.json @@ -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" } ] } diff --git a/evaluation_examples/examples/libreoffice_calc/21df9241-f8d7-4509-b7f1-37e501a823f7.json b/evaluation_examples/examples/libreoffice_calc/21df9241-f8d7-4509-b7f1-37e501a823f7.json new file mode 100644 index 0000000..b0f9577 --- /dev/null +++ b/evaluation_examples/examples/libreoffice_calc/21df9241-f8d7-4509-b7f1-37e501a823f7.json @@ -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" + } + } +} diff --git a/evaluation_examples/examples/libreoffice_calc/2bd59342-0664-4ccb-ba87-79379096cc08.json b/evaluation_examples/examples/libreoffice_calc/2bd59342-0664-4ccb-ba87-79379096cc08.json index 1d4e595..aa483ba 100644 --- a/evaluation_examples/examples/libreoffice_calc/2bd59342-0664-4ccb-ba87-79379096cc08.json +++ b/evaluation_examples/examples/libreoffice_calc/2bd59342-0664-4ccb-ba87-79379096cc08.json @@ -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" } ] } diff --git a/evaluation_examples/examples/libreoffice_calc/347ef137-7eeb-4c80-a3bb-0951f26a8aff.json b/evaluation_examples/examples/libreoffice_calc/347ef137-7eeb-4c80-a3bb-0951f26a8aff.json index 3efa94e..fd7a7e7 100644 --- a/evaluation_examples/examples/libreoffice_calc/347ef137-7eeb-4c80-a3bb-0951f26a8aff.json +++ b/evaluation_examples/examples/libreoffice_calc/347ef137-7eeb-4c80-a3bb-0951f26a8aff.json @@ -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" } ] } diff --git a/evaluation_examples/examples/libreoffice_calc/4188d3a4-077d-46b7-9c86-23e1a036f6c1.json b/evaluation_examples/examples/libreoffice_calc/4188d3a4-077d-46b7-9c86-23e1a036f6c1.json index 0f67ab7..8fbc5e8 100644 --- a/evaluation_examples/examples/libreoffice_calc/4188d3a4-077d-46b7-9c86-23e1a036f6c1.json +++ b/evaluation_examples/examples/libreoffice_calc/4188d3a4-077d-46b7-9c86-23e1a036f6c1.json @@ -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" } ] } diff --git a/evaluation_examples/examples/libreoffice_calc/f9584479-3d0d-4c79-affa-9ad7afdd8850.json b/evaluation_examples/examples/libreoffice_calc/f9584479-3d0d-4c79-affa-9ad7afdd8850.json index bf8c328..125f10f 100644 --- a/evaluation_examples/examples/libreoffice_calc/f9584479-3d0d-4c79-affa-9ad7afdd8850.json +++ b/evaluation_examples/examples/libreoffice_calc/f9584479-3d0d-4c79-affa-9ad7afdd8850.json @@ -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" } ] } From 6f225b2a020b1e35fd4b1772df2d729d24b2c6c1 Mon Sep 17 00:00:00 2001 From: David Chang Date: Fri, 29 Dec 2023 21:43:33 +0800 Subject: [PATCH 2/4] ver Dec29thv2 re-organized functions w.r.t. comparing xlsx with a golden one --- desktop_env/evaluators/metrics/__init__.py | 2 +- desktop_env/evaluators/metrics/table.py | 111 ++++++++---------- desktop_env/evaluators/metrics/utils.py | 8 +- .../21df9241-f8d7-4509-b7f1-37e501a823f7.json | 7 +- .../2bd59342-0664-4ccb-ba87-79379096cc08.json | 8 +- .../347ef137-7eeb-4c80-a3bb-0951f26a8aff.json | 5 +- 6 files changed, 72 insertions(+), 69 deletions(-) diff --git a/desktop_env/evaluators/metrics/__init__.py b/desktop_env/evaluators/metrics/__init__.py index 73090bc..d4aa8df 100644 --- a/desktop_env/evaluators/metrics/__init__.py +++ b/desktop_env/evaluators/metrics/__init__.py @@ -1,2 +1,2 @@ -from .table import compare_table, compare_with_sparklines, compare_with_charts +from .table import compare_table from .table import check_sheet_list, check_xlsx_freeze diff --git a/desktop_env/evaluators/metrics/table.py b/desktop_env/evaluators/metrics/table.py index 878db8a..7daa2fb 100644 --- a/desktop_env/evaluators/metrics/table.py +++ b/desktop_env/evaluators/metrics/table.py @@ -9,71 +9,62 @@ from typing import Dict, List from typing import Any -def compare_table(actual, expected): - df1 = pd.read_excel(expected) - df2 = pd.read_excel(actual) - - # Compare the DataFrames - return 1 if df1.equals(df2) else 0 - - -def compare_with_sparklines(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)) - - sp1 = load_sparklines(actual) - sp2 = load_sparklines(expected) - sparkline_metric: bool = sp1 == sp2 - print("Sparkline Metric: {:}".format(sparkline_metric)) - - return float(normal_content_metric and sparkline_metric) - - -def compare_with_charts(actual: str, expected: str, **options) -> float: +def compare_table(actual: str, expected: str, **options) -> float: """ Args: actual (str): path to result xlsx expected (str): path to gold xlsx - options (Dict[str, List[str]]): dict like {"chart_props": list of str} - giving the concerned chart properties + options (Dict[str, List[str]]): dict like + { + "features": list of str for other features, supports: + * sparkline + * chart + * number_format + "chart_props": list of str, giving the converned chart properties + } + + Return: + float: the score """ - 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)) + df1 = pd.read_excel(expected) + df2 = pd.read_excel(actual) + metric: bool = df1.equals(df2) + print("Normal Contents Metric: {:}".format(metric)) - charts1 = load_charts(actual, **options) - charts2 = load_charts(expected, **options) - chart_metric: bool = charts1 == charts2 - print("Chart Metric: {:}".format(chart_metric)) + features: List[str] = options.get("features", []) + for ftr in features: + workbook1: Workbook = openpyxl.load_workbook(actual) + workbook2: Workbook = openpyxl.load_workbook(expected) - return float(normal_content_metric and chart_metric) + if ftr=="sparkline": + sp1 = load_sparklines(actual) + sp2 = load_sparklines(expected) + new_metric: bool = sp1 == sp2 + print("Sparkline Metric: {:}".format(new_metric)) + elif ftr=="chart": + charts1 = load_charts(workbook1, **options) + charts2 = load_charts(workbook2, **options) + new_metric: bool = charts1 == charts2 + print("Chart Metric: {:}".format(new_metric)) + elif ftr=="number_format": + number_formats1: List[str] = [ c.number_format.lower()\ + for col in workbook1.active.iter_cols()\ + for c in col\ + if c.data_type=="n" + ] + number_formats2: List[str] = [ c.number_format.lower()\ + for col in workbook2.active.iter_cols()\ + for c in col\ + if c.data_type=="n" + ] + new_metric: bool = number_formats1==number_formats2 + print("Number Format Metric: {:}".format(new_metric)) + else: + raise NotImplementedError("Unsupported xlsx feature: {:}".format(ftr)) + metric = metric and new_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) + return float(metric) def check_sheet_list(result: str, rules: List[Dict[str, Any]]) -> float: # workbook: Workbook = openpyxl.load_workbook(filename=result) @@ -155,9 +146,9 @@ 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_table(path1, path2, features=["chart"], chart_props=["type", "direction"])) path1 = "../../任务数据/LibreOffice Calc/Represent_in_millions_billions_gold.xlsx" path2 = "../../任务数据/LibreOffice Calc/Represent_in_millions_billions_gold3.xlsx" @@ -172,4 +163,4 @@ if __name__ == '__main__': #print(worksheet1[position]) #print(worksheet1[position].value) #print(worksheet1[position].number_format) - print(compare_with_formats(path1, path2)) + print(compare_table(path1, path2, features=["number_format"])) diff --git a/desktop_env/evaluators/metrics/utils.py b/desktop_env/evaluators/metrics/utils.py index 65db158..b826d87 100644 --- a/desktop_env/evaluators/metrics/utils.py +++ b/desktop_env/evaluators/metrics/utils.py @@ -56,10 +56,10 @@ def load_sparklines(xlsx_file: str) -> Dict[str, str]: # type: "scatterChart" | "lineChart" | "barChart" # direction: "bar" (hori) | "col" (vert) # xtitle, ytitle, ztitle: str -def load_charts(xlsx_file: str, **options) -> Dict[str, Any]: +def load_charts(xlsx_file: Workbook, **options) -> Dict[str, Any]: """ Args: - xlsx_file (str): path to xlsx + xlsx_file (Workbook): concerned excel book options (Dict[str, List[str]]): dict like {"chart_props": list of str} giving the concerned chart properties @@ -67,8 +67,8 @@ def load_charts(xlsx_file: str, **options) -> Dict[str, Any]: Dict[str, Any]: information of charts """ - workbook: Workbook = openpyxl.load_workbook(filename=xlsx_file) - worksheet: Worksheet = workbook.active + #workbook: Workbook = openpyxl.load_workbook(filename=xlsx_file) + worksheet: Worksheet = xlsx_file.active charts: List[ChartBase] = worksheet._charts chart_set: Dict[str, Any] = {} diff --git a/evaluation_examples/examples/libreoffice_calc/21df9241-f8d7-4509-b7f1-37e501a823f7.json b/evaluation_examples/examples/libreoffice_calc/21df9241-f8d7-4509-b7f1-37e501a823f7.json index b0f9577..4347fd6 100644 --- a/evaluation_examples/examples/libreoffice_calc/21df9241-f8d7-4509-b7f1-37e501a823f7.json +++ b/evaluation_examples/examples/libreoffice_calc/21df9241-f8d7-4509-b7f1-37e501a823f7.json @@ -27,7 +27,7 @@ "libreoffice_calc" ], "evaluator": { - "func": "compare_with_formats", + "func": "compare_table", "result": { "type": "vm_file", "path": "/home/david/Represent_in_millions_billions.xlsx", @@ -37,6 +37,11 @@ "type": "cloud_file", "path": "", "dest": "Represent_in_millions_billions_gold.xlsx" + }, + "options": { + "features": [ + "number_format" + ] } } } diff --git a/evaluation_examples/examples/libreoffice_calc/2bd59342-0664-4ccb-ba87-79379096cc08.json b/evaluation_examples/examples/libreoffice_calc/2bd59342-0664-4ccb-ba87-79379096cc08.json index aa483ba..4974fcf 100644 --- a/evaluation_examples/examples/libreoffice_calc/2bd59342-0664-4ccb-ba87-79379096cc08.json +++ b/evaluation_examples/examples/libreoffice_calc/2bd59342-0664-4ccb-ba87-79379096cc08.json @@ -26,7 +26,7 @@ "libreoffice calc" ], "evaluator": { - "func": "compare_with_sparklines", + "func": "compare_table", "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", @@ -36,6 +36,10 @@ "type": "vm_file", "path": "/home/david/OrderId_Month_Chart.xlsx", "dest": "OrderId_Month_Chart.xlsx" - } + }, + "options": { + "features": [ + "sparkline" + ] } } diff --git a/evaluation_examples/examples/libreoffice_calc/347ef137-7eeb-4c80-a3bb-0951f26a8aff.json b/evaluation_examples/examples/libreoffice_calc/347ef137-7eeb-4c80-a3bb-0951f26a8aff.json index fd7a7e7..329c4f0 100644 --- a/evaluation_examples/examples/libreoffice_calc/347ef137-7eeb-4c80-a3bb-0951f26a8aff.json +++ b/evaluation_examples/examples/libreoffice_calc/347ef137-7eeb-4c80-a3bb-0951f26a8aff.json @@ -27,7 +27,7 @@ "libreoffice_calc" ], "evaluator": { - "func": "compare_with_charts", + "func": "compare_table", "result": { "type": "vm_file", "path": "/home/david/Create_column_charts_using_statistics.xlsx", @@ -39,6 +39,9 @@ "dest": "Create_column_charts_using_statistics_gold.xlsx" }, "options": { + "features": [ + "chart" + ], "chart_props": [ "type", "direction" From f73f6e1d4fc334a5a4640455e7fcfe486574abf3 Mon Sep 17 00:00:00 2001 From: David Chang Date: Fri, 29 Dec 2023 21:56:52 +0800 Subject: [PATCH 3/4] ver Dec29thv3 updated links --- .../21df9241-f8d7-4509-b7f1-37e501a823f7.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/evaluation_examples/examples/libreoffice_calc/21df9241-f8d7-4509-b7f1-37e501a823f7.json b/evaluation_examples/examples/libreoffice_calc/21df9241-f8d7-4509-b7f1-37e501a823f7.json index 4347fd6..f960d3f 100644 --- a/evaluation_examples/examples/libreoffice_calc/21df9241-f8d7-4509-b7f1-37e501a823f7.json +++ b/evaluation_examples/examples/libreoffice_calc/21df9241-f8d7-4509-b7f1-37e501a823f7.json @@ -9,7 +9,7 @@ "parameters": { "file": [ { - "url": "", + "url": "https://drive.usercontent.google.com/download?id=16PowrQA4E71xUoJmpXPHy0dr9HBcTRmo&export=download&authuser=0&confirm=t&uuid=9a6265f7-585c-4cf8-b321-3b859aec1e68&at=APZUnTWzzOw85wws0ojXNPsIwnjE:1703858126178", "path": "/home/david/Represent_in_millions_billions.xlsx" } ] @@ -35,7 +35,7 @@ }, "expected": { "type": "cloud_file", - "path": "", + "path": "https://drive.usercontent.google.com/download?id=1Jy6lZexhU5t0eW1GwXJ_csnwIe0Xiy9-&export=download&authuser=0&confirm=t&uuid=601701e7-9eb8-4ce8-83d5-35916094a15d&at=APZUnTW4WE-plIC5MmWTuFu24qLL:1703857882995", "dest": "Represent_in_millions_billions_gold.xlsx" }, "options": { From aaca06ba401166711587ca2679e117b610e7a93d Mon Sep 17 00:00:00 2001 From: David Chang Date: Fri, 29 Dec 2023 22:46:32 +0800 Subject: [PATCH 4/4] ver Dec29thv4 updated check_zoom --- desktop_env/evaluators/metrics/__init__.py | 2 +- desktop_env/evaluators/metrics/table.py | 41 +++++++++++++---- .../1334ca3e-f9e3-4db8-9ca7-b4c653be7d17.json | 44 +++++++++++++++++++ 3 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 evaluation_examples/examples/libreoffice_calc/1334ca3e-f9e3-4db8-9ca7-b4c653be7d17.json diff --git a/desktop_env/evaluators/metrics/__init__.py b/desktop_env/evaluators/metrics/__init__.py index d4aa8df..2722f2e 100644 --- a/desktop_env/evaluators/metrics/__init__.py +++ b/desktop_env/evaluators/metrics/__init__.py @@ -1,2 +1,2 @@ from .table import compare_table -from .table import check_sheet_list, check_xlsx_freeze +from .table import check_sheet_list, check_xlsx_freeze, check_zoom diff --git a/desktop_env/evaluators/metrics/table.py b/desktop_env/evaluators/metrics/table.py index 7daa2fb..f1a3eda 100644 --- a/desktop_env/evaluators/metrics/table.py +++ b/desktop_env/evaluators/metrics/table.py @@ -4,9 +4,11 @@ from openpyxl import Workbook from openpyxl.worksheet.worksheet import Worksheet from .utils import load_charts, load_sparklines +import operator from typing import Dict, List -from typing import Any +from typing import Any, Union +from numbers import Number def compare_table(actual: str, expected: str, **options) -> float: @@ -104,11 +106,17 @@ def check_sheet_list(result: str, rules: List[Dict[str, Any]]) -> float: return float(passes) - 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: + worksheet = openpyxl.load_workbook(filename=result).active + zoom_scale: Number = worksheet.sheet_view.zoomScale or 100. + return float( getattr(operator, rules["relation"])( zoom_scale + , rules["ref_value"] + ) + ) if __name__ == '__main__': # path1 = "" @@ -146,12 +154,12 @@ 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_table(path1, path2, features=["chart"], 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_table(path1, path2, features=["chart"], chart_props=["type", "direction"])) - path1 = "../../任务数据/LibreOffice Calc/Represent_in_millions_billions_gold.xlsx" - path2 = "../../任务数据/LibreOffice Calc/Represent_in_millions_billions_gold3.xlsx" + #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 # @@ -163,4 +171,21 @@ if __name__ == '__main__': #print(worksheet1[position]) #print(worksheet1[position].value) #print(worksheet1[position].number_format) - print(compare_table(path1, path2, features=["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" + #workbook1: Workbook = openpyxl.load_workbook(filename=path1) + #worksheet1: Worksheet = workbook1.active + #print(worksheet1.sheet_view.zoomScale) + #print(type(worksheet1.sheet_view.zoomScale)) +# + #import os + #import os.path + #for wb in filter( lambda f: f.endswith(".xlsx") + #, os.listdir("../../任务数据/LibreOffice Calc/") + #): + #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})) diff --git a/evaluation_examples/examples/libreoffice_calc/1334ca3e-f9e3-4db8-9ca7-b4c653be7d17.json b/evaluation_examples/examples/libreoffice_calc/1334ca3e-f9e3-4db8-9ca7-b4c653be7d17.json new file mode 100644 index 0000000..41c3cd2 --- /dev/null +++ b/evaluation_examples/examples/libreoffice_calc/1334ca3e-f9e3-4db8-9ca7-b4c653be7d17.json @@ -0,0 +1,44 @@ +{ + "id": "1334ca3e-f9e3-4db8-9ca7-b4c653be7d17", + "snapshot": "libreoffice_calc", + "instruction": "The cells are so big that I can not click on the cell I want, zoom out a little bit.", + "source": "https://techcommunity.microsoft.com/t5/excel/excel-workbook-top-way-too-big-can-t-see-rows-and-columns/m-p/4014694", + "config": [ + { + "type": "download", + "parameters": { + "file": [ + { + "url": "https://drive.usercontent.google.com/download?id=1Wkepf_vic9o7CZFiosZ4jZT_Hy2WbRPZ&export=download&authuser=0&confirm=t&uuid=bc2ce901-a6bb-433f-bcce-cbe42d813f18&at=APZUnTVQcGTcXjwqenmtSH6IMFkM:1703858853235", + "path": "/home/david/Zoom_Out_Oversized_Cells.xlsx" + } + ] + } + }, + { + "type": "open", + "parameters": { + "path": "/home/david/Zoom_Out_Oversized_Cells.xlsx" + } + } + ], + "trajectory": "trajectories/1334ca3e-f9e3-4db8-9ca7-b4c653be7d17", + "related_apps": [ + "libreoffice_calc" + ], + "evaluator": { + "func": "check_zoom", + "result": { + "type": "vm_file", + "path": "/home/david/Zoom_Out_Oversized_Cells.xlsx", + "dest": "Zoom_Out_Oversized_Cells.xlsx" + }, + "expected": { + "type": "rule", + "rules": { + "relation": "lt", + "ref_value": 260 + } + } + } +}