Spaces:
Paused
Paused
Download python_files/summarize_floors.py from Rachel7/hvac_fable: direct link, hf CLI and curl.
- Browser
- Download file 2.09 kB
-
https://huggingface.co/spaces/Rachel7/hvac_fable/resolve/main/python_files/summarize_floors.py
- Command line
-
hf download hf://spaces/Rachel7/hvac_fable/python_files/summarize_floors.py
-
curl -L -o summarize_floors.py https://huggingface.co/spaces/Rachel7/hvac_fable/resolve/main/python_files/summarize_floors.py
2.09 kB
| import json, glob, re | |
| from collections import Counter | |
| from pathlib import Path | |
| files = sorted(glob.glob('output/floor_*_detections.json')) | |
| print(f'{len(files)} floors processed:\n') | |
| # Schedule for comparison | |
| with open(r'output/355 E 86th St Mechanical 100% CD Set_flattened_schedule_cache.json') as f: | |
| sched = json.load(f) | |
| schedule_totals = {tag: info.get('qty') or 0 for tag, info in sched.items()} | |
| all_tags_seen = set() | |
| floor_counts = {} | |
| 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).replace('_', ' ') | |
| with open(fp) as f: | |
| hits = json.load(f)['hits'] | |
| counts = Counter(h['tag'] for h in hits) | |
| floor_counts[(page_num, floor_name)] = counts | |
| all_tags_seen.update(counts.keys()) | |
| tags_present = sorted(t for t in schedule_totals if schedule_totals.get(t, 0) > 0 or t in all_tags_seen) | |
| # Build table | |
| header = ['Floor'] + tags_present + ['Total'] | |
| rows = [] | |
| det_totals = Counter() | |
| for (pn, fn), counts in sorted(floor_counts.items()): | |
| row = [f'{pn:>2} {fn}'] | |
| total = 0 | |
| for tag in tags_present: | |
| cnt = counts.get(tag, 0) | |
| det_totals[tag] += cnt | |
| total += cnt | |
| row.append(str(cnt) if cnt else '-') | |
| row.append(str(total)) | |
| rows.append(row) | |
| # Schedule and detected total rows | |
| sched_row = ['Schedule'] + [str(schedule_totals.get(t, 0)) for t in tags_present] + [str(sum(schedule_totals.get(t,0) for t in tags_present))] | |
| det_row = ['Detected'] + [str(det_totals.get(t, 0)) for t in tags_present] + [str(sum(det_totals.values()))] | |
| # Print table | |
| col_widths = [max(len(r[i]) for r in (rows + [header, sched_row, det_row])) for i in range(len(header))] | |
| def fmt_row(row): | |
| return ' '.join(c.rjust(w) if i > 0 else c.ljust(w) for i, (c, w) in enumerate(zip(row, col_widths))) | |
| print(fmt_row(header)) | |
| print('-' * (sum(col_widths) + 2 * (len(col_widths) - 1))) | |
| for r in rows: | |
| print(fmt_row(r)) | |
| print('-' * (sum(col_widths) + 2 * (len(col_widths) - 1))) | |
| print(fmt_row(sched_row)) | |
| print(fmt_row(det_row)) | |