Explorer
/proc/3/root/tmp/b01_runtime_setup.py
← Zurück ↓ Download
import json,hashlib,os,datetime
b='/opt/struktur/reports/aa043-p44-r1a-batches/B01'
r='/opt/struktur/reports/aa043-p44-pass-a-runtime'
expected='57c738126797341d918b1027e912309181a0c4c00191ef41150fdd6d2bd058e3'
p=b+'/p44-r1a-b01-labels.json'
got=hashlib.sha256(open(p,'rb').read()).hexdigest()
if got!=expected: raise SystemExit('B01_HASH_MISMATCH '+got)
v=json.load(open(b+'/p44-r1a-b01-validation.json'))
if v.get('BATCH_COMPLETENESS')!='PASS' or v.get('annotated_cases')!=40 or any(v.get(k)!=0 for k in ['missing_positions','duplicate_positions','duplicate_case_ids','out_of_range_positions']): raise SystemExit('B01_VALIDATION_FAIL '+json.dumps(v))
d=json.load(open(p)); items=d['items']
if len(items)!=40 or [x['global_order_position'] for x in items]!=list(range(1,41)): raise SystemExit('B01_ORDER_FAIL')
os.makedirs(r,exist_ok=True)
label=r+'/pass-a-labels.jsonl'
# idempotent exact initialization; refuse if existing content differs
lines=''.join(json.dumps(x,ensure_ascii=False,separators=(',',':'))+'\n' for x in items)
if os.path.exists(label):
 old=open(label).read()
 if old!=lines: raise SystemExit('RUNTIME_LABEL_FILE_EXISTS_DIFFERENT')
else: open(label,'w').write(lines)
ids=[x['case_id'] for x in items]
cp={'runtime_id':'AA-043-P44-R1CRON-R1','source_batch':'B01','completed_global_positions':[1,40],'completed_case_ids':ids,'count_completed':40,'next_global_position':41,'total_positions':812,'max_cases_per_run':25,'schedule':'every 10m','lock':'/opt/struktur/reports/aa043-p44-pass-a-runtime/run.lock','label_path':label,'status':'RUNNING','pass_a_completeness':None,'technical_errors':[],'updated_at':datetime.datetime.now(datetime.timezone.utc).isoformat()}
open(r+'/checkpoint.json','w').write(json.dumps(cp,ensure_ascii=False,indent=2)+'\n')
print(json.dumps({'b01_hash':got,'items':len(items),'runtime':r,'next':41,'label_bytes':os.path.getsize(label),'checkpoint':cp},ensure_ascii=False))