njudge

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VerdictAC = Verdict(problems.VerdictAC)
	VerdictWA = Verdict(problems.VerdictWA)
	VerdictRE = Verdict(problems.VerdictRE)
	VerdictTL = Verdict(problems.VerdictTL)
	VerdictML = Verdict(problems.VerdictML)
	VerdictXX = Verdict(problems.VerdictXX)
	VerdictDR = Verdict(problems.VerdictDR)
	VerdictPC = Verdict(problems.VerdictPC)
	VerdictPE = Verdict(problems.VerdictPE)

	VerdictCE Verdict = 998
	VerdictRU Verdict = 999
	VerdictUP Verdict = 1000
)

Variables

View Source
var (
	ErrorProblemNotFound    = errors.New("njudge: problem not found")
	ErrorFileNotFound       = errors.New("njudge: file not found")
	ErrorStatementNotFound  = errors.New("njudge: statement not found")
	ErrorProblemTagNotFound = errors.New("njudge: problem tag not found")
)
View Source
var (
	ErrorNonAlphanumeric = errors.New("njudge: string is not alphanumeric")
	ErrorFieldRequired   = errors.New("njudge: field must not be empty")
	ErrorUnknownRole     = errors.New("njudge: unknown role")
	ErrorSameName        = errors.New("njudge: name already in use")
	ErrorSameEmail       = errors.New("njudge: email already in use")
)
View Source
var (
	ErrorCategoryNotFound = errors.New("njudge: category not found")
)
View Source
var ErrorSubmissionNotFound = errors.New("njudge: submission not found")
View Source
var (
	ErrorTagNotFound = errors.New("njudge: tag not found")
)
View Source
var (
	ErrorUnableToModifyProblemTags = errors.New("njudge: user can't modify tags")
)
View Source
var ErrorUnsupportedLanguage = errors.New("njudge: unsupported language")
View Source
var (
	ErrorUserNotFound = errors.New("njudge: user not found")
)
View Source
var ProblemFields = struct {
	ID          string
	Problemset  string
	Problem     string
	Category    string
	SolverCount string
	Tags        string
}{
	ID:          "id",
	Problemset:  "problemset",
	Problem:     "problem",
	Category:    "category",
	SolverCount: "category",
	Tags:        "tags",
}
View Source
var SubmissionFields = struct {
	ID string

	UserID    string
	ProblemID string
	Language  string
	Source    string
	Private   string

	Started   string
	Verdict   string
	Ontest    string
	Submitted string
	Status    string
	Judged    string
	Score     string
}{
	ID:        "id",
	UserID:    "user_id",
	ProblemID: "problem_id",
	Language:  "language",
	Source:    "source",
	Private:   "private",
	Started:   "started",
	Verdict:   "verdict",
	Ontest:    "ontest",
	Submitted: "submitted",
	Status:    "status",
	Judged:    "judged",
	Score:     "score",
}
View Source
var SubmissionRejudgeFields = []string{SubmissionFields.Judged, SubmissionFields.Started}
View Source
var UserFields = struct {
	ID                   string
	Name                 string
	Password             string
	Email                string
	ActivationInfo       string
	Role                 string
	Points               string
	Settings             string
	Created              string
	ForgottenPasswordKey string
}{
	ID:                   "id",
	Name:                 "name",
	Password:             "password",
	Email:                "email",
	ActivationInfo:       "activated",
	Role:                 "role",
	Points:               "points",
	Settings:             "settings",
	Created:              "created",
	ForgottenPasswordKey: "forgotten_password_key",
}

Functions

func Fields

func Fields(s ...string) []string

func NewRegisterService

func NewRegisterService(u Users) *registerService

Types

type Categories

type Categories interface {
	GetAll(ctx context.Context) ([]Category, error)
	GetAllWithParent(ctx context.Context, parentID int) ([]Category, error)
	Insert(ctx context.Context, c Category) (*Category, error)
}

type Category

type Category struct {
	ID       int
	Name     string
	ParentID null.Int
}

func NewCategory

func NewCategory(name string, parent *Category) *Category

type CategoryFilter

type CategoryFilter struct {
	Type  CategoryFilterType
	Value interface{}
}

func NewCategoryEmptyFilter

func NewCategoryEmptyFilter() CategoryFilter

func NewCategoryIDFilter

func NewCategoryIDFilter(ID int) CategoryFilter

type CategoryFilterType

type CategoryFilterType int
const (
	CategoryFilterNone CategoryFilterType = iota
	CategoryFilterEmpty
	CategoryFilterID
)

type ForgottenPasswordKey

type ForgottenPasswordKey struct {
	ID         int
	UserID     int
	Key        string
	ValidUntil time.Time
}

