models

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package models defines all the data models used in the database, as well as methods to acquire and modify them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchInsertJobs

func BatchInsertJobs(db db.DBContext, jobs ...*Job) error

BatchInsertJobs try to insert all given jobs.

func CollectUserProblemResults

func CollectUserProblemResults(db db.DBContext, userID string, problems []*Problem) (map[int]*ProblemResult, error)

CollectProblemResults collects an user's problem results for a contest. The result map's key is the problem ID.

func GetProblemByName

func GetProblemByName(db db.DBContext, contestID int, name string) (*Problem, error)

GetProblemByName gets a Problem from the Database by its name and contest.

func (*TestGroup) Hidden

func (r *TestGroup) Hidden() bool

Hidden returns whether the test group is hidden.

func RejudgeCompile

func RejudgeCompile(db db.DBContext, subIDs ...int) error

RejudgeCompile re-compiles all submissions given.

func RejudgeRun

func RejudgeRun(db db.DBContext, subIDs ...int) error

RejudgeRun re-runs all tests for the submissions given.

func RejudgeScore

func RejudgeScore(db db.DBContext, subIDs ...int) error

RejudgeScore re-scores all submissions given.

func (*TestGroup) Verify

func (r *TestGroup) Verify() error

Verify verifies TestGroup's content.

func (*Problem) WriteFiles

func (p *Problem) WriteFiles(db db.DBContext, files []*File) error

WriteFiles writes the given files as brand new, overwritting the old ones. Note that because of overwritting behaviour, we cannot ensure the validity of the indicies, hence they are not reflected into the *Files.

func (*TestGroup) WriteTests

func (r *TestGroup) WriteTests(db db.DBContext, tests []*Test, override bool) error

WriteTests writes the given set of tests into the Database. If override is set, all tests in the test group gets deleted first.

Types

type Config

type Config struct {
	SessionKey         []byte `db:"session_key"`
	EnableRegistration bool   `db:"enable_registration"`
}

Config is the configuation of the server.

func GenerateConfig

func GenerateConfig() (*Config, error)

GenerateConfig generates a random configuration.

func GetConfig

func GetConfig(db db.DBContext) (*Config, error)

GetConfig gets the configuration of the server.

func (*Config) Verify

func (c *Config) Verify() error

Verify verifies a Config's content.

func (*Config) Write

func (c *Config) Write(db *db.DB) error

Write writes to the database. It needs a root DB because we need a transaction.

type ContestType

type ContestType string

ContestType is the enum representing the contest type. The contest type determines ONLY how the scoreboard is rendered.

const (
	// The contestants are sorted by number of "solved" problems, then by total penalty.
	ContestTypeUnweighted ContestType = "unweighted"
	// Problems each have different scores, and penalty only serves as tiebreakers.
	ContestTypeWeighted ContestType = "weighted"
)

type JobType

type JobType string

JobType determines the type of the job. This can be: - Compile: highest priority. Compiles a submission into executable bytecode. - Test: run a test. - Score: recalculate the score.

const (
	JobTypeCompile JobType = "compile"
	JobTypeRun     JobType = "run"
	JobTypeScore   JobType = "score"
)

Possible values of JobType.

type Language

type Language string

Language represents the language of the submission. The available values depend on the machine the judge is run on.

const (
	LanguageCpp  Language = "g++"
	LanguagePas  Language = "fpc"
	LanguageJava Language = "javac"
	LanguagePy2  Language = "python2"
	LanguagePy3  Language = "python3"
	LanguageGo   Language = "go"
	LanguageRust Language = "rustc"
)

func LanguageByExt

func LanguageByExt(ext string) (Language, error)

LanguageByExt returns a language based on the file extension.

type PenaltyPolicy

type PenaltyPolicy string

