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