models

package
v0.0.0-...-1388524 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

models contains the domain models of the judging system; problems, users, contests, submissions and so on.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	// Internal account identifier. This should not be exposed externally.
	AccountID int32 `db:"account_id"`
	// External account identifier. This can be exposed externally and used in URLs.
	Username string `db:"username"`
	// A bcrypt hash of the user's password.
	PasswordHash string `db:"password_hash"`
	FullName     string `db:"full_name"`
	Email        string `db:"email"`
}

An Account represents a user account from the `account` table.

func (a *Account) Link() string

Link returns a link to the account's user page.

func (*Account) MatchesPassword

func (a *Account) MatchesPassword(password string) bool

Matches returns whether the given password matches the account password hash.

func (*Account) SetPassword

func (a *Account) SetPassword(password string)

SetPassword sets the account password hash to the hash of the given password.

type Contest

type Contest struct {
	ContestID int32 `db:"contest_id"`
	// Full name of the contest.
	Title string `db:"title"`
	// Short name of the contest, for use in e.g. URLs.
	ShortName string `db:"short_name"`
	// A host name for the contest. Web requests to this hostname will resolve to this contest.
	HostName        sql.NullString `db:"host_name"`
	StartTime       sql.NullTime   `db:"start_time"`
	FlexibleEndTime sql.NullTime   `db:"selection_window_end_time"`
	Duration        time.Duration  `db:"duration"`
	// Whether the scoreboard should be hidden for contestants during the contest.
	HiddenScoreboard bool `db:"hidden_scoreboard"`
	Problems         []*ContestProblem
}

A Contest is a contest with a number of problems team can register for and compete in.

func (*Contest) CanSeeScoreboard

func (c *Contest) CanSeeScoreboard(team *Team) bool

func (*Contest) ElapsedFor

func (c *Contest) ElapsedFor(t time.Time, team *Team) time.Duration

func (*Contest) EndTime

func (c *Contest) EndTime(team *Team) time.Time

func (*Contest) Flexible

func (c *Contest) Flexible() bool

func (*Contest) FullEndTime

func (c *Contest) FullEndTime() time.Time

func (*Contest) FullOver

func (c *Contest) FullOver() bool

func (*Contest) FullStart

func (c *Contest) FullStart() bool

func (*Contest) HasProblem

func (c *Contest) HasProblem(problemID int32) bool

func (*Contest) MaxScore

func (c *Contest) MaxScore() int32

func (*Contest) Over

func (c *Contest) Over(team *Team) bool

func (*Contest) RegistrationClosed

func (c *Contest) RegistrationClosed() bool

func (*Contest) RegistrationLimit

func (c *Contest) RegistrationLimit() time.Time

func (*Contest) StartFor

func (c *Contest) StartFor(team *Team) time.Time

func (*Contest) Started

func (c *Contest) Started(team *Team) bool

func (*Contest) UntilEnd

func (c *Contest) UntilEnd(team *Team) time.Duration

func (*Contest) UntilFullEnd

func (c *Contest) UntilFullEnd() time.Duration

func (*Contest) UntilStart

func (c *Contest) UntilStart() time.Duration

func (*Contest) Within

func (c *Contest) Within(time time.Time, team *Team) bool

type ContestProblem

type ContestProblem struct {
	ContestID int32 `db:"contest_id"`
	ProblemID int32 `db:"problem_id"`
	Problem   *Problem
	Label     string
}

A ContestProblem is a problem with associated metadata that appears in a contest.

type Evaluation

type Evaluation struct {
	Score       int32   `db:"score"`
	TimeUsageMS int32   `db:"time_usage_ms"`
	Verdict     Verdict `db:"verdict"`
}

An Evaluation is a collection of the various judgements of a given submission. The evaluation may represent a single test case, a group or the evaluation of an entire submission.

type HTMLString

type HTMLString string

An HTMLString represents a string that is assumed to be safe HTML.

func (HTMLString) HTML

func (s HTMLString) HTML() template.HTML

HTML converts a HTMLString to a template variable for HTML.

type IncludedFiles

type IncludedFiles struct {
	LanguageId     string         `db:"language_id"`
	InclusionFiles types.JSONText `db:"inclusion_files"`
}

type License

type License string

A License is the license under which a problem is published.

const (
	// The Creative Commons by-sa 3 license.
	LicenseCcBySa3 License = "CC_BY_SA_3"
	// A license to reproduce the problem with specific permission.
	LicensePermission License = "BY_PERMISSION"
	// A license for problems that may freely be reproduced for any purpose.
	LicensePublicDomain License = "PUBLIC_DOMAIN"
	// A license for problems that you lack the rights to reproduce.
	LicensePrivate License = "PRIVATE"
)

func (License) String

func (l License) String() string

String returns a user-friendly name for a license.

type NilableStoredFile

type NilableStoredFile struct {
	Hash sql.NullString `db:"hash"`
	URL  []byte         `db:"url"`
}

A NilableStoredFile is used to represent a file that may or may not be present.

func (*NilableStoredFile) Nil

func (s *NilableStoredFile) Nil() bool

Nil checks if the stored file is absent.

type OutputValidator

type OutputValidator struct {
	ValidatorLanguageID sql.NullString     `db:"language_id"`
	ValidatorSourceZIP  *NilableStoredFile `db:"validator_source_zip"`
}

OutputValidator is a custom validator of the output from a submission problem.

type Problem

type Problem struct {
	// The numeric problem ID. This should not be exposed externally.
	ProblemID int32 `db:"problem_id"`
	// The short name of the problem. This is suitable to use in e.g. URLs or as externally-visible identifiers.
	ShortName      string `db:"short_name"`
	Statements     []*ProblemStatement
	Author         string          `db:"author"`
	License        License         `db:"license"`
	CurrentVersion *ProblemVersion `db:"problem_version"`
	Source         string          `db:"source"`
	StatementFiles []*ProblemStatementFile
	PublicFrom     *time.Time `db:"public_from"`
}

A Problem is a problem users can submit solutions to.

func (*Problem) Hidden

func (p *Problem) Hidden() bool
func (p *Problem) Link() string

Link returns a link to the problem page for the problem.

func (*Problem) LocalizedStatement

func (p *Problem) LocalizedStatement(preferred []language.Tag) template.HTML

LocalizedStatement returns the problem statement with preference given to some languages.

func (*Problem) LocalizedTitle

func (p *Problem) LocalizedTitle(preferred []language.Tag) string

LocalizedTitle returns the problem title with preference given to some languages.

func (p *Problem) SubmitLink() string

type ProblemList

type ProblemList []*Problem

func (ProblemList) AsMap

func (pl ProblemList) AsMap() ProblemMap

type ProblemMap

type ProblemMap map[int32]*Problem

ProblemMap maps problem IDs to problems.

func (ProblemMap) Ids

func (p ProblemMap) Ids() []int32

type ProblemStatement

type ProblemStatement struct {
	ProblemID int32 `db:"problem_id"`
	// The tag of the language that the statement is written in.
	Language string `db:"language"`
	// The title of the statement.
	Title string `db:"title"`
	// The HTML template of the statement.
	HTML string `db:"html"`
}

A ProblemStatement is the text statement of a problem in a given language.

type ProblemStatementFile

type ProblemStatementFile struct {
	ProblemID int32 `db:"problem_id"`
	// The tag of the language that the statement is written in.
	Path       string      `db:"file_path"`
	Attachment bool        `db:"attachment"`
	Content    *StoredFile `db:"content"`
}

A ProblemStatementFile is a file that is used by the text statement of a problem.

type ProblemVersion

type ProblemVersion struct {
	ProblemVersionID int32            `db:"problem_version_id"`
	ProblemID        int32            `db:"problem_id"`
	TimeLimMS        int32            `db:"time_limit_ms"`
	MemLimKB         int32            `db:"memory_limit_kb"`
	OutputValidator  *OutputValidator `db:"validator"`
	TestGroups       TestGroupList
	IncludedFiles    []*IncludedFiles
}

A ProblemVersion contains the judging-specific information of a problem that affect submission evaluation.

func (*ProblemVersion) MaxScore

func (p *ProblemVersion) MaxScore() int32

func (*ProblemVersion) MemLimString

func (p *ProblemVersion) MemLimString() string

