feat: 新增阶梯提醒与请求失败告警规则
- 阶梯提醒:以「上次提醒时的价格」为基准,每偏离一个步长提醒一次并更新基准; 方向支持每上涨/每下跌/双向,步长可填具体变动值或百分比,基准落盘 rule-state.json - 请求失败告警:某品种连续抓取失败达到设定次数时提醒一次;抓取成功即清零, 下一波连续失败可重新触发;支持「持续失败每 N 秒重复提醒」与生效时段 - 配置归一化接受 ladder / failure 类型,失败告警的 value 按次数取整、冷却固定为 0 - 规则弹窗补充两类规则的字段显隐、方向文案、预览与说明;重复间隔标签按类型切换 - 规则列表新增橙色「阶梯」、红色「失败告警」标签,失败告警不展示冷却 - README 补阶梯提醒与请求失败告警章节,规则类型更新为六类
This commit is contained in:
+11
-5
@@ -2,7 +2,7 @@
|
||||
* 配置存取层。
|
||||
* 配置全部落在 config/config.json:
|
||||
* - instruments 监控品种(数据源、刷新频率、单位等)
|
||||
* - rules 提醒规则(阈值 / 涨跌幅 / 价差)
|
||||
* - rules 提醒规则(阈值 / 涨跌幅 / 阶梯 / 价差 / 定时 / 请求失败告警)
|
||||
* - email 邮箱 SMTP 配置
|
||||
* - desktop Windows 桌面通知开关
|
||||
* - monitor 全局轮询与静默时段
|
||||
@@ -181,13 +181,18 @@ function normalizeScheduleTimes(raw) {
|
||||
}
|
||||
|
||||
function normalizeRule(raw, index) {
|
||||
const type = ['threshold', 'change', 'spread', 'schedule'].includes(raw?.type) ? raw.type : 'threshold';
|
||||
const type = ['threshold', 'change', 'spread', 'schedule', 'ladder', 'failure'].includes(raw?.type) ? raw.type : 'threshold';
|
||||
const channels = Array.isArray(raw?.channels)
|
||||
? raw.channels.filter((c) => CHANNEL_KEYS.includes(c))
|
||||
: ['desktop'];
|
||||
const direction = ['above', 'below', 'abs', 'up', 'down', 'both'].includes(raw?.direction)
|
||||
? raw.direction
|
||||
: (type === 'threshold' ? 'above' : 'abs');
|
||||
: (type === 'threshold' ? 'above' : type === 'ladder' ? 'up' : 'abs');
|
||||
|
||||
// 请求失败告警的 value 是「连续失败次数」,必须是 1 以上的整数,默认 3 次
|
||||
const value = type === 'failure'
|
||||
? Math.round(clampNumber(raw?.value, 3, 1, 500))
|
||||
: clampNumber(raw?.value, 0, -1e9, 1e9);
|
||||
|
||||
return {
|
||||
id: raw?.id ? String(raw.id) : uid('rule'),
|
||||
@@ -198,8 +203,9 @@ function normalizeRule(raw, index) {
|
||||
compareInstrumentId: raw?.compareInstrumentId ? String(raw.compareInstrumentId) : '',
|
||||
mode: raw?.mode === 'percent' ? 'percent' : 'abs',
|
||||
direction,
|
||||
value: clampNumber(raw?.value, 0, -1e9, 1e9),
|
||||
cooldownSec: Math.round(clampNumber(raw?.cooldownSec, 1800, 30, 86400 * 7)),
|
||||
value,
|
||||
// 请求失败告警不看「次数」以外的条件,冷却固定为 0(重复频率交给 repeatIntervalSec)
|
||||
cooldownSec: type === 'failure' ? 0 : Math.round(clampNumber(raw?.cooldownSec, 1800, 30, 86400 * 7)),
|
||||
repeatIntervalSec: Math.round(clampNumber(raw?.repeatIntervalSec, 0, 0, 86400)),
|
||||
// 涨跌幅的统计区间(秒):0 = 日内(相对昨收),>0 = 近 N 秒的滚动窗口
|
||||
windowSec: Math.round(clampNumber(raw?.windowSec, 0, 0, 43200)),
|
||||
|
||||
Reference in New Issue
Block a user