ver Mar6thv3

new multi_app tasks and metrics
This commit is contained in:
David Chang
2024-03-06 23:29:01 +08:00
parent e045eee901
commit 054e016aff
8 changed files with 548 additions and 2 deletions

View File

@@ -11,5 +11,4 @@ experiment_screenshot_a11y_tree.py
experiment_screenshot_seeact.py
experiment_screenshot_som.py
quick_compare_table.py
quick_evaluate.py

View File

@@ -130,7 +130,7 @@ from .vscode import (
check_python_file_by_gold_file,
compare_zip_files
)
from .others import compare_epub, check_mp3_meta
def infeasible():
pass

View File

@@ -0,0 +1,128 @@
import zipfile
import os.path
import os
import lxml.html
from lxml.html import HtmlElement
from typing import List, Dict
from typing import Union, TypeVar
from mutagen.easyid3 import EasyID3
from .general import diff_text_file
from .utils import _match_value_to_rule
import logging
logger = logging.getLogger("desktopenv.metric.others")
def process_epub(filename: str) -> List[str]:
file_list: List[str] = []
base_dir: str = filename + ".dir"
os.makedirs(base_dir, exist_ok=True)
try:
with zipfile.ZipFile(filename, "r") as z_f:
with z_f.open("toc.ncx") as in_f\
, open(os.path.join(base_dir, "toc.ncx"), "w") as out_f:
contents: str = in_f.read().decode()
contents = contents.splitlines()
for l in contents:
if "navPoint" not in l:
out_f.write(l + "\n")
file_list.append(os.path.join(base_dir, "toc.ncx"))
with z_f.open("content.opf") as in_f\
, open(os.path.join(base_dir, "content.opf"), "w") as out_f:
contents: str = in_f.read().decode()
contents = contents.splitlines()
for l in contents:
if "dc:identifier" not in l:
out_f.write(l + "\n")
file_list.append(os.path.join(base_dir, "content.opf"))
for f_n in z_f.namelist():
if f_n.endswith(".html"):
with z_f.open(f_n) as in_f\
, open(os.path.join(base_dir, f_n), "w") as out_f:
html: HtmlElement = lxml.html.fromstring(
''.join( filter( lambda ch: ch!="\n" and ch!="\r"
, in_f.read().decode()
)
).encode()
)
out_f.write(lxml.html.tostring(html, pretty_print=True, encoding="unicode"))
file_list.append(os.path.join(base_dir, f_n))
logger.debug("%s: %s", filename, file_list)
return list(sorted(file_list))
except zipfile.BadZipFile:
return []
def compare_epub(result: str, expected: str) -> float:
if result is None:
return 0.
result_files: List[str] = process_epub(result)
expected_files: List[str] = process_epub(expected)
metric: float = 1.
for f1, f2 in zip(result_files, expected_files):
current_metric: float = diff_text_file(f1, f2)
logger.debug("%s vs %s: %f", f1, f2, current_metric)
metric *= current_metric
return metric
V = TypeVar("Value")
def check_mp3_meta(result: str, meta: Dict[str, Dict[str, Union[str, V]]]) -> bool:
# checks using _match_value_to_rule
if result is None:
return 0.
id3_dict = EasyID3(result)
metric: bool = True
for k, r in meta.items():
value = id3_dict.get(k, "")
if isinstance(value, list):
value: str = value[0]
logger.debug("%s.%s: %s", result, k, value)
metric = metric and _match_value_to_rule(value, r)
return float(metric)
if __name__ == "__main__":
import datetime
import sys
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
datetime_str: str = datetime.datetime.now().strftime("%Y%m%d@%H%M%S")
file_handler = logging.FileHandler(os.path.join("logs", "normal-{:}.log".format(datetime_str)))
debug_handler = logging.FileHandler(os.path.join("logs", "debug-{:}.log".format(datetime_str)))
stdout_handler = logging.StreamHandler(sys.stdout)
sdebug_handler = logging.FileHandler(os.path.join("logs", "sdebug-{:}.log".format(datetime_str)))
file_handler.setLevel(logging.INFO)
debug_handler.setLevel(logging.DEBUG)
stdout_handler.setLevel(logging.INFO)
sdebug_handler.setLevel(logging.DEBUG)
formatter = logging.Formatter(fmt="\x1b[1;33m[%(asctime)s \x1b[31m%(levelname)s \x1b[32m%(module)s/%(lineno)d-%(processName)s\x1b[1;33m] \x1b[0m%(message)s")
file_handler.setFormatter(formatter)
debug_handler.setFormatter(formatter)
stdout_handler.setFormatter(formatter)
sdebug_handler.setFormatter(formatter)
logger.addHandler(file_handler)
logger.addHandler(debug_handler)
logger.addHandler(stdout_handler)
logger.addHandler(sdebug_handler)
metric = check_mp3_meta( "snapshots/test/cache/3f05f3b9-29ba-4b6b-95aa-2204697ffc06/Cheng Xiang - Missing You - gt.mp3"
, { "title": { "method": "eq"
, "ref": "Missing You"
}
, "artist": { "method": "eq"
, "ref": "Cheng Xiang"
}
}
)
print(metric)