PenaltyPolicy dictates how the penalty is calculated. There are: - None: no penalty at all (IOI - like). - SubmitTime: minutes passed from the start of the contest, of the submission time. - ICPC: SubmitTime + 20 * (# of past submissions)

const (
	PenaltyPolicyNone       PenaltyPolicy = "none"
	PenaltyPolicySubmitTime PenaltyPolicy = "submit_time"
	PenaltyPolicyICPC       PenaltyPolicy = "icpc"
)

Defined values for PenaltyPolicy.

type ProblemWithTestGroups

type ProblemWithTestGroups struct {
	*Problem
	TestGroups []*TestGroup
}

ProblemWithTestGroups is a problem with attached test groups, that will provide score-related statistics.

func CollectTestGroups

func CollectTestGroups(db db.DBContext, problems []*Problem, private bool) ([]*ProblemWithTestGroups, error)

CollectTestGroups collects the test groups for a list of problems.

func (*ProblemWithTestGroups) SubtaskScores

func (p *ProblemWithTestGroups) SubtaskScores() string

SubtaskScores returns the problem's test group scores as a list seperated by forward slash.

func (*ProblemWithTestGroups) TotalScore

func (p *ProblemWithTestGroups) TotalScore() float64

TotalScore returns the problem's maximal total score.

type QueueOverview

type QueueOverview struct {
	Compile int
	Run     int
	Score   int
}

QueueOverview gives overview information about the queue of jobs.

func GetQueueOverview

func GetQueueOverview(db db.DBContext) (*QueueOverview, error)

GetQueueOverview gets the current queue overview.

func (*QueueOverview) Total

func (q *QueueOverview) Total() int

Total returns the sum of all queue counts.

type ScoringMode

type ScoringMode string

ScoringMode dictates how the best submission is chosen. There are: - Best: The submission with the highest score is chosen. If on a tie, choose the one with largest penalty. - Once: The first (successfully compiled) submission is the best one. - Last: The last submission is the best one. - Decay: The last submission is the best one. The score is modified by the number of submissions before it (0.1 * count), and the time passed (0.7 * time passed in %), to a minimum of 0.3 times the original.

const (
	ScoringModeBest  ScoringMode = "best"
	ScoringModeOnce  ScoringMode = "once"
	ScoringModeLast  ScoringMode = "last"
	ScoringModeDecay ScoringMode = "decay"
)

Defined values for ScoringMode.

type TestGroupWithTests

type TestGroupWithTests struct {
	*TestGroup
	Tests []*Test
}

TestGroupWithTests are wrapped test groups with tests included.

func GetProblemTests

func GetProblemTests(db db.DBContext, problemID int) ([]*TestGroupWithTests, error)

GetProblemTests collects test groups and tests from a problem.

func GetProblemTestsMeta

func GetProblemTestsMeta(db db.DBContext, problemID int) ([]*TestGroupWithTests, error)

GetProblemTestsMeta is like GetProblemTests, but inputs and outputs are not included.

func (*TestGroupWithTests) ComputeScore

func (tg *TestGroupWithTests) ComputeScore(results map[int]*TestResult) float64

ComputeScore returns the score of a test group (with tests), given the test results.

type TestScoringMode

type TestScoringMode string

TestScoringMode determines how the score of each test in the group adds up to the total of the group. The schemes are: - Sum: Each test has an equal weight and the score of the group is (sum of test scores / # of tests) * (group score) - Min: The score of the group = min(score of each test) * (group score) - Product: Score of the group = product(score of each test) * (group score)

const (
	TestScoringModeSum     TestScoringMode = "sum"
	TestScoringModeMin     TestScoringMode = "min"
	TestScoringModeProduct TestScoringMode = "product"
)

All possible values of TestScoringMode.

Directories

Path Synopsis
Command "generate-models" reads the model information from the "models/models.json" file, and generate the relevant "models/generated.go" file.
Command "generate-models" reads the model information from the "models/models.json" file, and generate the relevant "models/generated.go" file.
Package verify implements certain verification methods for simple data structures.
Package verify implements certain verification methods for simple data structures.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL