Datasets:
File size: 4,927 Bytes
3f15e9f | 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 | """Measure one saved residential trial without changing native evidence."""
import argparse
import hashlib
import json
from pathlib import Path
import sys
def read(path):
return json.loads(Path(path).read_text())
def sha(path):
h = hashlib.sha256()
with Path(path).open('rb') as stream:
for block in iter(lambda: stream.read(4 * 1024 * 1024), b''):
h.update(block)
return h.hexdigest()
def selected_scene_qualified(result, diagnostic_geometry=None):
"""A rendered diagnostic attempt keeps its own native acceptance verdict."""
if diagnostic_geometry is not None:
return diagnostic_geometry.get('full_geometry_passed') is True
return result.get('geometry_passed') is True
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--tree', required=True, type=Path)
parser.add_argument('--case', required=True, type=Path)
parser.add_argument('--out', required=True, type=Path)
parser.add_argument('--diagnostic-attempt', type=Path)
args = parser.parse_args()
sys.path[:0] = [str(args.tree), str(args.tree/'engine'),
str(args.tree/'engine/source/scripts/internal/scene_generation/real_assets')]
args.out.mkdir(parents=True, exist_ok=False)
ledger = read(args.case/'layout_recovery_execution.json')
case = Path(ledger['final_case'])
output = Path(ledger['final_output'])
result = read(output/'result.json')
geometry = None
if args.diagnostic_attempt:
attempt = args.diagnostic_attempt.resolve()
if args.case.resolve() not in attempt.parents:
raise ValueError('Diagnostic attempt must belong to this case')
geometry = read(attempt/'geometry/result.json')
matches = [p for p in (attempt/'generated').glob('*/composition_manifest.runtime.json')
if sha(p) == geometry.get('manifest_sha256')]
if len(matches) != 1:
raise ValueError('Need exactly one native geometry-bound manifest')
manifest_path = matches[0]
blend = manifest_path.parent/(manifest_path.parent.name+'.blend')
if sha(blend) != geometry.get('scene_sha256'):
raise ValueError('Native geometry scene hash mismatch')
else:
manifest_path = Path(result['generated_manifest'])
if result.get('generated_manifest_sha256') != sha(manifest_path):
raise ValueError('Native result does not match saved manifest')
manifest = read(manifest_path)
shell_path = manifest_path.parent/'shell_geometry_input.json'
shell = read(shell_path)
if not shell.get('floor_mesh_bounds') or not shell.get('wall_mesh_bounds'):
raise ValueError('Measured shell bounds unavailable; no approximate passability substitution')
spec_path = args.case/'desired_scene_spec.json'
from residential_quality import evaluate
from layout_conventions_audit import audit
from passability import analyse_with_sensitivity, BODY_RADIUS_M, CARRY_RADIUS_M
from room_plan_render import render_room_plans
report = dict(case=str(case), output=str(output), recovery=ledger, native_result=result,
geometry_qualified=selected_scene_qualified(result, geometry),
final_result_geometry_qualified=result.get('geometry_passed') is True,
scope='Saved manifest measurements and native evidence; robot dynamics not simulated',
diagnostic_attempt=str(args.diagnostic_attempt) if args.diagnostic_attempt else None,
diagnostic_only=bool(args.diagnostic_attempt), native_geometry=geometry,
sources={str(p): sha(p) for p in (manifest_path, shell_path, spec_path, output/'result.json')})
for name, call in (
('quality', lambda: evaluate(manifest, read(spec_path))),
('conventions', lambda: audit(manifest, shell)),
('body_passability', lambda: analyse_with_sensitivity(manifest['floor_plan'], manifest['entities'], shell, BODY_RADIUS_M)),
('carry_passability', lambda: analyse_with_sensitivity(manifest['floor_plan'], manifest['entities'], shell, CARRY_RADIUS_M)),
):
try:
report[name] = call()
except Exception as exc:
report[name] = dict(measured=False, error=repr(exc))
try:
report['room_plans'] = render_room_plans(manifest, args.out/'room_plans', shell,
report.get('conventions', {}).get('findings', []))
except Exception as exc:
report['room_plan_error'] = repr(exc)
(args.out/'measurements.json').write_text(json.dumps(report, ensure_ascii=False, indent=2, allow_nan=False)+'\n')
print(json.dumps(dict(report=str(args.out/'measurements.json'), geometry_qualified=report['geometry_qualified'],
entity_count=len(manifest['entities'])), ensure_ascii=False))
if __name__ == '__main__':
main()
|