Compare commits
No commits in common. "45490f3d1eec0f61051378dc6e251ccc7270f763" and "b3663d87823141f5bd41766a74863fbb4737caf9" have entirely different histories.
45490f3d1e
...
b3663d8782
|
@ -13,7 +13,6 @@ import (
|
||||||
_ "github.com/joint-online-judge/JOJ3/internal/parser/resultdetail"
|
_ "github.com/joint-online-judge/JOJ3/internal/parser/resultdetail"
|
||||||
_ "github.com/joint-online-judge/JOJ3/internal/parser/resultstatus"
|
_ "github.com/joint-online-judge/JOJ3/internal/parser/resultstatus"
|
||||||
_ "github.com/joint-online-judge/JOJ3/internal/parser/sample"
|
_ "github.com/joint-online-judge/JOJ3/internal/parser/sample"
|
||||||
_ "github.com/joint-online-judge/JOJ3/internal/parser/tierscore"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// this file does nothing but imports to ensure all the init() functions
|
// this file does nothing but imports to ensure all the init() functions
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
// Package tierscore provides a parser for tiered scoring based on
|
|
||||||
// time and memory constraints. Leave the field empty or 0 to disable.
|
|
||||||
|
|
||||||
package tierscore
|
|
||||||
|
|
||||||
import "github.com/joint-online-judge/JOJ3/internal/stage"
|
|
||||||
|
|
||||||
var name = "tierscore"
|
|
||||||
|
|
||||||
type Tier struct {
|
|
||||||
TimeLessThan uint64 // ns
|
|
||||||
MemoryLessThan uint64 // bytes
|
|
||||||
Score int
|
|
||||||
}
|
|
||||||
|
|
||||||
type Conf struct {
|
|
||||||
Tiers []Tier
|
|
||||||
}
|
|
||||||
|
|
||||||
type TierScore struct{}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
stage.RegisterParser(name, &TierScore{})
|
|
||||||
}
|
|
|
@ -1,102 +0,0 @@
|
||||||
package tierscore
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/joint-online-judge/JOJ3/internal/stage"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (*TierScore) Run(results []stage.ExecutorResult, confAny any) (
|
|
||||||
[]stage.ParserResult, bool, error,
|
|
||||||
) {
|
|
||||||
conf, err := stage.DecodeConf[Conf](confAny)
|
|
||||||
if err != nil {
|
|
||||||
return nil, true, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var res []stage.ParserResult
|
|
||||||
forceQuit := false
|
|
||||||
|
|
||||||
for _, result := range results {
|
|
||||||
totalScore := 0
|
|
||||||
var commentBuilder strings.Builder
|
|
||||||
|
|
||||||
for i, tier := range conf.Tiers {
|
|
||||||
conditionsMet := true
|
|
||||||
var conditionDesc []string
|
|
||||||
|
|
||||||
if tier.TimeLessThan > 0 {
|
|
||||||
if result.Time < tier.TimeLessThan {
|
|
||||||
conditionDesc = append(
|
|
||||||
conditionDesc,
|
|
||||||
fmt.Sprintf(
|
|
||||||
"Time < `%d ms`",
|
|
||||||
tier.TimeLessThan/1e6,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
conditionsMet = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if tier.MemoryLessThan > 0 {
|
|
||||||
if result.Memory < tier.MemoryLessThan {
|
|
||||||
conditionDesc = append(
|
|
||||||
conditionDesc,
|
|
||||||
fmt.Sprintf(
|
|
||||||
"Memory < `%.2f MiB`",
|
|
||||||
float64(tier.MemoryLessThan)/(1024*1024),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
conditionsMet = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if conditionsMet {
|
|
||||||
totalScore += tier.Score
|
|
||||||
fmt.Fprintf(
|
|
||||||
&commentBuilder,
|
|
||||||
"Tier %d: +%d (meets %s)\n",
|
|
||||||
i,
|
|
||||||
tier.Score,
|
|
||||||
strings.Join(conditionDesc, " and "),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
var required []string
|
|
||||||
if tier.TimeLessThan > 0 {
|
|
||||||
required = append(
|
|
||||||
required,
|
|
||||||
fmt.Sprintf(
|
|
||||||
"Time < `%d ms`",
|
|
||||||
tier.TimeLessThan/1e6,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if tier.MemoryLessThan > 0 {
|
|
||||||
required = append(
|
|
||||||
required,
|
|
||||||
fmt.Sprintf(
|
|
||||||
"Memory < `%.2f MiB`",
|
|
||||||
float64(tier.MemoryLessThan)/(1024*1024),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
fmt.Fprintf(
|
|
||||||
&commentBuilder,
|
|
||||||
"Tier %d: +0 (requires %s)\n",
|
|
||||||
i+1,
|
|
||||||
strings.Join(required, " and "),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Fprintf(&commentBuilder, "Final score: %d", totalScore)
|
|
||||||
res = append(res, stage.ParserResult{
|
|
||||||
Score: totalScore,
|
|
||||||
Comment: commentBuilder.String(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return res, forceQuit, nil
|
|
||||||
}
|
|
|
@ -36,14 +36,14 @@ type Cmd struct {
|
||||||
Stdout *CmdFile `json:"stdout,omitempty"`
|
Stdout *CmdFile `json:"stdout,omitempty"`
|
||||||
Stderr *CmdFile `json:"stderr,omitempty"`
|
Stderr *CmdFile `json:"stderr,omitempty"`
|
||||||
|
|
||||||
CPULimit uint64 `json:"cpuLimit"` // ns
|
CPULimit uint64 `json:"cpuLimit"`
|
||||||
RealCPULimit uint64 `json:"realCpuLimit"` // deprecated: use clock limit instead (still working)
|
RealCPULimit uint64 `json:"realCpuLimit"`
|
||||||
ClockLimit uint64 `json:"clockLimit"` // ns
|
ClockLimit uint64 `json:"clockLimit"`
|
||||||
MemoryLimit uint64 `json:"memoryLimit"` // byte
|
MemoryLimit uint64 `json:"memoryLimit"`
|
||||||
StackLimit uint64 `json:"stackLimit"` // byte
|
StackLimit uint64 `json:"stackLimit"`
|
||||||
ProcLimit uint64 `json:"procLimit"`
|
ProcLimit uint64 `json:"procLimit"`
|
||||||
CPURateLimit uint64 `json:"cpuRateLimit"` // limit cpu usage (1000 equals 1 cpu)
|
CPURateLimit uint64 `json:"cpuRateLimit"`
|
||||||
CPUSetLimit string `json:"cpuSetLimit"` // set the cpuSet for cgroup
|
CPUSetLimit string `json:"cpuSetLimit"`
|
||||||
|
|
||||||
CopyIn map[string]CmdFile `json:"copyIn"`
|
CopyIn map[string]CmdFile `json:"copyIn"`
|
||||||
CopyInCached map[string]string `json:"copyInCached"`
|
CopyInCached map[string]string `json:"copyInCached"`
|
||||||
|
@ -111,9 +111,9 @@ type ExecutorResult struct {
|
||||||
Status Status `json:"status"`
|
Status Status `json:"status"`
|
||||||
ExitStatus int `json:"exitStatus"`
|
ExitStatus int `json:"exitStatus"`
|
||||||
Error string `json:"error,omitempty"`
|
Error string `json:"error,omitempty"`
|
||||||
Time uint64 `json:"time"` // ns (cgroup recorded time)
|
Time uint64 `json:"time"`
|
||||||
Memory uint64 `json:"memory"` // byte
|
Memory uint64 `json:"memory"`
|
||||||
RunTime uint64 `json:"runTime"` // ns (wall clock time)
|
RunTime uint64 `json:"runTime"`
|
||||||
Files map[string]string `json:"files,omitempty"`
|
Files map[string]string `json:"files,omitempty"`
|
||||||
FileIDs map[string]string `json:"fileIds,omitempty"`
|
FileIDs map[string]string `json:"fileIds,omitempty"`
|
||||||
FileError []FileError `json:"fileError,omitempty"`
|
FileError []FileError `json:"fileError,omitempty"`
|
||||||
|
@ -125,9 +125,9 @@ type ExecutorResultSummary struct {
|
||||||
Status Status `json:"status"`
|
Status Status `json:"status"`
|
||||||
ExitStatus int `json:"exitStatus"`
|
ExitStatus int `json:"exitStatus"`
|
||||||
Error string `json:"error,omitempty"`
|
Error string `json:"error,omitempty"`
|
||||||
Time uint64 `json:"time"` // ns (cgroup recorded time)
|
Time uint64 `json:"time"`
|
||||||
Memory uint64 `json:"memory"` // byte
|
Memory uint64 `json:"memory"`
|
||||||
RunTime uint64 `json:"runTime"` // ns (wall clock time)
|
RunTime uint64 `json:"runTime"`
|
||||||
Files map[string]string `json:"files,omitempty"`
|
Files map[string]string `json:"files,omitempty"`
|
||||||
FileIDs map[string]string `json:"fileIds,omitempty"`
|
FileIDs map[string]string `json:"fileIds,omitempty"`
|
||||||
FileError []FileError `json:"fileError,omitempty"`
|
FileError []FileError `json:"fileError,omitempty"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user