image.domain\self_evolve\smart_priority.mbt

75% · 33 / 44 points · 161 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

  1. 1///|
  2. 2/// # 智能优先 self_evolve/smart_priority
  3. 3///
  4. 4/// 图像处理库子模块
  5. 5/// 图像处理库子模块 Image processing library submodule
  6. 6// 智能测试优先级 — 基于历史数据智能评分
  7. 7// Smart test priority: intelligently score test priorities based on historical data
  8. 8//
  9. 9// Phase 9 v303: 将演化从"回归检测"推向"智能评分" — 多因子加权评分。
  10. 10
  11. 11///|
  12. 12/// 评分因子类型。
  13. 13/// 描述 Score factor kind.
  14. 14/// `#non_exhaustive` 表示未来可能添加新构造器
  15. 15#derive(Eq, @debug.Debug)
  16. 16#non_exhaustive
  17. 17pub(all) enum ScoreFactor {
  18. 18 DegradationRisk
  19. 19 CoverageGap
  20. 20 HistoryWeight
  21. 21 PropagationRisk
  22. 22}
  23. 23
  24. 24///|
  25. 25pub extend ScoreFactor with @debug.Debug::{to_repr}
  26. 26
  27. 27///|
  28. 28pub extend ScoreFactor with Eq::{not_equal, equal}
  29. 29
  30. 30///|
  31. 31/// 单算子智能评分。
  32. 32/// 智能 Smart score for a single op.
  33. 33#derive(Eq, @debug.Debug)
  34. 34pub(all) struct SmartScore {
  35. 35 op_tag : String
  36. 36 score : Int32
  37. 37 factors : Array[ScoreFactor]
  38. 38 recommendation : String
  39. 39}
  40. 40
  41. 41///|
  42. 42pub extend SmartScore with @debug.Debug::{to_repr}
  43. 43
  44. 44///|
  45. 45pub extend SmartScore with Eq::{not_equal, equal}
  46. 46
  47. 47///|
  48. 48/// 智能优先级报告。
  49. 49/// 智能 Smart priority report.
  50. 50#derive(Eq, @debug.Debug)
  51. 51pub(all) struct SmartPriorityReport {
  52. 52 scores : Array[SmartScore]
  53. 53 total_ops : Int32
  54. 54 high_priority_count : Int32
  55. 55 summary : String
  56. 56}
  57. 57
  58. 58///|
  59. 59pub extend SmartPriorityReport with @debug.Debug::{to_repr}
  60. 60
  61. 61///|
  62. 62pub extend SmartPriorityReport with Eq::{not_equal, equal}
  63. 63
  64. 64///|
  65. 65/// 为单个算子计算智能评分 (0-100)。
  66. 66/// 计算 Calculate smart score for a single op (0-100).
  67. 67pub fn score_op(op : @imgir.IROp) -> SmartScore {
  68. 68● let tag = op.tag()
  69. 69 let factors : Array[ScoreFactor] = []
  70. 70 let mut score = 0
  71. 71● let degs = detect_degradation(op)
  72. 72● let deg_count = degs.length()
  73. 73 if deg_count > 0 {
  74. 74● score = score + deg_count * 25
  75. 75● factors.push(DegradationRisk)
  76. 76 }
  77. 77● let cov = coverage_percentage(op)
  78. 78 if cov < 50 {
  79. 79● score = score + (50 - cov)
  80. 80● factors.push(CoverageGap)
  81. 81 }
  82. 82● let log = history_log()
  83. 83 let mut has_history = false
  84. 84 for e in log.entries {
  85. 85● if e.degradation_count > 0 {
  86. 86○ has_history = true
  87. 87 }
  88. 88 }
  89. 89 if has_history {
  90. 90○ score = score + 5
  91. 91○ factors.push(HistoryWeight)
  92. 92 }
  93. 93● let pipe = @imgir.IRPipeline::new().add(op)
  94. 94● let prop = analyze_propagation(pipe)
  95. 95 if prop.total_propagations > 0 {
  96. 96○ score = score + prop.total_propagations * 10
  97. 97○ factors.push(PropagationRisk)
  98. 98 }
  99. 99 if score > 100 {
  100. 100○ score = 100
  101. 101 }
  102. 102 let rec = if score >= 70 {
  103. 103○ "高优先级 — 立即处理"
  104. 104● } else if score >= 40 {
  105. 105○ "中优先级 — 计划处理"
  106. 106 } else {
  107. 107● "低优先级 — 按需处理"
  108. 108 }
  109. 109 { op_tag: tag, score, factors, recommendation: rec, }
  110. 110}
  111. 111
  112. 112///|
  113. 113/// 为所有算子计算智能评分。
  114. 114/// 计算 Calculate smart scores for all ops.
  115. 115pub fn score_all_ops() -> SmartPriorityReport {
  116. 116● let scores : Array[SmartScore] = []
  117. 117 let mut high_count = 0
  118. 118● for op in all_ops() {
  119. 119● let s = score_op(op)
  120. 120 if s.score >= 70 {
  121. 121○ high_count = high_count + 1
  122. 122 }
  123. 123● scores.push(s)
  124. 124 }
  125. 125● let total = scores.length()
  126. 126 let summary = "智能评分: " +
  127. 127● total.to_string() +
  128. 128 " 算子, " +
  129. 129● high_count.to_string() +
  130. 130 " 高优先级"
  131. 131 { scores, total_ops: total, high_priority_count: high_count, summary, }
  132. 132}
  133. 133
  134. 134///|
  135. 135/// 获取前 N 个最高优先级算子。
  136. 136/// 获取 Get top N priority ops.
  137. 137pub fn SmartPriorityReport::top_priority(
  138. 138 self : SmartPriorityReport,
  139. 139 n : Int32,
  140. 140) -> Array[SmartScore] {
  141. 141● let sorted : Array[SmartScore] = []
  142. 142 for s in self.scores {
  143. 143● sorted.push(s)
  144. 144 }
  145. 145● let len = sorted.length()
  146. 146 for i in 0..<len {
  147. 147● for j in 0..<(len - 1 - i) {
  148. 148● if sorted[j].score < sorted[j + 1].score {
  149. 149○ let tmp = sorted[j]
  150. 150 sorted[j] = sorted[j + 1]
  151. 151 sorted[j + 1] = tmp
  152. 152 }
  153. 153 }
  154. 154 }
  155. 155 let result : Array[SmartScore] = []
  156. 156◐ let limit = if n < len { n } else { len }
  157. 157 for i in 0..<limit {
  158. 158● result.push(sorted[i])
  159. 159 }
  160. 160 result
  161. 161}