View File

@@ -0,0 +1,153 @@
{
"id": "3f05f3b9-29ba-4b6b-95aa-2204697ffc06",
"snapshot": "os",
"instruction": "I have a collection of MP3s named with their artist and title. However, their meta data are messy. I don't know how to quickly fix them. Some people tells that Picard or Kid3 may help, but I have never used them. Please help me to do this.",
"source": "authors",
"config": [
{
"type": "execute",
"parameters": {
"command": ["mkdir", "-p", "/home/user/Documents/Finance/receipts", "/home/user/Documents/Projects/OSWorld", "/home/user/Documents/Novels/4th Year in Tsinghua", "/home/user/Documents/Novels/Pass Through"]
}
},
{
"type": "download",
"parameters": {
"files": [
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2308.pdf", "url": "https://drive.google.com/uc?id=1azRFXf4A7fvW0S7r9upHvleMEi-92hHM&export=download"},
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2309.pdf", "url": "https://drive.google.com/uc?id=1x-lpHm8U4U7uRPZ74-9wq9KzW2R55ln1&export=download"},
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2310.pdf", "url": "https://drive.google.com/uc?id=1pcrgV9G6NO4ekMEQBiupwXtq6mmke7b_&export=download"},
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2311.pdf", "url": "https://drive.google.com/uc?id=1JzbCK_nIY8X_3QZjnkzTtb-cRoq9zNT-&export=download"},
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2312.pdf", "url": "https://drive.google.com/uc?id=1RqbulzKG_HeYb1GZmLABOzlohlFg02UU&export=download"},
{"path": "/home/user/Documents/Finance/receipts/X-receipt-2312.pdf", "url": "https://drive.google.com/uc?id=1QzWjNzvNosG_yQr7VVonvYb3cUYF5f3u&export=download"},
{"path": "/home/user/Documents/Finance/tally_book.xlsx", "url": "https://drive.google.com/uc?id=13yuLhBPmouoWR-DybfgaIbWUOxbY_jhL&export=download"},
{"path": "/home/user/.projects.tar.xz", "url": "https://drive.google.com/uc?id=1oJcxpjqF474Wm16i1aZc8DlCEfAvc4t_&export=download"},
{"path": "/home/user/.old-chapters.tar.xz", "url": "https://drive.google.com/uc?id=11y-kLI83sQz6ncmP1-tkIR6mQJ7SfX5-&export=download"},
{"path": "/home/user/.pass-through.tar.xz", "url": "https://drive.google.com/uc?id=1z7QGTWMHhoZCAd7O1O6CWWKy49oKUowf&export=download"},
{"path": "/home/user/Music/Cheng Xiang - Missing You.mp3", "url": "https://drive.google.com/uc?id=1dqAiQoHhXn0UIatHs0iUzL266w8OhuzI&export=download"},
{"path": "/home/user/Music/Han Baoyi - Tears of Dancing Girl.mp3", "url": "https://drive.google.com/uc?id=1ePZMj14XfdzSERB6iveUMTF7nvfx45K7&export=download"},
{"path": "/home/user/Music/Huang An - I Know Missing is Painful.mp3", "url": "https://drive.google.com/uc?id=1h790X11CHFXZyB6SiftNtiq-3kd2Q12j&export=download"},
{"path": "/home/user/Music/Chen Shaohua - Red Daughter.mp3", "url": "https://drive.google.com/uc?id=1GHhlAw4KZglAwV9C5bhHDCHIFb_adJUO&export=download"},
{"path": "/home/user/Music/Zhou Xuan - Nights in Shanghai.mp3", "url": "https://drive.google.com/uc?id=1MGTK-Sr00CihcitI9ebei-HFzJNhtgIo&export=download"}
]
}
},
{
"type": "execute",
"parameters": {
"command": ["tar", "-xJvf", "/home/user/.projects.tar.xz", "-C", "/home/user/Documents/Projects/OSWorld"]
}
},
{
"type": "execute",
"parameters": {
"command": ["tar", "-xJvf", "/home/user/.old-chapters.tar.xz", "-C", "/home/user/Documents/Novels/4th Year in Tsinghua"]
}
},
{
"type": "execute",
"parameters": {
"command": ["tar", "-xJvf", "/home/user/.pass-through.tar.xz", "-C", "/home/user/Documents/Novels/Pass Through"]
}
}
],
"trajectory": "trajectories/3f05f3b9-29ba-4b6b-95aa-2204697ffc06",
"related_apps": ["os", "picard"],
"evaluator": {
"func": ["check_mp3_meta", "check_mp3_meta", "check_mp3_meta", "check_mp3_meta", "check_mp3_meta"],
"result": [
{
"type": "vm_file",
"path": "/home/user/Music/Cheng Xiang - Missing You.mp3",
"dest": "Cheng Xiang - Missing You.mp3"
},
{
"type": "vm_file",
"path": "/home/user/Music/Han Baoyi - Tears of Dancing Girl.mp3",
"dest": "Han Baoyi - Tears of Dancing Girl.mp3"
},
{
"type": "vm_file",
"path": "/home/user/Music/Huang An - I Know Missing is Painful.mp3",
"dest": "Huang An - I Know Missing is Painful.mp3"
},
{
"type": "vm_file",
"path": "/home/user/Music/Chen Shaohua - Red Daughter.mp3",
"dest": "Chen Shaohua - Red Daughter.mp3"
},
{
"type": "vm_file",
"path": "/home/user/Music/Zhou Xuan - Nights in Shanghai.mp3",
"dest": "/Zhou Xuan - Nights in Shanghai.mp3"
}
],
"expected": [
{
"type": "rule",
"rules": {
"title": {
"method": "eq",
"ref": "Missing You"
},
"artist": {
"method": "eq",
"ref": "Cheng Xiang"
}
}
},
{
"type": "rule",
"rules": {
"title": {
"method": "eq",
"ref": "Tears of Dancing Girl"
},
"artist": {
"method": "eq",
"ref": "Han Baoyi"
}
}
},
{
"type": "rule",
"rules": {
"title": {
"method": "eq",
"ref": "I Know Missing is Painful"
},
"artist": {
"method": "eq",
"ref": "Huang An"
}
}
},
{
"type": "rule",
"rules": {
"title": {
"method": "eq",
"ref": "Red Daughter"
},
"artist": {
"method": "eq",
"ref": "Chen Shaohua"
}
}
},
{
"type": "rule",
"rules": {
"title": {
"method": "eq",
"ref": "Nights in Shanghai"
},
"artist": {
"method": "eq",
"ref": "Zhou Xuan"
}
}
}
]
}
}

