38 lines
2.1 KiB
Python
38 lines
2.1 KiB
Python
"""Octo 1.12 client tables vs current native client tables: by ID, common DBD field names."""
|
|
import os,json,collections,sys
|
|
W=os.path.dirname(os.path.abspath(__file__))
|
|
def load(p):
|
|
rows={}
|
|
for l in open(p,encoding='utf8',errors='replace'):
|
|
c=l.rstrip('\n').split('\t'); d=dict(x.split('=',1) for x in c[1:] if '=' in x)
|
|
if 'ID' in d:
|
|
try: rows[int(d['ID'])]=d
|
|
except ValueError: pass
|
|
return rows
|
|
def same(a,b):
|
|
if a==b: return True
|
|
try:
|
|
A=[float(x) for x in a.split(',')]; B=[float(x) for x in b.split(',')]
|
|
if len(A)!=len(B):
|
|
n=min(len(A),len(B)); return A[:n]==B[:n] and not any(A[n:]) and not any(B[n:])
|
|
return all(abs(x-y)<=1e-4*max(1,abs(x)) for x,y in zip(A,B))
|
|
except ValueError: return False
|
|
if __name__=='__main__':
|
|
rep={}
|
|
for f in sorted(os.listdir(W+'/dump')):
|
|
if not f.endswith('.octo.tsv'): continue
|
|
t=f[:-9]; o=load(W+'/dump/'+f); np=W+'/dump/'+t+'.native.tsv'
|
|
if not os.path.exists(np): rep[t]=dict(octo=len(o),native=None); continue
|
|
n=load(np); common=set(o)&set(n)
|
|
fields=[k for k in (next(iter(o.values())).keys() if o else []) if k!='ID' and n and k in next(iter(n.values()))]
|
|
diff=collections.Counter(); drows=[]
|
|
for i in common:
|
|
bad=[k for k in fields if not same(o[i].get(k,''),n[i].get(k,''))]
|
|
if bad: drows.append(i); diff.update(bad)
|
|
missing=sorted(set(o)-set(n))
|
|
rep[t]=dict(octo=len(o),native=len(n),missing=len(missing),missing_ids=missing[:50],differ=len(drows),differ_ids=sorted(drows)[:30],fields=dict(diff.most_common(8)),compared_fields=len(fields))
|
|
json.dump(rep,open(W+'/compare.json','w'),indent=1)
|
|
for t,r in sorted(rep.items(),key=lambda kv:-(kv[1].get('missing') or 0)-(kv[1].get('differ') or 0)):
|
|
if r.get('native') is None: print(f"{t:28} octo {r['octo']:6} NO NATIVE TABLE"); continue
|
|
print(f"{t:28} octo {r['octo']:6} native {r['native']:7} missing {r['missing']:5} differ {r['differ']:5} fields {r['compared_fields']:3} {r['fields']}")
|