|
|
|
|
|
import json |
|
|
|
|
|
def read_json(file_path): |
|
|
with open(file_path, 'r', encoding='utf-8') as file: |
|
|
data = json.load(file) |
|
|
return data |
|
|
|
|
|
def write_json(file_path, data): |
|
|
with open(file_path, 'w', encoding='utf-8') as file: |
|
|
json.dump(data, file, ensure_ascii=False, indent=4) |
|
|
|
|
|
data = read_json('/inspire/hdd/ws-ba572160-47f8-4ca1-984e-d6bcdeb95dbb/a100-maybe/wangbaode/NIPS_2025/Agent/Dataset/android_env/intermediate_data_8k.json') |
|
|
|
|
|
|
|
|
|
|
|
def parse_node(node, nodes, depth=0, parent_bounds=None): |
|
|
|
|
|
class_name = node.get("className", "Unknown") |
|
|
|
|
|
view_id = node.get("viewIdResourceName", "") |
|
|
simplified_view_id = view_id.split(":")[-1] if view_id else "" |
|
|
simplified_view_id = ' '.join(simplified_view_id.split('_')) |
|
|
simplified_view_id = simplified_view_id.replace('id/','') |
|
|
|
|
|
bounds = node.get("boundsInScreen", {}) |
|
|
|
|
|
bounds_str = f"[{bounds.get('left', 0)}, {bounds.get('top', 0)}, {bounds.get('right', 0)}, {bounds.get('bottom', 0)}]" |
|
|
|
|
|
|
|
|
if parent_bounds and bounds == parent_bounds: |
|
|
bounds_str = "" |
|
|
|
|
|
|
|
|
node_str = f"{' ' * depth}└── {simplified_view_id} {f'({bounds_str})' if bounds_str else ''}" |
|
|
|
|
|
|
|
|
children_str = "" |
|
|
if "childIds" in node: |
|
|
children = [child for child in nodes if 'uniqueId' in child and child['uniqueId'] in node['childIds']] |
|
|
for child in children: |
|
|
children_str += "\n" + parse_node(child, nodes, depth + 1, bounds) |
|
|
|
|
|
return node_str + children_str |
|
|
|
|
|
|
|
|
def parse_tree(window_data): |
|
|
|
|
|
window_info = window_data['windows'][0] |
|
|
window_type = window_info.get('windowType', 'Unknown') |
|
|
root_node_str = f"Window ({window_type})" |
|
|
nodes = window_info['tree']['nodes'] |
|
|
root_node_str += "\n" + parse_node(nodes[0], nodes, 1) |
|
|
return root_node_str |
|
|
|
|
|
json_dict = json.loads(data[0]['accessibility_trees'][0]) |
|
|
|
|
|
tree_output = parse_tree(json_dict) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from tqdm import tqdm |
|
|
|
|
|
for i in tqdm(data): |
|
|
accessibility_trees = [] |
|
|
for trees in i['accessibility_trees']: |
|
|
if len(trees) < 20: |
|
|
continue |
|
|
|
|
|
json_dict = json.loads(trees) |
|
|
tree_output = parse_tree(json_dict) |
|
|
|
|
|
accessibility_trees.append(tree_output) |
|
|
|
|
|
i['accessibility_trees'] = accessibility_trees |
|
|
|
|
|
|
|
|
|
|
|
write_json('/inspire/hdd/ws-ba572160-47f8-4ca1-984e-d6bcdeb95dbb/a100-maybe/wangbaode/NIPS_2025/Agent/Dataset/android_env/intermediate_data.json', data) |
|
|
|