polygon

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: MIT Imports: 11 Imported by: 0

README

Introduction

polygon provides a simple interface to interact with Polygon via its API. This library contains all the custom objects mentioned in the API Documentation (along with convenient functions to pretty print them). It provides functions with just one input parameter for each API end point, while doing the rest of the steps internally, (such as creating the URL according to API specifications, unmarshalling into custom objects, error handling, etc)

For example, once you've created an API object, calling an endpoint is as easy as api.ProblemsList(parameters), where parameters is a map containing all your required parameters.

Installation

Just running

go get github.com/variety-jones/polygon

should add this package to your GOPATH.

Usage

To use it to create custom applications, you just need to import it via

import github.com/variety-jones/polygon

After that, each API can be accessed via the polygon.PolygonApi object.

Note that due to Go language specifications, all functions/structs/exposed-fields from the polygon library would start with a capital letter. Also, you have to skip the dots in the name and capitalize the letter following the dot.

For example,

problem.saveStatement can be called via api.ProblemSaveStatement

Examples

To get a better understanding of how to use this package, please go through this example

Documentation

For a detailed documentation of each function's description, parameters and return types, along with the exposed fields of the custom objects, visit this Package documentation

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileObject

type FileObject struct {
	Name                       string
	ModificationTimeSeconds    int64
	Length                     int64
	SourceType                 string
	ResourceAdvancedProperties ResourceAdvancedPropertiesObject
}

FileObject represents a resource, source or aux file.

Parameter Description

Name : name

ModificationTimeSeconds : file’s modification time in unix format

Length : file length

SourceType : (present only for source files) - source file type

ResourceAdvancedProperties : (may be absent) Problem resource files can have extra property called ResourceAdvancedProperties of type ResourceAdvancedProperties

TODO

Address name conflicts

func (*FileObject) Prettify

func (file *FileObject) Prettify() (prettyFile string, err error)

Prettify pretty prints a fileObject

type PackageObject

type PackageObject struct {
	Id                  int64
	Revision            int
	CreationTimeSeconds int64
	State               string
	Comment             string
}

PackageObject represents a package

Parameter Description

Id : package’s id

Revision : revision of the problem for which the package was created

CreationTimeSeconds : package’s creation time in unix format

State : PENDING/RUNNING/READY/FAILED package’s state

Comment : comment for the package

func (*PackageObject) Prettify

func (packageObj *PackageObject) Prettify() (prettyPackage string, err error)

Prettify pretty prints a PackageObject

type PolygonApi

type PolygonApi struct {
	ApiKey    string
	Secret    string
	ProblemId string
}

PolygonApi stores metadata for API calls

func (*PolygonApi) ContestProblems

func (api *PolygonApi) ContestProblems(parameters map[string]string) (problems []ProblemObject, err error)

ContestProblems returns a list of Problem objects - problems of the contest.

Parameters

contestId : The ID of the contest

func (*PolygonApi) ProblemChecker

func (api *PolygonApi) ProblemChecker(parameters map[string]string) (checkerName string, err error)

ProblemChecker returns the name of currently set checker.

func (*PolygonApi) ProblemEditSolutionExtraTags

func (api *PolygonApi) ProblemEditSolutionExtraTags(parameters map[string]string) (err error)

ProblemEditSolutionExtraTags adds or remove testset or test group extra tag for solution.

Parameters

remove : boolean, if true - remove extra tag, if false - add extra tag

name : solution name

testset : optional - testset name for which edit extra tag

testGroup : optional - test group name for which edit extra tag. Exactly one from testset and testGroup should be specified

tag : optional - when you add extra tag - solution’s extra tag (OK, RJ, TL, TO - Time Limit or Accepted, WA, PE, ML or RE)

func (*PolygonApi) ProblemEnableGroups

func (api *PolygonApi) ProblemEnableGroups(parameters map[string]string) (err error)

ProblemEnableGroups enable or disable test groups for the specified testset.

Parameters

testset : testset to enable or disable groups

enable : bool - if it is true test groups become enabled, else test groups become disabled

func (*PolygonApi) ProblemEnablePoints

func (api *PolygonApi) ProblemEnablePoints(parameters map[string]string) (err error)

ProblemEnablePoints enable or disable test points for the problem.

Parameters

