From e4fac099458118faa3180626b20e49de148dedf5 Mon Sep 17 00:00:00 2001 From: David Chang Date: Fri, 29 Dec 2023 21:19:52 +0800 Subject: [PATCH] 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" } ] }