AidopS4KpiMerge.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. namespace Admin.NET.Plugin.AiDOP.Infrastructure;
  2. /// <summary>
  3. /// L1/L2 合并:期量差与绿黄红(指标模型总方案 03)。
  4. /// 阈值含义(以达标比例%表示):
  5. /// higher_is_better: 绿 actual/target >= 100%;黄 >= yellowPct;红 &lt; redPct
  6. /// lower_is_better: 绿 actual/target &lt;= 100%;黄 &lt;= yellowPct;红 > redPct
  7. /// 默认值:higher (95/80) lower (110/120)
  8. /// </summary>
  9. public static class AidopS4KpiMerge
  10. {
  11. public const string Green = "green";
  12. public const string Yellow = "yellow";
  13. public const string Red = "red";
  14. public static string AchievementLevel(
  15. decimal? current, decimal? target, string direction,
  16. decimal? yellowThreshold = null, decimal? redThreshold = null)
  17. {
  18. if (current == null || target == null)
  19. return Yellow;
  20. var c = current.Value;
  21. var t = target.Value;
  22. if (t == 0) return Yellow;
  23. if (direction == "lower_is_better")
  24. {
  25. var yPct = yellowThreshold ?? 110m;
  26. var rPct = redThreshold ?? 120m;
  27. if (c <= t) return Green;
  28. if (c <= t * yPct / 100m) return Yellow;
  29. return Red;
  30. }
  31. // higher_is_better
  32. {
  33. var yPct = yellowThreshold ?? 95m;
  34. var rPct = redThreshold ?? 80m;
  35. if (c >= t) return Green;
  36. if (c >= t * yPct / 100m) return Yellow;
  37. return Red;
  38. }
  39. }
  40. /// <summary>期量差数值(当前−目标);展示用箭头与符号在调用方处理。</summary>
  41. public static decimal? GapValue(decimal? current, decimal? target)
  42. {
  43. if (current == null || target == null) return null;
  44. return current.Value - target.Value;
  45. }
  46. public static string GapArrow(decimal? gap)
  47. {
  48. if (gap == null) return "flat";
  49. return gap.Value >= 0 ? "up" : "down";
  50. }
  51. }