File size: 2,552 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
import curation_paths as paths
import sqlite3,json,os,shutil,time,hashlib,sys,collections as C
R=paths.R; W=paths.W; L=paths.L
SRC=L+"/full_matrix_reviewed_compatibility_v5.sqlite3"; DST=L+"/full_matrix_reviewed_compatibility_v6.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)
pub=json.load(open(W+"/release_pose/publication.json")); FIX=set(pub["fix"])
M_NEW=[1.0,0.0,0.0,0.0,0.0,-1.0,0.0,0.0,0.0,0.0,-1.0,0.0,0.0,0.0,0.0,1.0]
rows=[];n=0;skip=C.Counter()
for aid in FIX:
    r=db.execute("select record_json from annotations where asset_id=?",(aid,)).fetchone()
    if not r: skip["missing"]+=1; continue
    rec=json.loads(r[0]); d=rec.get("dimensions_m")
    if not d or len(d)<3: skip["no_dims"]+=1; continue
    if rec.get("canonical_transform")!=[1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1] and rec.get("canonical_transform")!=[1.0,0.0,0.0,0.0,0.0,0.0,-1.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,1.0]: skip["unexpected_old_matrix"]+=1; continue
    nd=[d[0],d[2],d[1]]
    rec["canonical_transform"]=list(M_NEW); fv=rec.setdefault("field_values",{})
    fv.setdefault("coordinate_transform",{})["source_to_canonical"]=list(M_NEW)
    rec["dimensions_m"]=nd
    if isinstance(fv.get("dimensions"),dict): fv["dimensions"]["dimensions_m"]=list(nd)
    sa=rec.setdefault("supplemental_annotations",{"schema":"rhg.supplemental_annotations.v1","fields":{}}); 
    sa["fields"]["pose_correction"]=dict(status="measured_from_authored_up_and_scene_placements",old_transform=[1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1],new_transform=M_NEW,old_dimensions_m=d,new_dimensions_m=nd,
        evidence="release_pose pose_fix_evidence (authored objects.csv up=(0,0,-1) + 168 scene placements + producer conflict)")
    nj=json.dumps(rec,ensure_ascii=False,separators=(",",":")); rows.append((nj,json.dumps(nd),aid)); n+=1
db.executemany("update annotations set record_json=? where asset_id=?",[(a,c) for a,b,c in rows])
db.executemany("update assets set record_json=?,dimensions_json=? where asset_id=?",rows)
db.execute("insert or replace into audit_meta_v3 values('v6_note','v6 = v5 + pose-corrected transform/dimensions for %d HSSD assets whose authored up axis is -Z (see release_pose). Matches release_pose identity/geometry exactly.')"%n)
db.commit(); db.execute("ANALYZE"); db.commit()
print("updated",n,"skipped",dict(skip),"integrity",db.execute("pragma integrity_check").fetchone()[0]); db.close(); os.chmod(DST,0o444)
print("sha256",hashlib.sha256(open(DST,"rb").read()).hexdigest()[:16])