File size: 3,329 Bytes
e8055cf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | """Shared fixtures and helpers for report-export tests."""
import json
import tempfile
import unittest
from pathlib import Path
from analysis.letters_reports import (
analyze_modular,
export_reports,
load_profile as load,
)
def vlm(letter, qid=1, score=1.0, protocol="base", model="m", frames=32):
r = {
"model": model,
"protocol": protocol,
"condition": protocol,
"question_id": qid,
"scene": "s",
"dataset": "d",
"question_type": "count",
"score": score,
"frame_count": frames,
"input_token_count": 10,
"output_token_count": 2,
"generation_seconds": 1.0,
"answer_given": "x",
"full_prompt": "p",
}
if letter == "A":
r["frame_selection"] = "uniform"
elif letter in "BC":
r.update(
input_selection="uniform",
spatial_code_format="explicit",
depth="metric",
tracking="tracking",
)
return r
def put(root, relative, record):
p = root / relative
p.parent.mkdir(parents=True, exist_ok=True)
p.write_text(json.dumps(record))
return p
class ReportTestCase(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.root = Path(self.temp.name)
def tearDown(self):
self.temp.cleanup()
def directory(self, letter, records):
d = self.root / letter
d.mkdir()
for i, r in enumerate(records):
put(d, f"{i}.json", r)
return d
def symbolic(self, future=False):
d = self.root / ("F_future" if future else "F")
d.mkdir(exist_ok=True)
prefix = (
"perceived/metric/tracking/uniform/32/explicit"
if future
else "metric/tracking/uniform/32/explicit"
)
put(
d,
f"{prefix}/s/1.json",
{
"model": "symbolic",
"condition": "metric:tracking:uniform:32:explicit",
"question_id": 1,
"scene": "s",
"dataset": "d",
"question_type": "count",
"score": 1.0,
"spatial_code_format": "explicit",
"depth": "metric",
"tracking": "tracking",
"input": "uniform",
"number_of_frames": 32,
},
)
return d
def ground_truth_symbolic(self):
d = self.root / "F"
d.mkdir()
put(
d,
"ground truth/explicit/s/1.json",
{
"model": "symbolic",
"condition": "ground truth:explicit",
"question_id": 1,
"scene": "s",
"dataset": "d",
"question_type": "count",
"score": 1.0,
"spatial_code_format": "explicit",
},
)
return d
def analyze(self, letters, dirs, pairs=(), protocols=("base",)):
profiles = {l: load(l) for l in letters}
per, combined = analyze_modular(
{l: dirs[l] for l in letters}, profiles, protocols, pairs
)
paths = export_reports(per, combined, self.root / "reports")
return per, combined, {p.name for p in paths}
|