VRRules.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. namespace EasyTemplate.Tool
  2. {
  3. /// <summary>
  4. /// 预警告计算规则配置(对应 C++ VR::rules 命名空间)
  5. /// </summary>
  6. public static class VRRules
  7. {
  8. private static bool? _refReachCount;
  9. private static int? _refCount;
  10. private static int? _refPrewarningIndex;
  11. private static int? _refPrewarningIndexAlert;
  12. private static bool? _bCountAllDay;
  13. /// <summary>
  14. /// 北京模式:是否使用达标计数模式
  15. /// 为 true 时:超标率>=阈值 且 总笔数>=5 时计为连续一天
  16. /// 为 false 时:使用标准模式(总笔数>=ref_count 时才检查超标率)
  17. /// </summary>
  18. public static bool RefReachCount
  19. {
  20. get
  21. {
  22. var value = Setting.Get<bool?>("VRRules:RefReachCount");
  23. return _refReachCount ?? (value ?? false);
  24. }
  25. set => _refReachCount = value;
  26. }
  27. /// <summary>
  28. /// 标准模式下的参考笔数阈值(通常为 5)
  29. /// 当累计总笔数达到此值时才进行超标率判断
  30. /// </summary>
  31. public static int RefCount
  32. {
  33. get
  34. {
  35. var value = Setting.Get<int?>("VRRules:RefCount");
  36. return _refCount ?? (value ?? 5);
  37. }
  38. set => _refCount = value;
  39. }
  40. /// <summary>
  41. /// 预报警超标率阈值(%)
  42. /// 当累计超标率>=此值时判定为超标
  43. /// </summary>
  44. public static int RefPrewarningIndex
  45. {
  46. get
  47. {
  48. var value = Setting.Get<int?>("VRRules:RefPrewarningIndex");
  49. return _refPrewarningIndex ?? (value ?? 20);
  50. }
  51. set => _refPrewarningIndex = value;
  52. }
  53. /// <summary>
  54. /// 预报警严重超标率阈值(%)
  55. /// 当累计严重超标率>=此值时判定为严重超标
  56. /// </summary>
  57. public static int RefPrewarningIndexAlert
  58. {
  59. get
  60. {
  61. var value = Setting.Get<int?>("VRRules:RefPrewarningIndexAlert");
  62. return _refPrewarningIndexAlert ?? (value ?? 50);
  63. }
  64. set => _refPrewarningIndexAlert = value;
  65. }
  66. /// <summary>
  67. /// 浙江中石化特殊规则:是否在不足 5 笔时也延续预警状态
  68. /// 为 true 时:即使 acc_total < ref_count,也会延续之前的连续天数
  69. /// </summary>
  70. public static bool BCountAllDay
  71. {
  72. get
  73. {
  74. var value = Setting.Get<bool?>("VRRules:BCountAllDay");
  75. return _bCountAllDay ?? (value ?? false);
  76. }
  77. set => _bCountAllDay = value;
  78. }
  79. /// <summary>
  80. /// 从配置文件加载所有规则
  81. /// </summary>
  82. public static void LoadFromConfig()
  83. {
  84. _refReachCount = null;
  85. _refCount = null;
  86. _refPrewarningIndex = null;
  87. _refPrewarningIndexAlert = null;
  88. _bCountAllDay = null;
  89. // 触发一次 getter 以重新读取配置
  90. _ = RefReachCount;
  91. _ = RefCount;
  92. _ = RefPrewarningIndex;
  93. _ = RefPrewarningIndexAlert;
  94. _ = BCountAllDay;
  95. }
  96. /// <summary>
  97. /// 手动设置所有规则(用于代码动态配置)
  98. /// </summary>
  99. public static void SetRules(bool refReachCount, int refCount, int refPrewarningIndex,
  100. int refPrewarningIndexAlert, bool bCountAllDay)
  101. {
  102. _refReachCount = refReachCount;
  103. _refCount = refCount;
  104. _refPrewarningIndex = refPrewarningIndex;
  105. _refPrewarningIndexAlert = refPrewarningIndexAlert;
  106. _bCountAllDay = bCountAllDay;
  107. }
  108. }
  109. }