| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- namespace EasyTemplate.Tool
- {
- /// <summary>
- /// 预警告计算规则配置(对应 C++ VR::rules 命名空间)
- /// </summary>
- public static class VRRules
- {
- private static bool? _refReachCount;
- private static int? _refCount;
- private static int? _refPrewarningIndex;
- private static int? _refPrewarningIndexAlert;
- private static bool? _bCountAllDay;
- /// <summary>
- /// 北京模式:是否使用达标计数模式
- /// 为 true 时:超标率>=阈值 且 总笔数>=5 时计为连续一天
- /// 为 false 时:使用标准模式(总笔数>=ref_count 时才检查超标率)
- /// </summary>
- public static bool RefReachCount
- {
- get
- {
- var value = Setting.Get<bool?>("VRRules:RefReachCount");
- return _refReachCount ?? (value ?? false);
- }
- set => _refReachCount = value;
- }
- /// <summary>
- /// 标准模式下的参考笔数阈值(通常为 5)
- /// 当累计总笔数达到此值时才进行超标率判断
- /// </summary>
- public static int RefCount
- {
- get
- {
- var value = Setting.Get<int?>("VRRules:RefCount");
- return _refCount ?? (value ?? 5);
- }
- set => _refCount = value;
- }
- /// <summary>
- /// 预报警超标率阈值(%)
- /// 当累计超标率>=此值时判定为超标
- /// </summary>
- public static int RefPrewarningIndex
- {
- get
- {
- var value = Setting.Get<int?>("VRRules:RefPrewarningIndex");
- return _refPrewarningIndex ?? (value ?? 20);
- }
- set => _refPrewarningIndex = value;
- }
- /// <summary>
- /// 预报警严重超标率阈值(%)
- /// 当累计严重超标率>=此值时判定为严重超标
- /// </summary>
- public static int RefPrewarningIndexAlert
- {
- get
- {
- var value = Setting.Get<int?>("VRRules:RefPrewarningIndexAlert");
- return _refPrewarningIndexAlert ?? (value ?? 50);
- }
- set => _refPrewarningIndexAlert = value;
- }
- /// <summary>
- /// 浙江中石化特殊规则:是否在不足 5 笔时也延续预警状态
- /// 为 true 时:即使 acc_total < ref_count,也会延续之前的连续天数
- /// </summary>
- public static bool BCountAllDay
- {
- get
- {
- var value = Setting.Get<bool?>("VRRules:BCountAllDay");
- return _bCountAllDay ?? (value ?? false);
- }
- set => _bCountAllDay = value;
- }
- /// <summary>
- /// 从配置文件加载所有规则
- /// </summary>
- public static void LoadFromConfig()
- {
- _refReachCount = null;
- _refCount = null;
- _refPrewarningIndex = null;
- _refPrewarningIndexAlert = null;
- _bCountAllDay = null;
- // 触发一次 getter 以重新读取配置
- _ = RefReachCount;
- _ = RefCount;
- _ = RefPrewarningIndex;
- _ = RefPrewarningIndexAlert;
- _ = BCountAllDay;
- }
- /// <summary>
- /// 手动设置所有规则(用于代码动态配置)
- /// </summary>
- public static void SetRules(bool refReachCount, int refCount, int refPrewarningIndex,
- int refPrewarningIndexAlert, bool bCountAllDay)
- {
- _refReachCount = refReachCount;
- _refCount = refCount;
- _refPrewarningIndex = refPrewarningIndex;
- _refPrewarningIndexAlert = refPrewarningIndexAlert;
- _bCountAllDay = bCountAllDay;
- }
- }
- }
|