enable : bool - if it is true test points become enabled, else test points become disabled

func (*PolygonApi) ProblemFiles

func (api *PolygonApi) ProblemFiles(parameters map[string]string) (rsa RsaObject, err error)

ProblemFiles returns the list of resource, source and aux files. Method returns a JSON object with three fields: resource, source, aux. EAch of them is a list of FileObject

func (*PolygonApi) ProblemInfo

func (api *PolygonApi) ProblemInfo(parameters map[string]string) (problemInfo ProblemInfoObject, err error)

ProblemInfo return a ProbelmInfoObject representing metadata about the problem

func (*PolygonApi) ProblemInteractor

func (api *PolygonApi) ProblemInteractor(parameters map[string]string) (interactorName string, err error)

ProblemInteractor returns the name of currently set interactor

func (*PolygonApi) ProblemPackages

func (api *PolygonApi) ProblemPackages(parameters map[string]string) (packages []PackageObject, err error)

ProblemPackages returns a list of Package objects - list all packages available for the problem.

Parameters

None

func (*PolygonApi) ProblemSaveFile

func (api *PolygonApi) ProblemSaveFile(parameters map[string]string) (err error)

ProblemSaveFile is used to add or edit resource, source or aux file. In case of editing, all parameters except for type and name are optional.

Parameters

checkExisting - boolean, optional - if true, only adding files is allowed

type - file type (resource/source or aux)

name - file name

file - file content

sourceType - optional - source type (in case of a source file)

In case of type=resource there are some possible additional parameters

forTypes - optional - semicolon separated list of applicable file types (see ResourceAdvancedProperties)

stages - optional - semicolon separated list of values COMPILE or RUN, meaning the phase when the resource is applicable (currently only stages=COMPILE is supported)

assets - optional - semicolon separated list of values VALIDATOR, INTERACTOR, CHECKER, SOLUTION, meaning the asset types the resource is applicable (currently only assets=SOLUTION is supported)

The parameters forTypes, stages, assets can be present only together (it means, all of them are absent or all of them are used at the same time). They can be used only for type=resource. To delete ResourceAdvancedProperties of a resource file pass empty “forTypes=”.

func (*PolygonApi) ProblemSaveGeneralDescription

func (api *PolygonApi) ProblemSaveGeneralDescription(parameters map[string]string) (err error)

ProblemSaveGeneralDescription saves problem general description.

Parameters

description : string – the problem general description to save. The description may be empty.

func (*PolygonApi) ProblemSaveGeneralTutorial

func (api *PolygonApi) ProblemSaveGeneralTutorial(parameters map[string]string) (err error)

ProblemSaveGeneralTutorial saves problem general tutorial.

Parameters:

tutorial : string – the problem general tutorial to save. The tutorial may be empty.

func (*PolygonApi) ProblemSaveScript

func (api *PolygonApi) ProblemSaveScript(parameters map[string]string) (err error)

ProblemSaveScript edits script.

Parameters

testset : testset of the script source : script source

func (*PolygonApi) ProblemSaveSolution

func (api *PolygonApi) ProblemSaveSolution(parameters map[string]string) (err error)

ProblemSaveSolution adds or edits solution In case of editing, all parameters except for name are optional.

Parameters

checkExisting : boolean, optional - if true, only adding solutions is allowed

name : solution name

file : solution content

sourceType : optional - source type

tag : solution’s tag (MA - Main, OK, RJ, TL, TO - Time Limit or Accepted, WA, PE, ML or RE)

func (*PolygonApi) ProblemSaveStatement

func (api *PolygonApi) ProblemSaveStatement(parameters map[string]string) (err error)

ProblemSaveStatement updates or creates a problem’s statement. All parameters except for lang are optional.

Parameters

lang : (required) - statement’s language

encoding : statement’s encoding

name : problem’s name in statement’s language

legend : problem’s language

input : problem’s input format

output : problem’s output format

scoring : problem’s scoring

notes : statement notes

tutorial : problem’s tutorial

func (*PolygonApi) ProblemSaveStatementResource

func (api *PolygonApi) ProblemSaveStatementResource(parameters map[string]string) (err error)

ProblemSaveStatementResource adds or edit statement resource file

Parameters

checkExisting : boolean, optional - if true, only adding files is allowed

name : file name

file : file content

