oioioi.contests.scores
¶
Each score class is represented in database as single string formatted as
"class_symbol:score_data"
where class_symbol
is used for binding
purposes (see ScoreValue
) and score_data
is score in
human readable form.
To create new score class MyScore
you have to choose class_symbol
and decide how to encode score as score_data
.
MyScore should extend ScoreValue
and implement its
unimplemented functions such as __add__()
, __lt__()
etc.
NOTE: when you create a new type of score, make sure that it gets
registered (its class gets loaded) before any attempt to deserialize its
instance.
If you are not sure if this is the case, adding the line
from oioioi.yourapp.score import YourScore
to yourapp.models.py
should fix the problem.
For simple example of score class implementation see IntegerScore
.
Module Contents¶
Classes¶
Base class of all classes that represent a score. Subclass |
|
Score consisting of integer number. |
- class oioioi.contests.scores.ScoreValue[source]¶
Bases:
oioioi.base.utils.ClassInitBase
Base class of all classes that represent a score. Subclass
ScoreValue
to implement a custom score.- symbol = '__override_in_subclasses__'¶
- _subclasses¶
- static deserialize(serialized)[source]¶
Invert the operation of
serialize()
.
- abstract __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.
- abstract __eq__(other)[source]¶
Implementation of operator
==
. Used to produce ranking, being greater means better result.Must be overridden in all subclasses.
- abstract __lt__(other)[source]¶
Implementation of operator
<
. Used to produce ranking, being greater means better result.Must be overridden in all subclasses.
- abstract __unicode__()[source]¶
Returns string representing score, suitable to display to the user.
Must be overridden in all subclasses.
- abstract _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
__eq__()
and__lt__()
, it will be used for sorting at db level.
- abstract 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]¶
Bases:
ScoreValue
Score consisting of integer number.
Database format:
"int:<value>"
Value is padded with zeros to 19 characters.
- symbol = 'int'¶
- __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.
- __eq__(other)[source]¶
Implementation of operator
==
. Used to produce ranking, being greater means better result.Must be overridden in all subclasses.
- __lt__(other)[source]¶
Implementation of operator
<
. 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.
- classmethod _from_repr(value)[source]¶
Creates an instance based on data from
_to_repr()
.Must be overridden in all subclasses.