TimeLimString returns a human formatted string of the memory limit.

func (*ProblemVersion) Samples

func (p *ProblemVersion) Samples() []*TestCase

Samples returns the test cases that should be publicly visible for the problem.

func (*ProblemVersion) TimeLimString

func (p *ProblemVersion) TimeLimString() string

TimeLimString returns a human formatted string of the time limit.

type StatementList

type StatementList []*ProblemStatement

type Status

type Status string

A Status is the execution status of a submission run.

const (
	// The status of a submission that has not yet been processed.
	StatusNew Status = "new"
	// The status of a submission that is currently compiling.
	StatusCompiling Status = "compiling"
	// The status of a submission that failed compiling.
	StatusCompilationFailed Status = "compilation_failed"
	// The status of a submission that is currently being judged on test data.
	StatusRunning Status = "running"
	// The status of a submission that is been successfully processed.
	StatusSuccessful Status = "successful"
)

func (Status) String

func (s Status) String() string

String returns a user-friendly name of a status.

func (Status) Waiting

func (s Status) Waiting() bool

Waiting returns whether the status represents a submission run that is still being

type StoredFile

type StoredFile struct {
	// Hash is a hash of the binary data of the stored file.
	Hash string
	// URL is a descriptor of how to retrieve the file, understood by the filestore service.
	URL []byte
}

A StoredFile represents a stored file in the StoredFile table.

func (*StoredFile) FileData

func (s *StoredFile) FileData() ([]byte, error)

FileData reads the data of the file from the file store.

func (*StoredFile) FileString

func (s *StoredFile) FileString() (string, error)

FileString returns the data of the file as a string.

func (*StoredFile) ToNilable

func (s *StoredFile) ToNilable() *NilableStoredFile

ToNilable converts a StoredFile to a NilableFile.

type Submission

type Submission struct {
	// SubmissionID The numeric ID of the submission. This may exposed externally.
	SubmissionID int32 `db:"submission_id"`
	// The ID of the author of the submission.
	AccountID int32    `db:"account_id"`
	Account   *Account `db:"account"`
	// The ID of the problem the submission was for.
	ProblemID int32 `db:"problem_id"`
	// The tag of the langauge the submission was made in.
	Language string
	// The creation date of the submission.
	Created time.Time `db:"date_created"`
	// The files the submission consists of.
	Files      []*SubmissionFile
	CurrentRun *SubmissionRun `db:"submission_run"`
}

A Submission is a user submission to a problem.

func (s *Submission) Link() string

Link returns the link to the details of the submission.

func (*Submission) ToRunnerProgram

func (s *Submission) ToRunnerProgram() *runpb.Program

ToRunnerProgram serializes submission to a program that can be compiled by the RunService.

type SubmissionFile

type SubmissionFile struct {
	SubmissionID int32 `db:"submission_id"`
	// The path that the file should be placed at, relative to the compilation working directory.
	Path     string `db:"file_path"`
	Contents string `db:"file_contents"`
}

A SubmissionFile is a file that is part of a user submission.

type SubmissionRun

type SubmissionRun struct {
	SubmissionID     int32 `db:"submission_id"`
	SubmissionRunID  int32 `db:"submission_run_id"`
	ProblemVersionID int32 `db:"problem_version_id"`
	Evaluation
	// The current judge workflow status of this run.
	Status       Status
	CompileError sql.NullString `db:"compile_error"`
	Created      time.Time      `db:"date_created"`

	GroupRuns TestGroupRunList `db:"group_runs"`
}

A SubmissionRun is a particular judge execution of a submission. A submission may have multiple runs when rejudged, for example if a new version of the problem is installed.

func (*SubmissionRun) Accepted

func (run *SubmissionRun) Accepted(pv *ProblemVersion) bool

func (*SubmissionRun) GroupScore

func (run *SubmissionRun) GroupScore(name string) int32

func (*SubmissionRun) GroupVerdict

func (run *SubmissionRun) GroupVerdict(name string) Verdict

func (*SubmissionRun) PartialAccepted

func (run *SubmissionRun) PartialAccepted(pv *ProblemVersion) bool

func (*SubmissionRun) Rejected

