JOJ3/internal/scoreboard/scoreboard.go
张佳澈520370910044 4455304db9
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is passing
style(main_test.go,-.drone.yml,-scoreboard.go): reformats
2024-07-03 00:22:20 +08:00

41 lines
910 B
Go

package scoreboard
import (
"encoding/json"
"os"
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
)
type TestRecord struct {
TestName string `json:"testname"`
StageResults []stage.StageResult `json:"stageresults"`
}
type ScoreboardData struct {
TestRecords []TestRecord `json:"testrecords"`
}
type Scoreboard struct {
scoreboard ScoreboardData
}
func (b *Scoreboard) Init() {
b.scoreboard.TestRecords = make([]TestRecord, 0)
}
func (b *Scoreboard) AddScore(testname string, results []stage.StageResult) {
b.scoreboard.TestRecords = append(b.scoreboard.TestRecords,
TestRecord{TestName: testname, StageResults: results})
}
func (b *Scoreboard) SaveFile(filePath string) {
json_file, _ := os.Create(filePath)
defer json_file.Close()
encoder := json.NewEncoder(json_file)
encoder.SetEscapeHTML(false)
encoder.SetIndent("", " ")
_ = encoder.Encode(b.scoreboard)
}