View File

@@ -0,0 +1,98 @@
{
"id": "42d25c08-fb87-4927-8b65-93631280a26f",
"snapshot": "chrome",
"instruction": "Hey, my friend has just sent me a web novel, but in txt files. Could you please help me convert it to epub format, so that I can easily read it on my mobile and kindle? I have found several tools to obtain an epub file, like https://github.com/kevinboone/txt2epub and https://github.com/potatoeggy/noveldown. But I'm not sure which one helps. Please help me to do this. Remember to name the file with novel's title.",
"source": "authors",
"config": [
{
"type": "launch",
"parameters": {
"command": [
"google-chrome",
"--remote-debugging-port=1337"
]
}
},
{
"type": "launch",
"parameters": {
"command": [
"socat",
"tcp-listen:9222,fork",
"tcp:localhost:1337"
]
}
},
{
"type": "chrome_open_tabs",
"parameters": {
"urls_to_open": [
"https://github.com/potatoeggy/noveldown",
"https://github.com/kevinboone/txt2epub"
]
}
},
{
"type": "execute",
"parameters": {
"command": ["mkdir", "-p", "/home/user/Documents/Finance/receipts", "/home/user/Documents/Projects/OSWorld", "/home/user/Documents/Novels/4th Year in Tsinghua", "/home/user/Documents/Novels/Pass Through"]
}
},
{
"type": "download",
"parameters": {
"files": [
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2308.pdf", "url": "https://drive.google.com/uc?id=1azRFXf4A7fvW0S7r9upHvleMEi-92hHM&export=download"},
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2309.pdf", "url": "https://drive.google.com/uc?id=1x-lpHm8U4U7uRPZ74-9wq9KzW2R55ln1&export=download"},
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2310.pdf", "url": "https://drive.google.com/uc?id=1pcrgV9G6NO4ekMEQBiupwXtq6mmke7b_&export=download"},
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2311.pdf", "url": "https://drive.google.com/uc?id=1JzbCK_nIY8X_3QZjnkzTtb-cRoq9zNT-&export=download"},
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2312.pdf", "url": "https://drive.google.com/uc?id=1RqbulzKG_HeYb1GZmLABOzlohlFg02UU&export=download"},
{"path": "/home/user/Documents/Finance/receipts/X-receipt-2312.pdf", "url": "https://drive.google.com/uc?id=1QzWjNzvNosG_yQr7VVonvYb3cUYF5f3u&export=download"},
{"path": "/home/user/Documents/Finance/tally_book.xlsx", "url": "https://drive.google.com/uc?id=13yuLhBPmouoWR-DybfgaIbWUOxbY_jhL&export=download"},
{"path": "/home/user/.projects.tar.xz", "url": "https://drive.google.com/uc?id=1oJcxpjqF474Wm16i1aZc8DlCEfAvc4t_&export=download"},
{"path": "/home/user/.old-chapters.tar.xz", "url": "https://drive.google.com/uc?id=11y-kLI83sQz6ncmP1-tkIR6mQJ7SfX5-&export=download"},
{"path": "/home/user/.pass-through.tar.xz", "url": "https://drive.google.com/uc?id=1z7QGTWMHhoZCAd7O1O6CWWKy49oKUowf&export=download"}
]
}
},
{
"type": "execute",
"parameters": {
"command": ["tar", "-xJvf", "/home/user/.projects.tar.xz", "-C", "/home/user/Documents/Projects/OSWorld"]
}
},
{
"type": "execute",
"parameters": {
"command": ["tar", "-xJvf", "/home/user/.old-chapters.tar.xz", "-C", "/home/user/Documents/Novels/4th Year in Tsinghua"]
}
},
{
"type": "execute",
"parameters": {
"command": ["tar", "-xJvf", "/home/user/.pass-through.tar.xz", "-C", "/home/user/Documents/Novels/Pass Through"]
}
},
{
"type": "launch",
"parameters": {
"command": ["nautilus", "/home/user/Documents/Novels/Pass Through"]
}
}
],
"trajectory": "trajectories/42d25c08-fb87-4927-8b65-93631280a26f",
"related_apps": ["chrome", "os"],
"evaluator": {
"func": "compare_epub",
"result": {
"type": "vm_file",
"dest": "Pass Through.epub",
"path": "/home/user/Documents/Novels/Pass Through/Pass Through.epub"
},
"expected": {
"type": "cloud_file",
"path": "https://drive.google.com/uc?id=14W0R5s0f6jMuDW9kjJMBmJsgDkyLl-aZ&export=download",
"dest": "Pass Through Gold.epub"
}
}
}