func (run *SubmissionRun) Rejected() bool

func (*SubmissionRun) StatusString

func (run *SubmissionRun) StatusString(p *ProblemVersion, filtered bool) string

func (*SubmissionRun) Waiting

func (run *SubmissionRun) Waiting() bool

type Team

type Team struct {
	TeamID    int32          `db:"team_id"`
	ContestID int32          `db:"contest_id"`
	TeamName  sql.NullString `db:"team_name"`
	StartTime sql.NullTime   `db:"start_time"`
	Members   TeamMemberList
}

func (*Team) DisplayName

func (t *Team) DisplayName() string
func (t *Team) Link() string

func (*Team) MemberIDs

func (t *Team) MemberIDs() []int32

type TeamList

type TeamList []*Team

type TeamMember

type TeamMember struct {
	TeamID    int32   `db:"team_id"`
	AccountID int32   `db:"account_id"`
	Account   Account `db:"account"`
}

type TeamMemberList

type TeamMemberList []*TeamMember

type TestCase

type TestCase struct {
	TestGroupID int32 `db:"problem_testgroup_id"`
	TestCaseID  int32 `db:"problem_testcase_id"`
	// A user-visible name for the test case.
	Name       string      `db:"testcase_name"`
	InputFile  *StoredFile `db:"input_file"`
	OutputFile *StoredFile `db:"output_file"`
}

A TestCase represents a single test case that submissions can be evaluated on.

type TestCaseRun

type TestCaseRun struct {
	SubmissionRunID int32 `db:"submission_run_id"`
	TestCaseID      int32 `db:"problem_testcase_id"`
	Evaluation
	Created time.Time `db:"date_created"`
}

A TestCaseRun is a particular judge execution of a test case.

type TestGroup

type TestGroup struct {
	TestGroupID      int32 `db:"problem_testgroup_id"`
	ProblemVersionID int32 `db:"problem_version_id"`
	// A user-visible name for the test group.
	Name string `db:"testgroup_name"`
	// Whether the tests in the group should be displayed to users.
	PublicVisibility bool `db:"public_visibility"`
	// The score that should be awarded if the test group is passed.
	Score int32 `db:"score"`
	// The flags that should be provided to output validators when evaluating the group.
	OutputValidatorFlags string `db:"output_validator_flags"`
	Tests                []*TestCase
}

A TestGroup is a group of test cases that belong together for evaluation purposes.

type TestGroupList

type TestGroupList []*TestGroup

func (TestGroupList) AsMap

func (tl TestGroupList) AsMap() TestGroupMap

type TestGroupMap

type TestGroupMap map[int32]*TestGroup

type TestGroupRun

type TestGroupRun struct {
	SubmissionRunID int32  `db:"submission_run_id"`
	TestGroupID     int32  `db:"problem_testgroup_id" json:"problem_testgroup_id"`
	TestGroupName   string `json:"testgroup_name"`
	Evaluation
	Created time.Time `db:"date_created"`
}

A TestGroupRun is a particular judge execution of a test group.

type TestGroupRunList

type TestGroupRunList []*TestGroupRun

func (*TestGroupRunList) Scan

func (m *TestGroupRunList) Scan(v interface{}) error

type Verdict

type Verdict string

A Verdict is the result of a submission on a test case, test group or the entire test data.

const (
	VerdictUnjudged          Verdict = "unjudged"
	VerdictAccepted          Verdict = "accepted"
	VerdictTimeLimitExceeded Verdict = "time_limit_exceeded"
	VerdictRunTimeError      Verdict = "run_time_error"
	VerdictWrongAnswer       Verdict = "wrong_answer"
)

func VerdictFromRunVerdict

func VerdictFromRunVerdict(verdict runpb.Verdict) Verdict

VerdictFromRunVerdict converts a verdict returned from the RunService to a Verdict.

func (Verdict) Accepted

func (v Verdict) Accepted() bool

func (Verdict) Filtered

func (v Verdict) Filtered(filtered bool) string

func (Verdict) String

func (v Verdict) String() string

String returns a user-friendly name of a verdict.

func (Verdict) Waiting

func (v Verdict) Waiting() bool

Jump to

Keyboard shortcuts

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