File size: 1,572 Bytes
870b85a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import curation_paths as paths
import sqlite3,json,collections as C
R=paths.R; W=paths.W
db=sqlite3.connect("file:"+paths.L+"/full_matrix_reviewed_compatibility_v6.sqlite3?mode=ro",uri=True)
cat=dict(db.execute("select asset_id,normalized_category from assets")); dims={}
for a,rj in db.execute("select asset_id,record_json from assets where asset_id like 'hssd:%'"): dims[a]=json.loads(rj).get("dimensions_m")
m=C.defaultdict(list)
for u,s,ch in db.execute("select urdf_asset_id,static_asset_id,chamfer_over_bbox_diag from urdf_static_geometry_match where chamfer_over_bbox_diag<=0.005"): m[u].append((s,ch))
cats=[];dimsout=[];c=C.Counter()
for u,L in m.items():
    sc=C.Counter(cat[s] for s,_ in L if cat.get(s) and cat[s]!="unknown")
    if cat.get(u)=="unknown" and sc:
        top,n=sc.most_common(1)[0]
        if n/sum(sc.values())>=.8: cats.append(dict(asset_id=u,proposed_category=top,basis="geometry_match_to_static_hssd_asset",n_matches=len(L),agreement=round(n/sum(sc.values()),2))); c["cat_inherited"]+=1
        else: c["cat_ambiguous"]+=1
    ds=[tuple(round(x,3) for x in dims[s]) for s,_ in L if dims.get(s)]
    if ds and len(set(ds))==1: dimsout.append(dict(asset_id=u,ext_xyz_m=list(ds[0]),how="inherited_from_geometry_matched_static_asset(canonical_frame_of_static)")); c["dims_inherited"]+=1
print(dict(c),"| urdf with unknown category:",sum(1 for u in m if cat.get(u)=="unknown"),"of",len(m)); print(C.Counter(x["proposed_category"] for x in cats).most_common(6))
json.dump(dict(categories=cats,dims=dimsout),open(W+"/out/urdf_inherit.json","w"))