score

package
v0.0.0-...-34457ff Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2019 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrScoreNotFound = errors.New("score not found in string")

ErrScoreNotFound is returned if the parse string did not contain a JSON score string.

View Source
var GlobalSecret = "NOT SET"

GlobalSecret represents the unique course identifier that will be used in the Score constructors. Users of this package must set this variable appropriately (for example in func init) before using any exported function in this package. The value of the global secret is available from the teachers panel after a course has been created.

Functions

func HasPrefix

func HasPrefix(s string) bool

HasPrefix returns true if the provided string s has a parsable prefix string.

func Total

func Total(scores []*Score) uint8

Total returns the total score computed over the set of scores provided. The total is a grade in the range 0-100.

Types

type GradingScheme

type GradingScheme struct {
	ID uint64 `json:"id"`

	Name        string
	GradePoints []uint8
	GradeNames  []string
}

GradingScheme for an assignment

func (*GradingScheme) Grade

func (g *GradingScheme) Grade(points uint8) string

Grade computes the grade for the given points. The points must be in the range [0,100].

type Score

type Score struct {
	Secret   string // the unique identifier for the course
	TestName string // name of the test
	Score    int    // the score obtained
	MaxScore int    // max score possible to get on this specific test
	Weight   int    // the weight of this test; used to compute final grade
}

Score encodes the score of a test or a group of tests. When a test passes in Autograder, a JSON object representing this struct is emitted to the output stream.

The JSON object emitted on the output stream contains a Secret hash value which is a unique course identifier that can be obtained from the teachers panel in Autograder. This Secret is used by Autograder to extract Score objects from the output stream. All other output is ignored when computing the score.

The Autograder computes the score accoring to the formula below, providing a percentage score for a test or a group of tests. The Weight parameter can be used to give more/less value to some Score objects (representing different test sets). For example, a Weight of 2 on test A and a Weight of 1 on all other tests will give twice the score for test A compare to the other tests.

If you want to only give a score for completing a test, then you can simply use NewScoreMax(1, 1), without using any API methods to decrement the score, giving a result of Score = MaxScore = 1 (and Weight = 1).

The Autograder computes the final score as follows: TotalWeight = sum(Weight) TaskScore[i] = Score[i] / MaxScore[i], gives {0 < TaskScore < 1} TaskWeight[i] = Weight[i] / TotalWeight Score = sum(TaskScore[i]*TaskWeight[i]), gives {0 < Score < 1}

func NewScore

func NewScore(max, weight int) *Score

NewScore returns a new Score object with the given max and weight. The Score.Score field is 0 initially, and so Score.Inc() and IncBy() can be called on the returned Score object. Note that the TestName is initialized to the name of the calling method.

func NewScoreMax

func NewScoreMax(max, weight int) *Score

NewScoreMax returns a new Score object with the given max and weight. The Score.Score field is max initially, and so Score.Dec() and DecBy() can be called on the returned Score object. Note that the TestName is initialized to the name of the calling method.

func Parse

func Parse(s, secret string) (*Score, error)

Parse returns a score object for the provided JSON string s which contains secret.

func (*Score) Dec

func (s *Score) Dec()

Dec decrements score if score is greater than zero.

func (*Score) DecBy

func (s *Score) DecBy(n int)

DecBy decrements score n times or until Score equals zero.

func (*Score) Inc

func (s *Score) Inc()

Inc increments score if score is less than MaxScore.

func (*Score) IncBy

func (s *Score) IncBy(n int)

IncBy increments score n times or until score equals MaxScore.

func (*Score) String

func (s *Score) String() string

String returns a string representation of score s. Format: "TestName: 2/10 cases passed".

func (*Score) WriteJSON

func (s *Score) WriteJSON(w io.Writer)

WriteJSON writes the JSON representation of s to w.

func (*Score) WriteString

func (s *Score) WriteString(w io.Writer)

WriteString writes the string representation of s to w.

Jump to

Keyboard shortcuts

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