njudge

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VerdictUnknown = Verdict(problems.VerdictUnknown)
	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)
	VerdictSK      = Verdict(problems.VerdictSK)

	VerdictCE Verdict = "CE"
	VerdictRU Verdict = "RU"
	VerdictUP Verdict = "UP"
)

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 ErrorAlreadyActivated = errors.New("njudge: user already activated")
View Source
var (
	ErrorCategoryNotFound = errors.New("njudge: category not found")
)
View Source
var ErrorProblemsetNotFound = errors.New("njudge: problemset 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 ErrorWrongActivationKey = errors.New("njudge: wrong activation key")
View Source
var ProblemFields = struct {
	ID          string
	Problemset  string
	Problem     string
	Category    string
	SolverCount string
	Visible     string
	Author      string

	Tags string
}{
	ID:          "id",
	Problemset:  "problemset",
	Problem:     "problem",
	Category:    "category",
	SolverCount: "solver_count",
	Visible:     "visible",
	Author:      "author",

	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, SubmissionFields.Status, SubmissionFields.Verdict}
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 GetUserPlaceInProblemsetRanklist added in v0.6.0

func GetUserPlaceInProblemsetRanklist(ctx context.Context, name string, userID int, service ProblemsetRanklistService) (int, error)

Types

type Categories

type Categories interface {
	Get(ctx context.Context, id int) (*Category, error)
	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
	Visible  bool
	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 CodeVisibility added in v0.6.0

type CodeVisibility string
const (
	CodeVisibilityPrivate CodeVisibility = "private"
	CodeVisibilitySolved  CodeVisibility = "solved"
	CodeVisibilityPublic  CodeVisibility = "public"
)

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 Judge added in v0.4.0

type Judge struct {
	ID           int
	Name         string
	URL          string
	Online       bool
	ProblemList  []string
	LanguageList []string
}

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
	Visible     bool
	Author      string

	Tags ProblemTags
}

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
	User           *User
}

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 struct {
	problems.Problem
}

func (*ProblemStoredData) GetAttachment

func (p *ProblemStoredData) GetAttachment(attachment string) (problems.NamedData, error)

func (*ProblemStoredData) GetLanguage added in v0.5.0

func (p *ProblemStoredData) GetLanguage(id string) language.Language

func (*ProblemStoredData) GetPDF

func (p *ProblemStoredData) GetPDF(lang Language) (io.ReadCloser, error)

type ProblemTag

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

type ProblemTags added in v0.5.0

type ProblemTags []ProblemTag

func (ProblemTags) ToTags added in v0.5.0

func (p ProblemTags) ToTags() []Tag

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 Problemset added in v0.6.0

type Problemset struct {
	Name           string
	CodeVisibility CodeVisibility
}

type ProblemsetRanklist added in v0.6.0

type ProblemsetRanklist struct {
	Rows           []ProblemsetRanklistRow
	PaginationData PaginationData
}

type ProblemsetRanklistRequest added in v0.6.0

type ProblemsetRanklistRequest struct {
	Name    string
	Page    int
	PerPage int

	FilterAdmin bool
}

type ProblemsetRanklistRow added in v0.6.0

type ProblemsetRanklistRow struct {
	Place int
	ID    int
	Name  string
	Score float64
}

type ProblemsetRanklistService added in v0.6.0

type ProblemsetRanklistService interface {
	GetRanklist(ctx context.Context, req ProblemsetRanklistRequest) (*ProblemsetRanklist, error)
}

type Problemsets added in v0.6.0

type Problemsets interface {
	GetByName(ctx context.Context, problemsetName string) (*Problemset, error)
	GetAll(ctx context.Context) ([]Problemset, error)
	Insert(ctx context.Context, problemset Problemset) error
}

type RegisterRequest

type RegisterRequest struct {
	Name     string
	Email    string
	Password string
}

type SolvedStatus

type SolvedStatus string
const (
	Unattempted     SolvedStatus = "Unattempted"
	Attempted       SolvedStatus = "Attempted"
	PartiallySolved SolvedStatus = "PartiallySolved"
	Solved          SolvedStatus = "Solved"
	Unknown         SolvedStatus = "Unknown"
)

type SolvedStatusQuery added in v0.4.0

type SolvedStatusQuery interface {
	GetSolvedStatus(ctx context.Context, problemID, userID int) (SolvedStatus, error)
}

type SortDirection

type SortDirection string
const (
	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)
	GetACSubmissionsOf(ctx context.Context, problemID int) ([]Submission, error)
}

type SubmitRequest

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

type SubmitService

type SubmitService struct {
	// contains filtered or unexported fields
}

func NewSubmitService added in v0.5.0

func NewSubmitService(users Users, problemQuery ProblemQuery, problemStore problems.Store) *SubmitService

func (*SubmitService) Submit

func (s *SubmitService) Submit(ctx context.Context, req 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 TaskArchiveNode added in v0.5.0

type TaskArchiveNode struct {
	ID           int
	Type         TaskArchiveNodeType
	Category     *Category
	Problem      *Problem
	SolvedStatus SolvedStatus
	Children     []TaskArchiveNode
	Visible      bool
}

func (*TaskArchiveNode) Search added in v0.5.0

func (t *TaskArchiveNode) Search(f func(node *TaskArchiveNode) bool)

type TaskArchiveNodeType added in v0.5.0

type TaskArchiveNodeType string
const (
	TaskArchiveNodeRoot     TaskArchiveNodeType = "root"
	TaskArchiveNodeCategory TaskArchiveNodeType = "category"
	TaskArchiveNodeProblem  TaskArchiveNodeType = "problem"
)

type TaskArchiveService added in v0.5.0

type TaskArchiveService struct {
	Categories        Categories
	Problems          Problems
	SolvedStatusQuery SolvedStatusQuery
	ProblemQuery      ProblemQuery
	ProblemStore      problems.Store
}

func (TaskArchiveService) CreateTopLevel added in v0.5.0

func (tas TaskArchiveService) CreateTopLevel(ctx context.Context, u *User) (*TaskArchiveNode, error)

func (TaskArchiveService) CreateWithCategory added in v0.5.0

func (tas TaskArchiveService) CreateWithCategory(ctx context.Context, category Category, u *User) (*TaskArchiveNode, error)

func (TaskArchiveService) CreateWithRoot added in v0.5.0

func (tas TaskArchiveService) CreateWithRoot(ctx context.Context, categories []Category, u *User, limit int) (*TaskArchiveNode, 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 RegisterUser added in v0.5.0

func RegisterUser(ctx context.Context, users Users, req RegisterRequest, postRegisterFunc func(*User) error) (*User, error)

func (*User) Activate

func (u *User) Activate()

func (*User) ActivateWithKey added in v0.5.0

func (u *User) ActivateWithKey(key string) error

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)
	GetAll(ctx context.Context) ([]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 string

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