Files
MeltMind/docs/claude/data/warp_census.py
T

22 lines
1.8 KiB
Python

import os,sys,struct,zlib,re
d=sys.argv[1]
def txt(f):
b=open(os.path.join(d,f),'rb').read(); nl,el=struct.unpack('<HH',b[26:30]); m=struct.unpack('<H',b[8:10])[0]
x=b[30+nl+el:]; return (zlib.decompressobj(-15).decompress(x) if m==8 else x).decode('latin1')
g=lambda t,p:(lambda m:m.group(1) if m else '')(re.search(p,t))
print('file_stem,group_key,part_nodes,elements,volume_m3,melt_K,mold_K,fill_time_set_s,vol_filled_vp_pct,t_vp_s,p_vp_Pa,last_fill_pct,last_status,p_last_Pa,pack_profile_max_pct,short_shot_text,inlet_x,inlet_y,inlet_z,normal_x,normal_y,normal_z')
for f in sorted(x for x in os.listdir(d) if x.endswith('.log.bin')):
t=txt(f); s=f[:-8]
i=t.find('Filling Phase:'); j=t.find('End of filling phase results summary',i)
rows=re.findall(r'\|\s*([\d.]+)\s*\|\s*([\d.]+)\s*\|\s*([\dEe.+-]+)\s*\|[^\n]*\|\s*([A-Za-z/]+)\s*\|',t[i:j]) if i>=0 and j>i else []
last=rows[-1] if rows else ('','','','')
k=t.find('Pressure profile:'); prof=re.findall(r'[\d.]+ s\s+([\d.]+)',t[k:k+600]) if k>=0 else []
yv=txt(s+'.yml.bin') if os.path.exists(os.path.join(d,s+'.yml.bin')) else ''
nums=re.findall(r'-\s*([-\dEe.+]+)',yv)
print(','.join([s,s.split('_')[1],g(t,r'Total number of part nodes\s*=\s*(\d+)'),g(t,r'Total number of elements\s*=\s*(\d+)'),
g(t,r'Volume of tetrahedral elements\s*=\s*([\dE.+-]+)'),g(t,r'Melt temperature\s*=\s*([\d.]+)'),g(t,r'Mold temperature\s*=\s*([\d.]+)'),
g(t,r'Fill time\s*=\s*([\d.]+) s'),g(t,r'Volume filled at velocity/pressure switch-over\s*=\s*([\d.]+)'),
g(t,r'Time at velocity/pressure switch-over\s*=\s*([\d.]+)'),g(t,r'Injection pressure at velocity/pressure switch-over\s*=\s*([\dE.+-]+)'),
last[1],last[3],last[2],str(max(map(float,prof))) if prof else '',
str(bool(re.search(r'short shot|did not fill|not completely filled',t,re.I)))]+(nums[:6]+['']*6)[:6]))