MCPcopy Create free account
hub / github.com/ChartGalaxy/ChartGalaxy / convert_tree_json

Function convert_tree_json

code_generation_benchmark/utils/utils_eval.py:233–257  ·  view source on GitHub ↗
(logger, tree_file, file_type)

Source from the content-addressed store, hash-verified

231 gt_match_sims[i] = sims_record[i][j]
232
233def convert_tree_json(logger, tree_file, file_type):
234 assert file_type in ['gt', 'pr'], 'file_type should be gt or pr'
235 logger.info(f'converting {tree_file} to leafs')
236 tree_json = load_json(tree_file)
237 ref_bbox = tree_json['bounding_box']
238 normalize_tree_leafs(tree_json, ref_bbox)
239 leafs = parse_all_leafs(tree_json, [])
240 logger.info(f'*** {file_type} all: {len(leafs)}')
241
242 for leaf in leafs:
243 leaf['valid'] = judge_invalid_elements(leaf)
244 if file_type == 'pr' and leaf['node']['tag'] == 'image':
245 leaf['valid'] = False
246 safe_save_json(leafs, tree_file.replace('.json', '_ori_leafs.json'))
247
248 leafs = [leaf for leaf in leafs if leaf['valid']]
249 logger.info(f'*** {file_type} filter: {len(leafs)}')
250 # reorder leafs by x and y and update ids
251 leafs = sorted(leafs, key=lambda x: x['node']['norm_bbox'][0])
252 leafs = sorted(leafs, key=lambda x: x['node']['norm_bbox'][1])
253 for i, leaf in enumerate(leafs):
254 leaf['id'] = i
255 safe_save_json(leafs, tree_file.replace('.json', '_leafs.json'))
256 leaf_bboxes = [leaf['node']['norm_bbox'] for leaf in leafs]
257 vis_bboxes_with_indexes(leaf_bboxes, tree_file.replace('.json', '.png'), tree_file.replace('.json', '_leafs.png'))
258
259def compute_element_pairs(logger, gt_file, pr_file):
260 gt_leafs_file = gt_file.replace('.json', '_leafs.json')

Callers 2

single_gt_convertFunction · 0.90
single_expFunction · 0.90

Calls 6

load_jsonFunction · 0.90
safe_save_jsonFunction · 0.90
vis_bboxes_with_indexesFunction · 0.90
normalize_tree_leafsFunction · 0.85
parse_all_leafsFunction · 0.85
judge_invalid_elementsFunction · 0.85

Tested by

no test coverage detected