MCPcopy Create free account
hub / github.com/astercloud/aster / calculateSummary

Function calculateSummary

pkg/evals/batch.go:177–215  ·  view source on GitHub ↗

calculateSummary 计算汇总统计

(results []*BatchResult)

Source from the content-addressed store, hash-verified

175
176// calculateSummary 计算汇总统计
177func calculateSummary(results []*BatchResult) *BatchSummary {
178 summary := &BatchSummary{
179 TotalCases: len(results),
180 AverageScores: make(map[string]float64),
181 }
182
183 scorerCounts := make(map[string]int)
184 scorerSums := make(map[string]float64)
185 totalDuration := time.Duration(0)
186
187 for _, result := range results {
188 if result.Error == "" {
189 summary.SuccessfulCases++
190 totalDuration += result.Duration
191
192 for _, score := range result.Scores {
193 scorerSums[score.Name] += score.Value
194 scorerCounts[score.Name]++
195 }
196 } else {
197 summary.FailedCases++
198 }
199 }
200
201 // 计算平均分
202 for name, sum := range scorerSums {
203 count := scorerCounts[name]
204 if count > 0 {
205 summary.AverageScores[name] = sum / float64(count)
206 }
207 }
208
209 // 计算平均执行时间
210 if summary.SuccessfulCases > 0 {
211 summary.AverageDuration = totalDuration / time.Duration(summary.SuccessfulCases)
212 }
213
214 return summary
215}
216
217// RunBatchSimple 简化版批量评估(顺序执行)
218func RunBatchSimple(ctx context.Context, testCases []*BatchTestCase, scorers []Scorer) (*BatchEvalResult, error) {

Callers 2

TestCalculateSummaryFunction · 0.85
RunBatchFunction · 0.85

Calls 1

DurationMethod · 0.45

Tested by 1

TestCalculateSummaryFunction · 0.68