Skip to content

Commit 7ee54be

Browse files
author
tpfz
committed
fix 聚合得分
1 parent 3f6b0d3 commit 7ee54be

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

backend/modules/evaluation/domain/service/expt_result_aggr_impl.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ func NewExptAggrResultService(
7272
}
7373
}
7474

75+
// effectiveEvaluatorResultScoreForAggr 返回用于实验聚合统计的分数:Correction.Score 优先(非 nil 时),否则原始 Score。
76+
// 与 expt_result_impl.calculateWeightedScore、CorrectEvaluatorRecord 语义一致。
77+
func effectiveEvaluatorResultScoreForAggr(res *entity.EvaluatorResult) (float64, bool) {
78+
if res == nil {
79+
return 0, false
80+
}
81+
if res.Correction != nil && res.Correction.Score != nil {
82+
return *res.Correction.Score, true
83+
}
84+
if res.Score != nil {
85+
return *res.Score, true
86+
}
87+
return 0, false
88+
}
89+
7590
func (e *ExptAggrResultServiceImpl) CreateExptAggrResult(ctx context.Context, spaceID, experimentID int64) (err error) {
7691
now := time.Now().Unix()
7792
defer func() { e.metric.EmitCalculateExptAggrResult(spaceID, int64(entity.CreateAllFields), err != nil, now) }()
@@ -122,13 +137,14 @@ func (e *ExptAggrResultServiceImpl) CreateExptAggrResult(ctx context.Context, sp
122137
if !ok || evalResult == nil {
123138
continue
124139
}
125-
if evalResult.EvaluatorOutputData == nil ||
126-
evalResult.EvaluatorOutputData.EvaluatorResult == nil ||
127-
evalResult.EvaluatorOutputData.EvaluatorResult.Score == nil {
140+
if evalResult.EvaluatorOutputData == nil {
128141
continue
129142
}
130-
131-
aggregatorGroup.Append(gptr.Indirect(evalResult.EvaluatorOutputData.EvaluatorResult.Score))
143+
score, hasScore := effectiveEvaluatorResultScoreForAggr(evalResult.EvaluatorOutputData.EvaluatorResult)
144+
if !hasScore {
145+
continue
146+
}
147+
aggregatorGroup.Append(score)
132148
}
133149
}
134150
}
@@ -401,12 +417,12 @@ func (e *ExptAggrResultServiceImpl) UpdateExptAggrResult(ctx context.Context, pa
401417

402418
aggregatorGroup := NewAggregatorGroup(WithScoreDistributionAggregator())
403419
for _, evalResult := range recordMap {
404-
if evalResult.EvaluatorOutputData == nil || evalResult.EvaluatorOutputData.EvaluatorResult == nil {
420+
if evalResult.EvaluatorOutputData == nil {
405421
continue
406422
}
407-
score := gptr.Indirect(evalResult.EvaluatorOutputData.EvaluatorResult.Score)
408-
if evalResult.EvaluatorOutputData.EvaluatorResult.Correction != nil {
409-
score = gptr.Indirect(evalResult.EvaluatorOutputData.EvaluatorResult.Correction.Score)
423+
score, ok := effectiveEvaluatorResultScoreForAggr(evalResult.EvaluatorOutputData.EvaluatorResult)
424+
if !ok {
425+
continue
410426
}
411427
aggregatorGroup.Append(score)
412428
}

0 commit comments

Comments
 (0)