Representing scores

Scores may be very different things, based on the rules of the competition. They may be simple numbers, like in IntegerScore or substantially more complex things, like these used for ACM competitions – ACMScore.

Storing scores in models

To store a score in a model field, use oioioi.contests.fields.ScoreField, for example:

from django.db import models
from oioioi.contests.fields import ScoreField
from oioioi.contests.models import SubmissionReport

class ScoreReport(models.Model):
    submission_report = models.ForeignKey(SubmissionReport)
    score = ScoreField()

You cannot then assign primitive types, like int directly, but you can use score types:

from oioioi.contests.scores import IntegerScore

report = ScoreReport(...)
report.score = IntegerScore(2)

# It's also ok to directly assign a serialized value, if you really know
# what you're doing:
serialized_score = IntegerScore(2).serialize()
...
report.score = serialized_score

All score types support at least comparison, addition and human-readable conversion to unicode type.

In database they are represented by VARCHAR columns built from the actual class symbol and serialized data returned by to_repr().

Reference

class oioioi.contests.scores.ScoreValue[source]

Base class of all classes that represent a score. Subclass ScoreValue to implement a custom score.

symbol = '__override_in_subclasses__'

A unique, short class identifier prepended to the database representation of the value. This must be overridden in all subclasses.

serialize()[source]

Converts the instance of any subclass to string.

static deserialize(serialized)[source]

Invert the operation of serialize().

__add__(other)[source]

Implementation of operator +.

Used for example when creating user result for round based on scores from all problems of the round.

Must be overridden in all subclasses.

__cmp__(other)[source]

Implementation of order. Used to produce ranking, being greater means better result.

Must be overridden in all subclasses.

__unicode__()[source]

Returns string representing score, suitable to display to the user.

Must be overridden in all subclasses.

_to_repr()[source]

Returns score data serialized to string, without the class’s symbol.

Must be overridden in all subclasses.

Lexicographical order of serialized data has to correspond to the given by __cmp__(), it will be used for sorting at db level.

classmethod _from_repr(encoded_value)[source]

Creates an instance based on data from _to_repr().

Must be overridden in all subclasses.

class oioioi.contests.scores.IntegerScore(value=0)[source]

Score consisting of integer number.

Database format: "int:<value>"

Value is padded with zeros to 19 characters.