From 552491f765219504db875cae11be6475f5fb13c6 Mon Sep 17 00:00:00 2001 From: David Chang Date: Sun, 21 Jan 2024 23:55:04 +0800 Subject: [PATCH] ver Jan21stv2 fixed bugs updated parts of configs --- desktop_env/evaluators/README.md | 19 +++ desktop_env/evaluators/metrics/__init__.py | 2 +- desktop_env/evaluators/metrics/table.py | 143 ++++-------------- .../0bf05a7d-b28b-44d2-955a-50b41e24012a.json | 16 +- .../0cecd4f3-74de-457b-ba94-29ad6b5dafb6.json | 20 +-- .../1334ca3e-f9e3-4db8-9ca7-b4c653be7d17.json | 25 ++- .../21df9241-f8d7-4509-b7f1-37e501a823f7.json | 18 ++- 7 files changed, 104 insertions(+), 139 deletions(-) diff --git a/desktop_env/evaluators/README.md b/desktop_env/evaluators/README.md index eff47ac..78f6a9d 100644 --- a/desktop_env/evaluators/README.md +++ b/desktop_env/evaluators/README.md @@ -7,6 +7,25 @@ pip install python-docx ``` +## LibreOffice Calc + +### Required Libraries + +``` +openpyxl +pandas +lxml +xmltodict +``` + +### How to Generate CSV from XLSX + +```sh +libreoffice --convert-to "csv:Text - txt - csv (StarCalc):44,34,UTF8,,,,false,true,true,false,false,1" --out-dir /home/user /home/user/abc.xlsx +``` + +This command will generate `abc-Sheet1.csv` under `/home/user`. The last `1` in the conversion options indicates the sheet number (starting from 1) to export. Detailed usage should be referred to at [CSV Filter Options](https://help.libreoffice.org/latest/ro/text/shared/guide/csv_params.html). + ## Chrome ### Starting Chrome with Remote Debugging for Python diff --git a/desktop_env/evaluators/metrics/__init__.py b/desktop_env/evaluators/metrics/__init__.py index 45f98b5..a658192 100644 --- a/desktop_env/evaluators/metrics/__init__.py +++ b/desktop_env/evaluators/metrics/__init__.py @@ -6,7 +6,7 @@ from .docs import is_first_line_centered, check_file_exists, compare_contains_im from .general import exact_match, fuzzy_match, check_csv, check_accessibility_tree, check_list from .libreoffice import check_libre_locale from .pdf import check_pdf_pages -from .table import check_sheet_list, check_xlsx_freeze, check_xlsx_zoom, check_data_validations +#from .table import check_sheet_list, check_xlsx_freeze, check_xlsx_zoom, check_data_validations from .table import compare_table from .vlc import is_vlc_playing, is_vlc_recordings_folder, is_vlc_fullscreen, compare_images, compare_audios, \ compare_videos diff --git a/desktop_env/evaluators/metrics/table.py b/desktop_env/evaluators/metrics/table.py index 02c6de3..b99a9da 100644 --- a/desktop_env/evaluators/metrics/table.py +++ b/desktop_env/evaluators/metrics/table.py @@ -107,11 +107,8 @@ def compare_table(result: str, expected: str, **options) -> float: for r in options["rules"]: if r["type"] == "sheet_name": # Compare Sheet Names {{{ # - # sheet_idx0: 0 == "RI0" == "RNSheet1" | "EI0" == "ENSheet1" - # sheet_idx1: as sheet_idx0 - metric: bool = worksheetr_names==worksheete_names - logger.debug("Assertion: %s.sheet_names == %s.sheet_names - %s", r["sheet_idx0"], r["sheet_idx1"], metric) + logger.debug("Assertion: %s.sheet_names == %s.sheet_names - %s", result, expected, metric) # }}} Compare Sheet Names # elif r["type"] == "sheet_data": @@ -255,112 +252,34 @@ def compare_table(result: str, expected: str, **options) -> float: # }}} function compare_table # if __name__ == '__main__': - # path1 = "" - # path2 = "" - # print(compare_table(path1, path2)) - - # path1 = "../../../../../任务数据/LibreOffice Calc/OrderId_Month_Chart_gold.xlsx" - # path2 = "../../../../../任务数据/LibreOffice Calc/OrderId_Month_Chart.xlsx" - # print(compare_with_sparklines(path1, path2)) - - # path1 = "../../../../../任务数据/LibreOffice Calc/Freeze_row_column_gold.xlsx" - # path2 = "../../../../../任务数据/LibreOffice Calc/Freeze_row_column.xlsx" - # workbook1: Workbook = openpyxl.load_workbook(filename=path1) - # worksheet1: Worksheet = workbook1.active - # print(worksheet1.freeze_panes) - # workbook2: Workbook = openpyxl.load_workbook(filename=path2) - # worksheet2: Worksheet = workbook2.active - # print(worksheet2.freeze_panes) - # 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/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/Set_Decimal_Separator_Dot.xlsx" - # path2 = "../../任务数据/LibreOffice Calc/Set_Decimal_Separator_Dot_gold.xlsx" - # workbook1: Workbook = openpyxl.load_workbook(filename=path1) - # worksheet1: Worksheet = workbook1.active - # import itertools - # for col, r in itertools.product( ['A', 'B'] - # , range(1, 20) - # ): - # position: str = "{:}{:d}".format(col, r) - # print(worksheet1[position]) - # print(worksheet1[position].value) - # print(worksheet1[position].number_format) - # workbook2: Workbook = openpyxl.load_workbook(filename=path2) - # worksheet2: Worksheet = workbook2.active - # for col, r in itertools.product( ['A', 'B'] - # , range(1, 20) - # ): - # position: str = "{:}{:d}".format(col, r) - # print(worksheet2[position]) - # print(worksheet2[position].value) - # print(worksheet2[position].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})) - - #path1 = "../../任务数据/LibreOffice Calc/Customers_New_7digit_Id.xlsx" - #path2 = "../../任务数据/LibreOffice Calc/Customers_New_7digit_Id_gold.xlsx" - #data_frame: pd.DataFrame = pd.read_excel(path1) - #print(data_frame) - #print(compare_table(path1, path2, as_shown=True)) - - #from openpyxl.worksheet.cell_range import MultiCellRange - - path = "../../任务数据/LibreOffice Calc/Order_Id_Mark_Pass_Fail_gold.xlsx" - #worksheet: Worksheet = openpyxl.load_workbook(filename=path).active - ##print(worksheet.data_validations) - #print(type(worksheet.data_validations.dataValidation)) - #for dat_vldt in worksheet.data_validations.dataValidation: - #print(dat_vldt.sqref) - #print(all(r in MultiCellRange("D2:D30 B1:B60") for r in dat_vldt.sqref)) - print( check_data_validations( path, [ { "ranges": { "method": "spreadsheet_range" - , "ref": ["D2:D29", "D2:D1048576"] - } - , "type": { "method": "eq" - , "ref": "list" - } - , "formula1": { "method": "str_set_eq" - , "ref": ["Pass", "Fail", "Held"] - } - } - ] - ) + path1 = "../../任务数据/LibreOffice Calc/Represent_in_millions_billions.xlsx" + path2 = "../../任务数据/LibreOffice Calc/Represent_in_millions_billions_gold.xlsx" + rules = [ { "type": "sheet_print" + , "sheet_idx0": 0 + , "sheet_idx1": "EI0" + , "ignore_case": "true" + } + ] + print( compare_table( path1, path2 + , rules=rules + ) ) + print( compare_table( path2, path2 + , rules=rules + ) + ) + + #path = "../../任务数据/LibreOffice Calc/Order_Id_Mark_Pass_Fail_gold.xlsx" + #print( check_data_validations( path, [ { "ranges": { "method": "spreadsheet_range" + #, "ref": ["D2:D29", "D2:D1048576"] + #} + #, "type": { "method": "eq" + #, "ref": "list" + #} + #, "formula1": { "method": "str_set_eq" + #, "ref": ["Pass", "Fail", "Held"] + #} + #} + #] + #) + #) diff --git a/evaluation_examples/examples/libreoffice_calc/0bf05a7d-b28b-44d2-955a-50b41e24012a.json b/evaluation_examples/examples/libreoffice_calc/0bf05a7d-b28b-44d2-955a-50b41e24012a.json index 524b2d1..cd82473 100644 --- a/evaluation_examples/examples/libreoffice_calc/0bf05a7d-b28b-44d2-955a-50b41e24012a.json +++ b/evaluation_examples/examples/libreoffice_calc/0bf05a7d-b28b-44d2-955a-50b41e24012a.json @@ -63,7 +63,7 @@ "command": [ "libreoffice", "--convert-to", - "csv:Text - txt - csv (StarCalc):44,34,UTF-8,,,,false,true,true", + "csv:Text - txt - csv (StarCalc):44,34,UTF-8,,,,false,true,true,false,false,1", "--outdir", "/home/user", "/home/user/Customers_New_7digit_Id.xlsx" @@ -76,11 +76,11 @@ "type": "vm_file", "path": [ "/home/user/Customers_New_7digit_Id.xlsx", - "/home/user/Customers_New_7digit_Id.csv" + "/home/user/Customers_New_7digit_Id-Sheet1.csv" ], "dest": [ "Customers_New_7digit_Id.xlsx", - "Customers_New_7digit_Id.csv" + "Customers_New_7digit_Id-Sheet1.csv" ], "multi": true }, @@ -92,12 +92,18 @@ ], "dest": [ "Customers_New_7digit_Id_gold.xlsx", - "Customers_New_7digit_Id_gold.csv" + "Customers_New_7digit_Id_gold-Sheet1.csv" ], "multi": true }, "options": { - "as_shown": true + "rules": [ + { + "type": "sheet_print", + "sheet_idx0": 0, + "sheet_idx1": "EI0" + } + ] } } } 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 89203e0..cf0cebf 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 @@ -1,7 +1,7 @@ { "id": "0cecd4f3-74de-457b-ba94-29ad6b5dafb6", "snapshot": "libreoffice_calc", - "instruction": "Copy sheet1 and insert it before sheet2", + "instruction": "Copy Sheet1 and insert it before Sheet2 and rename it as Sheet1.bak", "source": "https://www.libreofficehelp.com/add-insert-delete-copy-move-rename-a-worksheet-in-libreoffice-calc/", "config": [ { @@ -52,19 +52,21 @@ } } ], - "func": "check_sheet_list", + "func": "compare_table", "result": { "type": "vm_file", "path": "/home/user/copy_sheet_insert.xlsx", "dest": "copy_sheet_insert.xlsx" }, "expected": { - "type": "rule", + "type": "cloud_file", + "path": "https://drive.usercontent.google.com/download?id=15SjZNQtdt55SW6FIpi2JmWmVOpoZGjEB&export=download&authuser=0&confirm=t&uuid=182ac3dc-e0e9-4d30-b800-b842d5fcd665&at=APZUnTXVlvE4vv1-QO7HKqQOrikJ:1705850636082", + "dest": "copy_sheet_insert_gold.xlsx" + }, + "options": { "rules": [ { - "type": "sheet_name", - "sheet_idx": 0, - "sheet_name": "Sheet1" + "type": "sheet_name" }, { "type": "sheet_data", @@ -72,9 +74,9 @@ "sheet_idx1": 1 }, { - "type": "sheet_name", - "sheet_idx": 2, - "sheet_name": "Sheet2" + "type": "sheet_data", + "sheet_idx0": 1, + "sheet_idx1": "EI1" } ] } 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 index 76a1018..f0948e4 100644 --- a/evaluation_examples/examples/libreoffice_calc/1334ca3e-f9e3-4db8-9ca7-b4c653be7d17.json +++ b/evaluation_examples/examples/libreoffice_calc/1334ca3e-f9e3-4db8-9ca7-b4c653be7d17.json @@ -52,18 +52,31 @@ } } ], - "func": "check_xlsx_zoom", + "func": "compare_table", "result": { "type": "vm_file", "path": "/home/user/Zoom_Out_Oversized_Cells.xlsx", "dest": "Zoom_Out_Oversized_Cells.xlsx" }, "expected": { - "type": "rule", - "rules": { - "relation": "lt", - "ref_value": 260 - } + "type": "cloud_file", + "path": "https://drive.usercontent.google.com/download?id=1sX_roln3dNbXat0umlAIwZrW2eBmLkLE&export=download&authuser=0&confirm=t&uuid=a8f92992-86bd-43f4-92ce-9e4d99dca980&at=APZUnTUDPJVW_y6QeI9vlxlHAS0Q:1705851308643", + "dest": "Zoom_Out_Oversized_Cells_gold.xlsx" + }, + "options": { + "rules": [ + { + "type": "zoom", + "sheet_idx": 0, + "method": "lt", + "ref": 260 + }, + { + "type": "table_data", + "sheet_idx0": 0, + "sheet_idx1": "EI0" + } + ] } } } 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 516dc91..89b05a5 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 @@ -63,7 +63,7 @@ "command": [ "libreoffice", "--convert-to", - "csv:Text - txt - csv (StarCalc):44,34,UTF-8,,,,false,true,true", + "csv:Text - txt - csv (StarCalc):44,34,UTF-8,,,,false,true,true,false,false,1", "--outdir", "/home/user", "/home/user/Represent_in_millions_billions.xlsx" @@ -76,11 +76,11 @@ "type": "vm_file", "path": [ "/home/user/Represent_in_millions_billions.xlsx", - "/home/user/Represent_in_millions_billions.csv" + "/home/user/Represent_in_millions_billions-Sheet1.csv" ], "dest": [ "Represent_in_millions_billions.xlsx", - "Represent_in_millions_billions.csv" + "Represent_in_millions_billions-Sheet1.csv" ], "multi": true }, @@ -92,13 +92,19 @@ ], "dest": [ "Represent_in_millions_billions_gold.xlsx", - "Represent_in_millions_billions_gold.csv" + "Represent_in_millions_billions_gold-Sheet1.csv" ], "multi": true }, "options": { - "as_shown": true, - "ignore_case": true + "rules": [ + { + "type": "sheet_print", + "sheet_idx0": 0, + "sheet_idx1": "EI0", + "ignore_case": true + } + ] } } }