import json, re, io T3 = json.load(open('ra_texts3.json', encoding='utf-8')) T4 = json.load(open('ra_texts4.json', encoding='utf-8')) S = json.load(open('ra_shapes.json', encoding='utf-8')) Mo = json.load(open('ra_model_dims.json', encoding='utf-8')) def num(s): s = s.strip().replace(',', '') try: return float(s) except Exception: return None def rows(T, xs, ylo, yhi): out = {} for x, y, l, t, h in T: if l.startswith('CS-TABL') and ylo < y < yhi: out.setdefault(round(y / 20), {})[round(x)] = t.strip() return out tab = {} order = [] r3 = rows(T3, None, -708000, -699500) last = None for y in sorted(r3, reverse=True): r = r3[y] if 64862 in r and re.match(r'^[A-Z]\d+$', r[64862]): dia = r.get(65762) if dia == '"': dia = last last = dia tab[r[64862]] = {'dia': dia, 'L': num(r[67162]), 'n': int(r[67862]), 'tot': num(r[69562])} order.append(r[64862]) # 커플러 표 (P1 54, P1-1 61) 는 제외 r4 = rows(T4, None, -707200, -705500) for y in sorted(r4, reverse=True): r = r4[y] for mx, dx, lx, nx, tx in ((89586, 90486, 91886, 92586, 94286), (99898, 100798, 102198, 102898, 104598)): if mx in r and re.match(r'^[A-Z]\d+(-\d)?$', r[mx]): dia = r.get(dx) tab[r[mx]] = {'dia': dia, 'L': num(r[lx]) * (1000 if num(r[lx]) < 100 else 1), 'n': int(r[nx]), 'tot': num(r[tx])} order.append(r[mx]) # ditto 해소 (P 계열) prev = {} for k in order: if tab[k]['dia'] == '"': tab[k]['dia'] = 'H16' tab['P1-1']['dia'] = 'H35'; tab['P1']['dia'] = 'H35'; tab['P1-2']['dia'] = 'H22' json.dump({'tab': tab, 'order': order}, open('ra_table.json', 'w', encoding='utf-8'), ensure_ascii=False) D = {} for e in S: D.setdefault(e['mark'], e) def mm(s): out = [] for p in s.strip().split('~'): p = re.sub(r'[^\d.,]', '', p).replace(',', '') if p: out.append(float(p)) return out o = io.open('ra_analysis.txt', 'w', encoding='utf-8') tot_t = 0; tot_m = 0 for mk in order: t = tab[mk]; m = Mo.get(mk) tot_t += t['tot'] if not m: o.write(u'%s 모델 없음 table n=%d L=%.0f\n' % (mk, t['n'], t['L'])); continue half = mk in ('P2', 'P2-1') cnt = m['n'] // (2 if half else 1) dl = [x * (2 if half else 1) for x in m['dl']] mean = sum(dl) / len(dl) tot = sum(m['dl']) / 1000.0 tot_m += tot line = u'%s n 표%d/모델%d L 표%.0f 모델평균%.0f(min%.0f max%.0f) 총 표%.3f 모델%.3f' % (mk, t['n'], cnt, t['L'], mean, min(dl), max(dl), t['tot'], tot) d = D.get(mk) if d: miss = [] for s in d['dims'] + d['dims2']: k, _, v = s.partition('=') k = k.strip() if k[:1] in ('j', 'x', 'r', 'd') and False: continue if k.startswith('j') or k.startswith('x'): continue for val in mm(v): if not any(abs(val - q) <= 3 for q in m['values']): miss.append('%s=%s' % (k, v)) line += u' | 도면 %s | 모델값 %s | 못 찾음 %s' % (' '.join(d['dims']), m['values'][:14], miss) o.write(line + u'\n') o.write(u'총계 표 %.3f 모델 %.3f\n' % (tot_t, tot_m)) print(len(tab), tot_t, tot_m)