func NewForgottenPasswordKey

func NewForgottenPasswordKey(validDuration time.Duration) ForgottenPasswordKey

func (*ForgottenPasswordKey) IsValid

func (f *ForgottenPasswordKey) IsValid() bool

type HashedPassword

type HashedPassword string

func NewHashedPassword

func NewHashedPassword(password string) (HashedPassword, error)

type Language

type Language string
const (
	LanguageHungarian Language = "hungarian"
	LanguageEnglish   Language = "english"
)

type PagedSubmissionList

type PagedSubmissionList struct {
	PaginationData PaginationData
	Submissions    []Submission
}

type PaginationData

type PaginationData struct {
	Page    int
	PerPage int
	Pages   int
	Count   int
}

type Problem

type Problem struct {
	ID          int
	Problemset  string
	Problem     string
	Category    *Category
	SolverCount int

	Tags []ProblemTag
}

func NewProblem

func NewProblem(problemset, problem string) Problem

func (*Problem) AddTag

func (p *Problem) AddTag(t Tag, userID int) error

func (*Problem) DeleteTag

func (p *Problem) DeleteTag(t Tag) error

func (*Problem) HasTag

func (p *Problem) HasTag(t Tag) bool

func (*Problem) SetCategory

func (p *Problem) SetCategory(c Category)

func (*Problem) WithStoredData

func (p *Problem) WithStoredData(store problems.Store) (ProblemStoredData, error)

type ProblemInfo

type ProblemInfo struct {
	UserInfo *ProblemUserInfo
}

type ProblemInfoQuery

type ProblemInfoQuery interface {
	GetProblemData(ctx context.Context, problemID, userID int) (*ProblemInfo, error)
}

type ProblemList

type ProblemList struct {
	PaginationData PaginationData
	Problems       []Problem
}

type ProblemListQuery

type ProblemListQuery interface {
	GetProblemList(ctx context.Context, req ProblemListRequest) (*ProblemList, error)
}

type ProblemListRequest

type ProblemListRequest struct {
	Problemset     string
	SortDir        SortDirection
	SortField      ProblemSortField
	Page           int
	PerPage        int
	TitleFilter    string
	TagFilter      []string
	CategoryFilter CategoryFilter
}

func (ProblemListRequest) IsFiltered

func (r ProblemListRequest) IsFiltered() bool

type ProblemQuery

type ProblemQuery interface {
	GetProblem(ctx context.Context, problemset, problem string) (*Problem, error)
	GetProblemsWithCategory(ctx context.Context, f CategoryFilter) ([]Problem, error)
}

type ProblemSortField

type ProblemSortField string
var (
	ProblemSortFieldID          ProblemSortField = "id"
	ProblemSortFieldSolverCount ProblemSortField = "solver_count"
)

type ProblemStoredData

type ProblemStoredData interface {
	problems.Problem

	GetPDF(lang Language) (io.ReadCloser, error)
	GetFile(filename string) (string, error)
	GetAttachment(name string) (problems.NamedData, error)
}

type ProblemTag

type ProblemTag struct {
	ProblemID int
	Tag       Tag
	UserID    int
	Added     time.Time
}

type ProblemUserInfo

type ProblemUserInfo struct {
	SolvedStatus SolvedStatus
	LastLanguage string
	Submissions  []Submission
}

type Problems

type Problems interface {
	Get(ctx context.Context, ID int) (*Problem, error)
	GetAll(ctx context.Context) ([]Problem, error)
	Insert(ctx context.Context, p Problem) (*Problem, error)
	Delete(ctx context.Context, ID int) error
	Update(ctx context.Context, p Problem, fields []string) error
}

type RegisterRequest

type RegisterRequest struct {
	Name     string
	Email    string
	Password string
}

type RegisterService

type RegisterService interface {
	Register(ctx context.Context, req RegisterRequest) (*User, error)
}

type SolvedStatus

type SolvedStatus int
const (
	Unattempted SolvedStatus = iota
	Attempted
	PartiallySolved
	Solved
	Unknown
)

type SortDirection

type SortDirection string
var (
	SortASC  SortDirection = "ASC"
	SortDESC SortDirection = "DESC"
)

type Submission

type Submission struct {
	ID int

	UserID    int
	ProblemID int
	Language  string
	Source    []byte
	Private   bool

	Started   bool
	Verdict   Verdict
	Ontest    null.String
	Submitted time.Time
	Status    problems.Status
	Judged    null.Time
	Score     float32
}

func NewSubmission

func NewSubmission(u User, p Problem, language language.Language) (*Submission, error)

func (*Submission) GetProblem