func (*PolygonApi) ProblemSaveTags

func (api *PolygonApi) ProblemSaveTags(parameters map[string]string) (err error)

ProblemSaveTags Saves tags for the problem. Existed tags will be replaced by new tags.

Parameters

tags – string of tags, separated by a comma. If you specified several same tags will be add only one of them.

func (*PolygonApi) ProblemSaveTest

func (api *PolygonApi) ProblemSaveTest(parameters map[string]string) (err error)

ProblemSaveTest adds or edit test. In case of editing, all parameters except for testset and testIndex are optional.

Parameters

checkExisting : boolean, optional - if true, only adding new test is allowed

testset : testset of the test

testIndex : index of the test

testInput : test input

testGroup : optional - test group (groups should be enabled for the testset)

testPoints : optional - test points (points should be enabled for the problem)

testDescription : optional - test description

testUseInStatements : bool, optional - whether to use test in statements

testInputForStatements : optional - test input for viewing in the statements

testOutputForStatements : optional - test output for viewing in the statements

verifyInputOutputForStatements : bool, optional - whether to verify input and output for statements

func (*PolygonApi) ProblemSaveTestGroups

func (api *PolygonApi) ProblemSaveTestGroups(parameters map[string]string) (err error)

ProblemSaveTestGroups Saves test group. Use if only to save a test group. If you want to create new test group, just add new test with such test group.

Parameters

testset : testset name

group : test group name

pointsPolicy : optional - COMPLETE_GROUP or EACH_TEST (leaves old value if no specified)

feedbackPolicy : optional - NONE, POINTS, ICPC or COMPLETE (leaves old value if no specified)

dependencies : optional - string of group names from which group should depends on separated by a comma

func (*PolygonApi) ProblemScript

func (api *PolygonApi) ProblemScript(parameters map[string]string) (scriptView string, err error)

ProblemScript returns script for generating tests. it returns plain view of the script.

Parameters

testset : testset for which the script is requested

func (*PolygonApi) ProblemSetChecker

func (api *PolygonApi) ProblemSetChecker(parameters map[string]string) (err error)

ProblemSetChecker updates checker

Parameters

checker : name of the checker (one of the source files)

func (*PolygonApi) ProblemSetInteractor

func (api *PolygonApi) ProblemSetInteractor(parameters map[string]string) (err error)

ProblemSetInteractor updates interactor

Parameters

interactor : name of the interactor (one of the source files)

func (*PolygonApi) ProblemSetTestGroup

func (api *PolygonApi) ProblemSetTestGroup(parameters map[string]string) (err error)

ProblemSetTestGroup sets test group for one or more tests. It expects that for specified testset test groups are enabled.

Parameters

testset : testset of the test(s)

testGroup : test group name to set

testIndex : index of the test, you can specify multiple parameters with the same name testIndex, to set test group to many tests of the same testset at the same time.

testIndices : list of test indices, separated by a comma. It’s alternative for testIndex, you should use only one from these two ways

func (*PolygonApi) ProblemSetValidator

func (api *PolygonApi) ProblemSetValidator(parameters map[string]string) (err error)

ProblemSetValidator updates validatdor

Parameters

validator : name of the validator (one of the source files)

func (*PolygonApi) ProblemSolutions

func (api *PolygonApi) ProblemSolutions(parameters map[string]string) (solutions []SolutionObject, err error)

ProblemSolutions returns the list of Solution objects.

func (*PolygonApi) ProblemStatementResources

func (api *PolygonApi) ProblemStatementResources(parameters map[string]string) (files []FileObject, err error)

ProblemStatementResources returns a list of statement resources for the problem.

Parameters

None

func (*PolygonApi) ProblemStatements

func (api *PolygonApi) ProblemStatements(parameters map[string]string) (statementsMap map[string]StatementObject, err error)

ProblemStatements returns a map from language to a Statement object for that language.

func (*PolygonApi) ProblemTestAnswer

func (api *PolygonApi) ProblemTestAnswer(parameters map[string]string) (testAnswerView string, err error)

ProblemTestAnswer returns generated test answer. It returns a plain view of the answer

Parameters

testset : testset of the test

testIndex : index of the test

func (*PolygonApi) ProblemTestInput

func (api *PolygonApi) ProblemTestInput(parameters map[string]string) (testInputView string, err error)