View File

@@ -0,0 +1,110 @@
{
"id": "48c46dc7-fe04-4505-ade7-723cba1aa6f6",
"snapshot": "chrome",
"instruction": "I'm currently working on OSWorld project. Every time I need to open the terminal and change to the project directory, open the file manager and change to the project directory, and open relative webpages in chrome browser. This is tedious. Help me to do this automatically. Open project directory in terminal and file manager and open github and online document in chrome browser. That's enough.",
"source": "authors",
"config": [
{
"type": "execute",
"parameters": {
"command": ["mkdir", "-p", "/home/user/Documents/Finance/receipts", "/home/user/Documents/Projects/OSWorld", "/home/user/.local/share/applications"]
}
},
{
"type": "launch",
"parameters": {
"command": [
"socat",
"tcp-listen:9222,fork",
"tcp:localhost:1337"
]
}
},
{
"type": "execute",
"parameters": {
"command": ["cp", "/usr/share/applications/google-chrome.desktop", "/home/user/.local/share/applications"]
}
},
{
"type": "execute",
"parameters": {
"command": [
"sed",
"-i.bak",
"-e",
"s#Exec=/usr/bin/google-chrome-stable#& --remote-debugging-port=1337#g",
"/home/user/.local/share/applications/google-chrome.desktop"
]
}
},
{
"type": "execute",
"parameters": {
"command": ["update-desktop-database"]
}
},
{
"type": "download",
"parameters": {
"files": [
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2308.pdf", "url": "https://drive.google.com/uc?id=1azRFXf4A7fvW0S7r9upHvleMEi-92hHM&export=download"},
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2309.pdf", "url": "https://drive.google.com/uc?id=1x-lpHm8U4U7uRPZ74-9wq9KzW2R55ln1&export=download"},
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2310.pdf", "url": "https://drive.google.com/uc?id=1pcrgV9G6NO4ekMEQBiupwXtq6mmke7b_&export=download"},
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2311.pdf", "url": "https://drive.google.com/uc?id=1JzbCK_nIY8X_3QZjnkzTtb-cRoq9zNT-&export=download"},
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2312.pdf", "url": "https://drive.google.com/uc?id=1RqbulzKG_HeYb1GZmLABOzlohlFg02UU&export=download"},
{"path": "/home/user/Documents/Finance/receipts/X-receipt-2312.pdf", "url": "https://drive.google.com/uc?id=1QzWjNzvNosG_yQr7VVonvYb3cUYF5f3u&export=download"},
{"path": "/home/user/Documents/Finance/tally_book.xlsx", "url": "https://drive.google.com/uc?id=13yuLhBPmouoWR-DybfgaIbWUOxbY_jhL&export=download"},
{"path": "/home/user/.projects.tar.xz", "url": "https://drive.google.com/uc?id=1oJcxpjqF474Wm16i1aZc8DlCEfAvc4t_&export=download"}
]
}
},
{
"type": "execute",
"parameters": {
"command": ["tar", "-xJvf", "/home/user/.projects.tar.xz", "-C", "/home/user/Documents/Projects/OSWorld"]
}
}
],
"trajectory": "trajectories/48c46dc7-fe04-4505-ade7-723cba1aa6f6",
"related_apps": ["chrome", "os"],
"evaluator": {
"postconfig": [
{
"type": "execute",
"parameters": {
"command": ["wmctrl", "-lx"],
"stdout": "wmctrl.out"
}
}
],
"func": ["check_list", "is_expected_tabs"],
"result": [
{
"type": "cache_file",
"path": "wmctrl.out"
},
{
"type": "open_tabs_info"
}
],
"expected": [
{
"type": "rule",
"rules": {
"expect": [
"\\borg\\.gnome\\.Nautilus\\.Org\\.gnome\\.Nautilus\\b.*\\bOSWorld\\b",
"gnome-terminal-server\\.Gnome-terminal\\b.*~/Documents/Projects/OSWorld\\b"
]
}
},
{
"type": "rule",
"rules": {
"type": "url",
"urls": ["https://github.com", "https://docs.python.org/3/"]
}
}
]
}
}

