Datasets:
File size: 6,308 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 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 | import curation_paths as paths
import sqlite3,json,os,shutil,time,hashlib,collections as C
R=paths.R; W=paths.W; A=paths.A; L=paths.L
SRC=L+"/full_matrix_reviewed_compatibility_v4.sqlite3"; DST=L+"/full_matrix_reviewed_compatibility_v5.sqlite3"
if os.path.exists(DST): os.chmod(DST,0o644); os.remove(DST)
shutil.copy(SRC,DST); os.chmod(DST,0o644); db=sqlite3.connect(DST)
def ld(p): return json.load(open(p))
# ---- evidence sources
supp=C.defaultdict(dict)
for aid,f,vj,st,src_,ev in db.execute("select asset_id,field,value_json,status,source_table,source_record_sha256 from asset_supplement"):
supp[aid][f]=(json.loads(vj),st,src_,ev)
art={r[0]:r for r in db.execute("select asset_id,front_axis,n_urdf,urdf_agreement,min_vote_share from static_front_from_articulation")}
published=set()
for l in open(W+"/release_art/release_00/records.jsonl","rb"):
if b"articulation_kinematic_transfer" in l: published.add(json.loads(l)["asset_id"])
vlm={p["asset_id"]:p for p in ld(W+"/out/proposals_v2.json")}
pose={r[0]:r[1:] for r in db.execute("select asset_id,tier,current_up,intended_up from hssd_pose_fix_candidates")}
molmo={r[0]:r[1:] for r in db.execute("select asset_id,best_vertical,confident from molmo_vertical_inference")}
audit={r[0]:r[1:] for r in db.execute("select asset_id,state,release_pool_status,release_front_status from asset_audit_v3")}
nostyle={r[0] for r in db.execute("select distinct asset_id from style_role_candidates_supplement")}
def names(mat):
out=[]
for x in (mat.get("appearance") or {}).get("appearance",[]) if isinstance(mat,dict) else []:
n=x.get("material_appearance")
if isinstance(n,str) and n and n not in out: out.append(n)
return out
st=C.Counter(); rows=[]
for aid,rj in db.execute("select asset_id,record_json from annotations").fetchall():
r=json.loads(rj); sa={}
s=supp.get(aid,{})
if "materials" in s and not r.get("materials"):
n=names(s["materials"][0])
if n:
r["materials"]=n; sa["materials"]=dict(status="inferred",basis="appearance material names from full-corpus content groups",source=s["materials"][2],source_record_sha256=s["materials"][3]); st["materials_filled"]+=1
if "direction.mounting" in s: sa["mounting"]=dict(status="inferred",value=s["direction.mounting"][0].get("mode"),source=s["direction.mounting"][2]); st["mounting"]+=1
if "joint_motions" in s: sa["joint_motion_count"]=dict(status="inherited_authored_metadata",value=len(s["joint_motions"][0]),source=s["joint_motions"][2]); st["joint_motions"]+=1
if aid in art:
a=art[aid]; sa["front_articulation_transfer"]=dict(status="inferred",axis=a[1],n_models=a[2],agreement=a[3],min_vote_share=a[4],frame="canonical_Z_up",
in_attribute_release=aid in published,note="NOT a certificate here; the consumable form is the attribute release"); st["art_front"]+=1
v=vlm.get(aid)
if v:
sa["front_vlm_proposal"]=dict(status="proposal_unreviewed",grade=v["grade"],axis=v["axis"] if v["frame_ok"] and not v["render_unreliable"] else None,
zeros=v["zeros"],render_unreliable=bool(v["render_unreliable"]),frame_verified=bool(v["frame_ok"]),models=["qwen35_9b","gemma4_31b"],prompt="v2_with_no_unique_front_option"); st["vlm_"+v["grade"]]+=1
if aid in pose: sa["pose_candidate"]=dict(status="candidate_not_certified",tier=pose[aid][0],current_up=json.loads(pose[aid][1]),intended_up=json.loads(pose[aid][2])); st["pose_"+pose[aid][0][0]]+=1
if aid in molmo: sa["vertical_axis_inference"]=dict(status="inferred_from_category_shape_prior",best_vertical=molmo[aid][0],confident=bool(molmo[aid][1]),declared_up="Z"); st["molmo_vert"]+=1
if aid in audit: sa["pipeline_state"]=dict(state=audit[aid][0],release_pool_status=audit[aid][1],release_front_status=audit[aid][2])
if aid in nostyle: sa["style"]=dict(status="inferred_unknown_style",note="no style membership in source; supplement rows exist"); st["unknown_style"]+=1
if sa:
r["supplemental_annotations"]=dict(schema="rhg.supplemental_annotations.v1",built=time.strftime("%F"),
warning="Nothing in this block is a verified/reviewed annotation. direction/function/annotation_status are unchanged.",fields=sa)
nj=json.dumps(r,ensure_ascii=False,separators=(",",":"))
# keep the original serialisation style for untouched rows: only rewritten rows differ
rows.append((nj,aid)); st["rows_rewritten"]+=1
db.executemany("update annotations set record_json=? where asset_id=?",rows)
db.executemany("update assets set record_json=? where asset_id=?",rows)
db.executescript("DROP TABLE IF EXISTS asset_annotations_v5; CREATE TABLE asset_annotations_v5(asset_id TEXT PRIMARY KEY,pipeline_state TEXT,front_evidence TEXT,front_axis TEXT,vlm_grade TEXT,pose_tier TEXT,mounting TEXT,materials_filled INTEGER,in_attribute_release INTEGER,note TEXT);")
for aid,rj in db.execute("select asset_id,record_json from annotations where record_json like '%supplemental_annotations%'").fetchall():
f=json.loads(rj)["supplemental_annotations"]["fields"]
fe=("articulation_transfer" if "front_articulation_transfer" in f else ("vlm_proposal" if f.get("front_vlm_proposal",{}).get("axis") else "none"))
ax=f.get("front_articulation_transfer",{}).get("axis") or f.get("front_vlm_proposal",{}).get("axis")
db.execute("insert into asset_annotations_v5 values(?,?,?,?,?,?,?,?,?,?)",(aid,f.get("pipeline_state",{}).get("state"),fe,ax,f.get("front_vlm_proposal",{}).get("grade"),f.get("pose_candidate",{}).get("tier"),f.get("mounting",{}).get("value"),int("materials" in f),int(f.get("front_articulation_transfer",{}).get("in_attribute_release",False)),"not a certificate"))
db.execute("create index if not exists ix_aa5_state on asset_annotations_v5(pipeline_state)")
db.execute("insert or replace into audit_meta_v3 values('v5_note','annotations/assets record_json: materials filled where empty (inferred) + supplemental_annotations block. direction, function, annotation_status, records table untouched. Nothing is verified/reviewed.')")
db.commit(); db.execute("ANALYZE"); db.commit()
print(dict(st)); print("integrity",db.execute("pragma integrity_check").fetchone()[0]); db.close()
os.chmod(DST,0o444); print("sha256",hashlib.sha256(open(DST,"rb").read()).hexdigest()[:16])
|