ProblemTestInput returns generated test input. It returns plain view of the resource.

Parameters

testset : testset of the test

testIndex : index of the test

func (*PolygonApi) ProblemTests

func (api *PolygonApi) ProblemTests(parameters map[string]string) (tests []TestObject, err error)

ProblemTests Rreturns tests for the given testset It returns a list of Test objects.

Parameters

testset : testset for which tests are requested

func (*PolygonApi) ProblemUpdateInfo

func (api *PolygonApi) ProblemUpdateInfo(parameters map[string]string) (err error)

ProblemUpdateInfo updates problem info. All parameters are optional.

Parameters

inputFile : problem’s input file

outputFile : problem’s output file

interactive : boolean - is problem interactive

timeLimit : problem’s time limit in milliseconds

memoryLimit : problem’s memory limit in MB

func (*PolygonApi) ProblemValidator

func (api *PolygonApi) ProblemValidator(parameters map[string]string) (validatorName string, err error)

ProblemValidator returns the name of currently set validator

func (*PolygonApi) ProblemViewFile

func (api *PolygonApi) ProblemViewFile(parameters map[string]string) (fileView string, err error)

ProblemViewFile returns resource, source or aux file. It returns plain view of the file with the corresponding mime-type set.

Parameters

type : resource/aux/source - requested file’s type

name : file name

func (*PolygonApi) ProblemViewGeneralDescription

func (api *PolygonApi) ProblemViewGeneralDescription(parameters map[string]string) (description string, err error)

ProblemViewGeneralDescription returns problem general description.

Parameters

None.

Returns

A string – the problem general description.

func (*PolygonApi) ProblemViewGeneralTutorial

func (api *PolygonApi) ProblemViewGeneralTutorial(parameters map[string]string) (tutorial string, err error)

ProblemViewGeneralTutorial returns problem general tutorial.

Parameters

None

Returns

A string – the problem general tutorial.

func (*PolygonApi) ProblemViewSolution

func (api *PolygonApi) ProblemViewSolution(parameters map[string]string) (solutionView string, err error)

ProblemViewSolution returns a view of the solution file

Parameters

name : solution’s name

func (*PolygonApi) ProblemViewTags

func (api *PolygonApi) ProblemViewTags(parameters map[string]string) (tags []string, err error)

ProblemViewTags returns tags for the problem.

Parameters

None.

Returns

A list of strings – tags for the problem.

func (*PolygonApi) ProblemViewTestGroup

func (api *PolygonApi) ProblemViewTestGroup(parameters map[string]string) (testGroups []TestGroupObject, err error)

ProblemViewTestGroup returns test groups for the specified testset.

Parameters

testset : testset name

group : optional - test group name

Returns

A list of TestGroup objects.

func (*PolygonApi) ProblemsList

func (api *PolygonApi) ProblemsList(parameters map[string]string) (problems []ProblemObject, err error)

ProblemsList returns a list of problems, available to the user, according to search parameters.

Parameters

showDeleted : bool, optional - show/hide deleted problems (defaults to false)

id : problem id, optional

name : problem name, optional

owner : problem owner login, optional

Returns

A list of Problem objects.

type ProblemInfoObject

type ProblemInfoObject struct {
	InputFile   string
	OutputFile  string
	Interactive bool
	TimeLimit   int
	MemoryLimit int
}

ProblemInfoObject represents problem’s general information

Parameter Description

InputFile : problem’s input file

OutputFile : problem’s output file

Interactive : is problem interactive

TimeLimit : problem’s time limit in milliseconds

MemoryLimit : problem’s memory limit in MB

func (*ProblemInfoObject) Prettify

func (problemInfo *ProblemInfoObject) Prettify() (prettyInfo string, err error)

Prettify pretty prints a ProblemInfoObject

type ProblemObject

type ProblemObject struct {
	Id            int
	Owner         string
	Name          string
	Deleted       bool
	Favourite     bool
	AccessType    string
	Revision      int
	LatestPackage int
	Modified      bool
}

ProblemObject represents a polygon problem

Parameter Description

Id : problem id

Owner : problem owner handle

Name : problem name

Deleted : is a problem deleted

Favourite : is a problem in user's favourites

AccessType : user’s access type for the problem

