30 行
1.3 KiB
Python
30 行
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
||
u"""布线缓存的「方向符合度」:每层按长度算顺 / 逆 / 斜各占多少(L1 优选 x、L4 优选 y,route_base.LAYER_DIR)。
|
||
|
||
/c/Python314/python .claude/r2/dir_stats.py [缓存.json ...] # 默认 _base_routes.json
|
||
"""
|
||
import io, json, math, os, sys
|
||
sys.stdout.reconfigure(encoding='utf-8')
|
||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||
PREF = {1: 'x', 2: 'y'}
|
||
NAME = {1: 'L1 插槽面(优选 x)', 2: 'L4 器件面(优选 y)'}
|
||
for path in (sys.argv[1:] or [os.path.join(HERE, '_base_routes.json')]):
|
||
d = json.load(io.open(path, encoding='utf-8'))
|
||
print(u'%s:%d 段 / %d 孔 / 未完成 %d' % (os.path.basename(path), len(d['segs']), len(d['vias']), len(d['logs'])))
|
||
for l in (1, 2):
|
||
a = {'顺': 0.0, '逆': 0.0, '斜': 0.0}
|
||
for s in d['segs']:
|
||
if s[0] != l:
|
||
continue
|
||
dx, dy = abs(s[3] - s[1]), abs(s[4] - s[2])
|
||
L = math.hypot(dx, dy)
|
||
if dx > 1e-6 and dy > 1e-6:
|
||
a['斜'] += L
|
||
elif (dx > dy) == (PREF[l] == 'x'):
|
||
a['顺'] += L
|
||
else:
|
||
a['逆'] += L
|
||
t = sum(a.values()) or 1.0
|
||
print(u' %s 总 %7.1f mm:顺 %5.1f%% 逆 %5.1f%% 斜 %5.1f%%'
|
||
% (NAME[l], t, 100 * a['顺'] / t, 100 * a['逆'] / t, 100 * a['斜'] / t))
|