fix aggregate
Some checks failed
judge / Build judge (push) Successful in 10s
judge / Linux / gcc / Debug (push) Successful in 9s
judge / Linux / clang / Release (push) Successful in 12s
judge / Linux / clang / Sanitized (push) Successful in 11s
judge / Linux / gcc / Release (push) Successful in 11s
judge / Linux / gcc / Sanitized (push) Successful in 10s
judge / Linux / gcc / Debug (valgrind) (push) Successful in 17s
judge / Windows / clang / Debug (push) Successful in 1m28s
judge / Windows / clang / Release (push) Successful in 1m24s
judge / Windows / msvc / Release (push) Successful in 1m28s
judge / Windows / msvc / Debug (push) Successful in 1m33s
judge / SUMMARY (push) Failing after 4s

This commit is contained in:
2026-04-06 14:28:51 +03:00
parent cb70adbf09
commit 856d7935b5
3 changed files with 90 additions and 14 deletions

View File

@@ -4,6 +4,9 @@ import (
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"sort"
"strings"
"github.com/Mond1c/judge/runner"
@@ -74,6 +77,60 @@ type jsonTestResult struct {
Failures []string `json:"failures,omitempty"`
}
func Aggregate(w io.Writer, dir string) error {
files, err := filepath.Glob(filepath.Join(dir, "*", "*.json"))
if err != nil {
return fmt.Errorf("glob reports: %w", err)
}
if len(files) == 0 {
files, _ = filepath.Glob(filepath.Join(dir, "*.json"))
}
if len(files) == 0 {
return fmt.Errorf("no JSON reports found in %s", dir)
}
sort.Strings(files)
type entry struct {
Config string
Score float64
}
var entries []entry
allPassed := true
for _, f := range files {
data, err := os.ReadFile(f)
if err != nil {
return fmt.Errorf("read %s: %w", f, err)
}
var report jsonSuiteResult
if err := json.Unmarshal(data, &report); err != nil {
return fmt.Errorf("parse %s: %w", f, err)
}
cfg := filepath.Base(filepath.Dir(f))
cfg = strings.TrimPrefix(cfg, "report_")
entries = append(entries, entry{Config: cfg, Score: report.TotalScore})
if report.TotalScore < 0.9999 {
allPassed = false
}
}
fmt.Fprintln(w, "# Judge results")
fmt.Fprintln(w)
fmt.Fprintln(w, "| Configuration | Score |")
fmt.Fprintln(w, "|---|---|")
for _, e := range entries {
fmt.Fprintf(w, "| %s | %.4f |\n", e.Config, e.Score)
}
if !allPassed {
return fmt.Errorf("one or more configurations scored below 1.0")
}
return nil
}
func jsonResult(r *runner.SuiteResult) jsonSuiteResult {
res := jsonSuiteResult{
TotalScore: r.TotalScore,