JOJ3/internal/scoreboard/scoreboard.go
张佳澈520370910044 e80f4b55da
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
feat(cmd/joj3/main_test.go,-internal/scoreboard/scoreboard.go,-scripts/submit_scoreboard.sh): removing unused function in scoreboard
2024-06-10 15:28:40 +08:00

41 lines
923 B
Go

package scoreboard
import (
"encoding/json"
"os"
"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage"
)
type StageRecord struct {
StageName string `json:"stagename"`
StageResults []stage.StageResult `json:"stageresults"`
}
type ScoreboardData struct {
StageRecords []StageRecord `json:"stagerecords"`
}
type Scoreboard struct {
scoreboard ScoreboardData
}
func (b *Scoreboard) Init() {
b.scoreboard.StageRecords = make([]StageRecord, 0)
}
func (b *Scoreboard) AddScore(stagename string, results []stage.StageResult) {
b.scoreboard.StageRecords = append(b.scoreboard.StageRecords,
StageRecord{StageName: stagename, 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)
}