func (s *Submission) GetProblem(ctx context.Context, ps Problems) (*Problem, error)

func (*Submission) GetUser

func (s *Submission) GetUser(ctx context.Context, us Users) (*User, error)

func (*Submission) MarkForRejudge

func (s *Submission) MarkForRejudge()

func (*Submission) SetSource

func (s *Submission) SetSource(src []byte)

type SubmissionList

type SubmissionList struct {
	Submissions []Submission
}

type SubmissionListQuery

type SubmissionListQuery interface {
	GetPagedSubmissionList(ctx context.Context, req SubmissionListRequest) (*PagedSubmissionList, error)

	GetSubmissionList(ctx context.Context, req SubmissionListRequest) (*SubmissionList, error)
	GetAttemptedSubmissionList(ctx context.Context, userID int) (*SubmissionList, error)
	GetSolvedSubmissionList(ctx context.Context, userID int) (*SubmissionList, error)
}

type SubmissionListRequest

type SubmissionListRequest struct {
	Problemset string
	Problem    string
	SortDir    SortDirection
	SortField  SubmissionSortField
	Page       int
	PerPage    int
	Verdict    *Verdict
	UserID     int
}

type SubmissionSortField

type SubmissionSortField string
var (
	SubmissionSortFieldID    SubmissionSortField = "id"
	SubmissionSortFieldScore SubmissionSortField = "score"
)

type Submissions

type Submissions interface {
	Get(ctx context.Context, ID int) (*Submission, error)
	GetAll(ctx context.Context) ([]Submission, error)
	Insert(ctx context.Context, s Submission) (*Submission, error)
	Delete(ctx context.Context, ID int) error
	Update(ctx context.Context, s Submission, fields []string) error
}

type SubmissionsQuery

type SubmissionsQuery interface {
	GetUnstarted(ctx context.Context, limit int) ([]Submission, error)
}

type SubmitRequest

type SubmitRequest struct {
	UserID     int
	Problemset string
	Problem    string
	Language   string
	Source     []byte
}

type SubmitService

type SubmitService interface {
	Submit(ctx context.Context, subRequest SubmitRequest) (*Submission, error)
}

type Tag

type Tag struct {
	ID   int
	Name string
}

func NewTag

func NewTag(name string) *Tag

type Tags

type Tags interface {
	Get(ctx context.Context, ID int) (*Tag, error)
	GetByName(ctx context.Context, name string) (*Tag, error)
	GetAll(ctx context.Context) ([]Tag, error)
	Insert(ctx context.Context, p Tag) (*Tag, error)
	Delete(ctx context.Context, ID int) error
	Update(ctx context.Context, p Tag) error
}

type TagsService

type TagsService interface {
	Add(ctx context.Context, tagID int, problemID int, userID int) error
	Delete(ctx context.Context, tagID int, problemID int, userID int) error
}

type User

type User struct {
	ID                   int
	Name                 string
	Password             HashedPassword
	Email                string
	ActivationInfo       UserActivationInfo
	Role                 string
	Points               float32
	Settings             UserSettings
	Created              time.Time
	ForgottenPasswordKey *ForgottenPasswordKey
}

func NewUser

func NewUser(name, email, role string) (*User, error)

func (*User) Activate

func (u *User) Activate()

func (*User) AuthenticatePassword

func (u *User) AuthenticatePassword(password string) bool

func (*User) DeleteForgottenPasswordKey

func (u *User) DeleteForgottenPasswordKey()

func (*User) SetForgottenPasswordKey

func (u *User) SetForgottenPasswordKey(fpkey ForgottenPasswordKey)

func (*User) SetPassword

func (u *User) SetPassword(password string) error

type UserActivationInfo

type UserActivationInfo struct {
	Activated bool
	Key       string
}

func GenerateActivationKey

func GenerateActivationKey() UserActivationInfo

type UserSettings

type UserSettings struct {
	ShowUnsolvedTags bool
}

type Users

type Users interface {
	Get(ctx context.Context, ID int) (*User, error)
	GetByName(ctx context.Context, name string) (*User, error)
	GetByEmail(ctx context.Context, email string) (*User, error)
	Insert(ctx context.Context, u User) (*User, error)
	Delete(ctx context.Context, ID int) error
	Update(ctx context.Context, user *User, fields []string) error
}

type Verdict

type Verdict int

func VerdictFromProblemsVerdictName

func VerdictFromProblemsVerdictName(name problems.VerdictName) Verdict

func (Verdict) String

func (v Verdict) String() string

func (Verdict) Translate

func (v Verdict) Translate(t i18n.Translator) string

Directories

Path Synopsis
db

Jump to

Keyboard shortcuts

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