Revision : current problem revision

LatestPackage : latest revision with package available (may be absent)

Modified : is the problem modified

func (*ProblemObject) Prettify

func (problem *ProblemObject) Prettify() (prettyProblem string, err error)

Prettify pretty prints a ProblemObject

type ResourceAdvancedPropertiesObject

type ResourceAdvancedPropertiesObject struct {
	ForTypes string
	Main     bool
	Stages   []string
	Assets   []string
}

ResourceAdvancedPropertiesObject represents special properties of resource files. Basically, they stand for compile- or run-time resources for specific file types and asset types. The most important application is IOI-style graders.

Example: {"forTypes":"cpp.*","main":false,"stages":["COMPILE"],"assets":["SOLUTION"]}

Parameter Description

ForTypes : colon or semicolon separated list of file types this resource if applied, wildcards are supported (example: “cpp.*” or “pascal.*;java.11”)

Main : currently reserved to be false,

Stages : array of possible string values COMPILE or RUN, meaning the phase when the resource is applicable,

Assets : array of possible string values VALIDATOR, INTERACTOR, CHECKER, SOLUTION, meaning the asset types the resource is applicable.

type RsaObject

type RsaObject struct {
	ResourceFiles []FileObject
	SourceFiles   []FileObject
	AuxFiles      []FileObject
}

RsaObject represents a slice of resource, source and aux fileObjects

type SolutionObject

type SolutionObject struct {
	Name                    string
	ModificationTimeSeconds int64
	Length                  int64
	SourceType              string
	Tag                     string
}

SolutionObject represents a problem solution

Parameter Description

Name : solution name

ModificationTimeSeconds : solution’s modification time in unix format

Length : solution length

SourceType : source file type

Tag : solution tag

func (*SolutionObject) Prettify

func (solution *SolutionObject) Prettify() (prettySolution string, err error)

Prettify pretty prints a SolutionObject

type StatementObject

type StatementObject struct {
	Encoding string
	Name     string
	Legend   string
	Input    string
	Output   string
	Scoring  string
	Notes    string
	Tutorial string
}

StatementObject represents a problem’s statement

Parameter Description

Encoding : statement’s encoding

Name : problem’s name in statement’s language

Legend : problem’s language

Input : problem’s input format

Output : problem’s output format

Scoring : problem’s scoring

Notes : statement notes

Tutorial : problem’s tutorial

func (*StatementObject) Prettify

func (statement *StatementObject) Prettify() (prettyStatement string, err error)

Prettify pretty prints a StatementObject

type TestGroupObject

type TestGroupObject struct {
	Name           string
	PointsPolicy   string
	FeedbackPolicy string
	Dependencies   string
}

TestGroupObject represents a test group in testset

Parameter Description

Name : test group name

PointsPolicy : test group points policy,

COMPLETE_GROUP for the complete group points policy,
EACH_TEST for the each test points policy

FeedbackPolicy : test group feedback policy,

COMPLETE for the complete feedback policy,
ICPC for the first error feedback policy, POINTS for the only points feedback policy,
NONE for no feedback policy.

Dependencies : list of group names from which this group depends on (may be empty)

func (*TestGroupObject) Prettify

func (test *TestGroupObject) Prettify() (prettyTestGroup string, err error)

Prettify pretty prints a TestGroupObject

type TestObject

type TestObject struct {
	Index                          int
	Manual                         bool
	Input                          string
	Description                    string
	UseInStatements                bool
	ScriptLine                     string
	Groups                         string
	Points                         string
	InputForStatement              string
	OutputForStatement             string
	VerifyInputOutputForStatements bool
}

TestObject represents a test for the problem.

Parameter Description

Index : test index

Manual : boolean - whether test is manual or generated

Input : test input (absent for generated tests)

Description : test description (may be absent)

UseInStatements : boolean - whether test is included in statements

ScriptLine : script line for generating test (absent for manual tests)

Groups : test group (may be absent)

Points : test points (may be absent)

InputForStatement : input for statements (may be absent)

OutputForStatement : output for statements (may be absent)

VerifyInputOutputForStatements : boolean - whether to verify input and output for statements (may be absent)

func (*TestObject) Prettify

func (test *TestObject) Prettify() (prettyTest string, err error)

Prettify pretty prints a TestObject

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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