models

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2020 License: AGPL-3.0 Imports: 15 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 (*TestGroup) DeleteResults added in v0.4.1

func (t *TestGroup) DeleteResults(db db.DBContext) error

DeleteResults deletes all test results of a given test group.

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 (*Problem) Verify

func (r *Problem) Verify() error

Verify verifies a Problem'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 JSONProblem added in v0.4.1

type JSONProblem struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	DisplayName string `json:"display_name"`
}

JSONProblem represents a JSON encoded problem metadata.

type JSONProblemResult added in v0.4.1

type JSONProblemResult struct {
	Score          float64 `json:"score"`
	Solved         bool    `json:"solved"`
	Penalty        int     `json:"penalty"`
	FailedAttempts int     `json:"failed_attempts"`
	BestSubmission int64   `json:"best_submission"`
}

JSONProblemResult represents a JSON encoded user's result of a problem in the scoreboard.

type JSONScoreboard added in v0.4.1

type JSONScoreboard struct {
	ContestID              int              `json:"contest_id"`
	ContestType            ContestType      `json:"contest_type"`
	Problems               []JSONProblem    `json:"problems"`
	Users                  []JSONUserResult `json:"users"`
	ProblemBestSubmissions map[int]int64    `json:"problem_best_submissions"`
}

JSONScoreboard represents a JSON encoded scoreboard.

type JSONUserResult added in v0.4.1

type JSONUserResult struct {
	ID             string                    `json:"id"`
	Rank           int                       `json:"rank"`
	TotalPenalty   int                       `json:"total_penalty"`
	SolvedProblems int                       `json:"solved_problems"`
	TotalScore     float64                   `json:"total_score"`
	ProblemResults map[int]JSONProblemResult `json:"problem_results"`
}

JSONUserResult represents a JSON encoded user in the scoreboard.

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 Scoreboard added in v0.4.1

type Scoreboard struct {
	Contest                *Contest
	Problems               []*Problem
	UserResults            []*UserResult
	ProblemBestSubmissions map[int]int64
}

Scoreboard is the struct used to render scoreboard

func GetScoreboard added in v0.4.1

func GetScoreboard(db db.DBContext, contest *Contest, problems []*Problem) (*Scoreboard, error)

Get scoreboard given problems and contest

func (*Scoreboard) CSV added in v0.4.1

func (s *Scoreboard) CSV(w io.Writer) error

CSV returns the CSV version of the scoreboard, with scores and penalties.

func (*Scoreboard) CSVScoresOnly added in v0.4.1

func (s *Scoreboard) CSVScoresOnly(w io.Writer) error

CSVScoresOnly returns the CSV version of the scoreboard, with only scores.

func (*Scoreboard) JSON added in v0.4.1

func (s *Scoreboard) JSON() JSONScoreboard

JSON returns the JSON representation of the scoreboard.

type ScoreboardViewStatus added in v0.4.1

type ScoreboardViewStatus string

ScoreboardViewStatus is the enum representing the scoreboard view status. scoreboard view status type determines how the scoreboard is accessed.

const (
	// This allowes everyone to see the scoreboard
	ScoreboardViewStatusPublic ScoreboardViewStatus = "public"
	// This only allowes registered users to see the scoreboard
	ScoreboardViewStatusUser ScoreboardViewStatus = "user"
	// There is no scoreboard rendered during the contest
	ScoreboardViewStatusNoScoreboard ScoreboardViewStatus = "no_scoreboard"
)

type ScoringMode

type ScoringMode string

ScoringMode dictates how the best submission is chosen. There are: - Min: The submission with the lowest score is chosen. If on a tie, choose the one with the highest penalty - Best: The submission with the highest score is chosen. If on a tie, choose the one with lowest 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 (
	ScoringModeMin   ScoringMode = "min"
	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.

type UserResult added in v0.4.1

type UserResult struct {
	User *User

	Rank           int
	TotalPenalty   int
	SolvedProblems int
	TotalScore     float64

	ProblemResults map[int]*ProblemResult
}

UserResult stores information about user's preformance in the contest

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