View File

@@ -0,0 +1,57 @@
{
"id": "788b3701-3ec9-4b67-b679-418bfa726c22",
"snapshot": "chrome",
"instruction": "I'm following a small tale set updating on https://github.com/4th-year-in-tsinghua/4th-year-in-tsinghua. I have already downloaded several chapters to my computer for reading and archiving. There should be some updates and help me to download the next chapter I haven't downloaded yet. Save it to my novel collection folder.",
"source": "authors",
"config": [
{
"type": "execute",
"parameters": {
"command": ["mkdir", "-p", "/home/user/Documents/Finance/receipts", "/home/user/Documents/Projects/OSWorld", "/home/user/Documents/Novels/4th Year in Tsinghua"]
}
},
{
"type": "download",
"parameters": {
"files": [
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2308.pdf", "url": "https://drive.google.com/uc?id=1azRFXf4A7fvW0S7r9upHvleMEi-92hHM&export=download"},
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2309.pdf", "url": "https://drive.google.com/uc?id=1x-lpHm8U4U7uRPZ74-9wq9KzW2R55ln1&export=download"},
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2310.pdf", "url": "https://drive.google.com/uc?id=1pcrgV9G6NO4ekMEQBiupwXtq6mmke7b_&export=download"},
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2311.pdf", "url": "https://drive.google.com/uc?id=1JzbCK_nIY8X_3QZjnkzTtb-cRoq9zNT-&export=download"},
{"path": "/home/user/Documents/Finance/receipts/aws-invoice-2312.pdf", "url": "https://drive.google.com/uc?id=1RqbulzKG_HeYb1GZmLABOzlohlFg02UU&export=download"},
{"path": "/home/user/Documents/Finance/receipts/X-receipt-2312.pdf", "url": "https://drive.google.com/uc?id=1QzWjNzvNosG_yQr7VVonvYb3cUYF5f3u&export=download"},
{"path": "/home/user/Documents/Finance/tally_book.xlsx", "url": "https://drive.google.com/uc?id=13yuLhBPmouoWR-DybfgaIbWUOxbY_jhL&export=download"},
{"path": "/home/user/.projects.tar.xz", "url": "https://drive.google.com/uc?id=1oJcxpjqF474Wm16i1aZc8DlCEfAvc4t_&export=download"},
{"path": "/home/user/.old-chapters.tar.xz", "url": "https://drive.google.com/uc?id=11y-kLI83sQz6ncmP1-tkIR6mQJ7SfX5-&export=download"}
]
}
},
{
"type": "execute",
"parameters": {
"command": ["tar", "-xJvf", "/home/user/.projects.tar.xz", "-C", "/home/user/Documents/Projects/OSWorld"]
}
},
{
"type": "execute",
"parameters": {
"command": ["tar", "-xJvf", "/home/user/.old-chapters.tar.xz", "-C", "/home/user/Documents/Novels/4th Year in Tsinghua"]
}
}
],
"trajectory": "trajectories/788b3701-3ec9-4b67-b679-418bfa726c22",
"related_apps": ["chrome", "os"],
"evaluator": {
"func": "diff_text_file",
"result": {
"type": "vm_file",
"path": "/home/user/Documents/Novels/4th Year in Tsinghua/早期建筑群.tex",
"dest": "download.tex"
},
"expected": {
"type": "cloud_file",
"path": "https://drive.google.com/uc?id=1kiCDbTn7uYfgqbymddC5IKMsvpkihW-s&export=download",
"dest": "real.tex"
}
}
}

View File

@@ -43,3 +43,4 @@ beautifulsoup4
dashscope
google-generativeai
PyYaml
mutagen