#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""PD132T ↔ PD136HA 灵敏度档位对齐图(现场调档照着贴)—— 纯 stdlib 手写 SVG
横轴 = Δf/f(进入/离开阈值的相对频偏,%);每档画 进入(实心)+离开(浅色) 两段
偏差 = 同档位号一对一映射的 (H−T)/T;最佳匹配 = 最近的进入阈值
转 PNG:chromium --headless=new --disable-gpu --no-sandbox \
--screenshot=docs/img/sens-alignment-pd132t-pd136ha.png --window-size=1500,880 \
file://$PWD/docs/img/sens-alignment-pd132t-pd136ha.svg
"""
W, H = 1500, 1060
FONT = "'Noto Serif CJK SC','Noto Sans CJK SC',sans-serif"
K = 65536.0
out = []
def esc(s):
return s.replace('&', '&').replace('<', '<').replace('>', '>')
def txt(x, y, s, size=14, fill='#222', anchor='start', weight='normal'):
out.append('%s'
% (x, y, size, fill, anchor, weight, FONT, esc(s)))
def line(x1, y1, x2, y2, stroke='#999', w=1.0, dash=None):
d = ' stroke-dasharray="%s"' % dash if dash else ''
out.append('' % (x1, y1, x2, y2, stroke, w, d))
def rect(x, y, w, h, fill='none', stroke='none', rx=2, sw=1.0, op=1.0):
out.append(''
% (x, y, w, h, rx, fill, op, stroke, sw))
def note(x, y, w, h, title, lines_, color='#0b6'):
rect(x, y, w, h, '#fbfdff', color, rx=6, sw=1.2, op=0.95)
txt(x + 12, y + 24, title, 14.5, color, weight='bold')
for i, s in enumerate(lines_):
txt(x + 12, y + 48 + i * 21, s, 13, '#333')
T_IN = [300, 60, 32, 21] # PD132T 进入表(档0..3)
T_OUT = [60, 32, 21, 14] # PD132T 离开表
H_IN = [162, 81, 54, 28] # PD136HA 进入表
H_OUT = [81, 54, 32, 18] # PD136HA 离开表
ct = lambda v: v / K * 100.0
out.append('')
open(OPEN, 'w', encoding='utf-8').write('\n'.join(out))
print('已写出 %s' % OPEN)
for i in range(4):
viT, viH = ct(T_IN[i]), ct(H_IN[i])
j = min(range(4), key=lambda k: abs(H_IN[k] - T_IN[i]))
print(' 档%d: PD132T %.4f%% ↔ PD136HA %.4f%%(同档 %+.1f%%)| 最近档 %d(%+.1f%%)'
% (i, viT, viH, (viH - viT) / viT * 100, j, (ct(H_IN[j]) - viT) / viT * 100))