hvac_fable / python_files /annotate_all.py
Rachel7's picture
Deploy Fable B-test analyzer
dac3297 verified
Raw History Blame Contribute Delete
1.1 kB
import json, glob, re, sys, warnings
warnings.filterwarnings('ignore')
sys.path.insert(0, '.')
from pathlib import Path
import analyze_blueprint as ab
pdf_path = Path(r'..\raw_pdfs\355 E 86th St Mechanical 100% CD Set_flattened.pdf')
out = Path('output')
with open('output/355 E 86th St Mechanical 100% CD Set_flattened_schedule_cache.json') as f:
sched = json.load(f)
known = list(sched.keys())
tag_colors = ab._build_color_map(sorted(known))
files = sorted(glob.glob('output/floor_*_detections.json'))
for fp in files:
m = re.match(r'.*floor_(\d+)_(.+)_detections\.json', fp)
if not m: continue
page_num = int(m.group(1)); floor_name = m.group(2)
out_png = out / f'floor_{page_num:03d}_{floor_name}_annotated.png'
if out_png.exists():
continue
with open(fp) as f:
data = json.load(f)
hits = [ab.TagHit(**h) for h in data['hits']]
color_img = ab._render_page(pdf_path, page_num - 1, 300)
ab.annotate_and_save(floor_name.replace('_', ' '), page_num, color_img, hits, out, tag_colors)
print(f'annotated: {out_png.name}')
print('done')