File size: 3,385 Bytes
870b85a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import curation_paths as paths
import sqlite3,json,os,shutil,hashlib,time,collections as C
R=paths.R; W=paths.W; L=paths.L
SRC=L+"/full_matrix_reviewed_compatibility_v7.sqlite3"; DST=L+"/full_matrix_reviewed_compatibility_v9.sqlite3"
REL=json.load(open(W+"/release_9/attribute_releases.json"))
dec=json.load(open(W+"/out/front_decisions.json"))["decisions"]
# single source of truth: the front actually present in the FINAL release (any provenance); fall back to the decision table
rel_axis={}; rel_prov={}
for ref in REL["releases"]:
    d=json.load(open(ref.get("delivery") or ref["delivery_uri"])); rp=d["artifacts"]["records.jsonl"]["uri"]
    for line in open(rp,"rb"):
        if b'"functional_front"' not in line: continue
        r=json.loads(line); ff=(r["attributes"].get("functional_front") or {})
        if ff.get("status") in("inferred","measured","verified"):
            v=ff.get("value"); ax=(v.get("visual") or {}).get("axis") or v.get("axis") if isinstance(v,dict) else None
            if ax in("+X","-X","+Y","-Y"): rel_axis[r["asset_id"]]=ax; rel_prov[r["asset_id"]]=(ff.get("provenance") or {}).get("method") or ("producer_review" if ff.get("provenance") else "producer")
print("fronts present in final release:",len(rel_axis),dict(C.Counter(rel_prov.values()).most_common(6)),flush=True)
if os.path.exists(DST): os.chmod(DST,0o644); os.remove(DST)
shutil.copy(SRC,DST); os.chmod(DST,0o644); db=sqlite3.connect(DST)
rows=[];st=C.Counter()
for aid,rj in db.execute("select asset_id,record_json from annotations").fetchall():
    ax=rel_axis.get(aid); src=rel_prov.get(aid)
    if ax is None and aid in dec and dec[aid]["source"]!="vlm_unpublished": ax=dec[aid]["axis"]; src="decision:"+dec[aid]["source"]+"(not in release)"
    if ax is None: continue
    rec=json.loads(rj); a=(rec.get("annotation_status") or {}); 
    if a.get("direction") not in("unknown",None,"inferred"): st["skip_status_"+str(a.get("direction"))]+=1; continue
    rec.setdefault("annotation_status",{})["direction"]="inferred"
    fv=rec.setdefault("field_values",{}); fv["direction"]={"axis_frame":"canonical","functional_front_axis":ax,"source":src,
        "note":"inferred front axis in the canonical frame; equals the axis in the attribute release where one exists"}
    sa=rec.setdefault("supplemental_annotations",{"schema":"rhg.supplemental_annotations.v1","fields":{}}); sa["fields"]["front_axis"]=dict(status="inferred",axis=ax,source=src,decision=dec.get(aid,{}).get("source"))
    rows.append((json.dumps(rec,ensure_ascii=False,separators=(",",":")),aid)); st[src.split(":")[0] if ":" in src else src]+=1
db.executemany("update annotations set record_json=? where asset_id=?",rows); db.executemany("update assets set record_json=? where asset_id=?",rows)
db.execute("insert or replace into audit_meta_v3 values('v9_note','v9 = v7 + direction annotation (status inferred, canonical frame) for %d assets; axis = the axis in release_9 where present, else the decision table.')"%len(rows))
db.commit(); db.execute("ANALYZE"); db.commit(); print("direction annotated",len(rows),dict(st),"integrity",db.execute("pragma integrity_check").fetchone()[0])
ax=C.Counter(json.loads(r[0])["field_values"]["direction"]["functional_front_axis"] for r in rows); print("axis mix",dict(ax)); db.close(); os.chmod(DST,0o444)
print("sha256",hashlib.sha256(open(DST,"rb").read()).hexdigest()[:16])