| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- namespace Admin.NET.Plugin.AiDOP.Infrastructure;
- /// <summary>
- /// L1/L2 合并:期量差与绿黄红(指标模型总方案 03)。
- /// 阈值含义(以达标比例%表示):
- /// higher_is_better: 绿 actual/target >= 100%;黄 >= yellowPct;红 < redPct
- /// lower_is_better: 绿 actual/target <= 100%;黄 <= yellowPct;红 > redPct
- /// 默认值:higher (95/80) lower (110/120)
- /// </summary>
- public static class AidopS4KpiMerge
- {
- public const string Green = "green";
- public const string Yellow = "yellow";
- public const string Red = "red";
- public static string AchievementLevel(
- decimal? current, decimal? target, string direction,
- decimal? yellowThreshold = null, decimal? redThreshold = null)
- {
- if (current == null || target == null)
- return Yellow;
- var c = current.Value;
- var t = target.Value;
- if (t == 0) return Yellow;
- if (direction == "lower_is_better")
- {
- var yPct = yellowThreshold ?? 110m;
- var rPct = redThreshold ?? 120m;
- if (c <= t) return Green;
- if (c <= t * yPct / 100m) return Yellow;
- return Red;
- }
- // higher_is_better
- {
- var yPct = yellowThreshold ?? 95m;
- var rPct = redThreshold ?? 80m;
- if (c >= t) return Green;
- if (c >= t * yPct / 100m) return Yellow;
- return Red;
- }
- }
- /// <summary>期量差数值(当前−目标);展示用箭头与符号在调用方处理。</summary>
- public static decimal? GapValue(decimal? current, decimal? target)
- {
- if (current == null || target == null) return null;
- return current.Value - target.Value;
- }
- public static string GapArrow(decimal? gap)
- {
- if (gap == null) return "flat";
- return gap.Value >= 0 ? "up" : "down";
- }
- }
|