:py:mod:`oioioi.contests.scores` ================================ .. py:module:: oioioi.contests.scores .. autoapi-nested-parse:: 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 :class:`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 :class:`ScoreValue` and implement its unimplemented functions such as :py:func:`__add__`, :py:func:`__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 :class:`IntegerScore`. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: oioioi.contests.scores.ScoreValue oioioi.contests.scores.IntegerScore .. py:class:: ScoreValue Bases: :py:obj:`oioioi.base.utils.ClassInitBase` Base class of all classes that represent a score. Subclass :class:`ScoreValue` to implement a custom score. .. py:attribute:: symbol :annotation: = __override_in_subclasses__ .. py:attribute:: _subclasses .. py:method:: __classinit__() :classmethod: Adds subclasses' bindings. .. py:method:: serialize() Converts the instance of any subclass to string. .. py:method:: __repr__() Return repr(self). .. py:method:: deserialize(serialized) :staticmethod: Invert the operation of :meth:`serialize`. .. py:method:: __add__(other) :abstractmethod: 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. .. py:method:: __eq__(other) :abstractmethod: Implementation of operator ``==``. Used to produce ranking, being greater means better result. Must be overridden in all subclasses. .. py:method:: __lt__(other) :abstractmethod: Implementation of operator ``<``. Used to produce ranking, being greater means better result. Must be overridden in all subclasses. .. py:method:: __unicode__() :abstractmethod: Returns string representing score, suitable to display to the user. Must be overridden in all subclasses. .. py:method:: _to_repr() :abstractmethod: 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 :meth:`__eq__` and :meth:`__lt__`, it will be used for sorting at db level. .. py:method:: _from_repr(encoded_value) :classmethod: :abstractmethod: Creates an instance based on data from :meth:`_to_repr`. Must be overridden in all subclasses. .. py:class:: IntegerScore(value=0) Bases: :py:obj:`ScoreValue` Score consisting of integer number. Database format: ``"int:"`` Value is padded with zeros to 19 characters. .. py:attribute:: symbol :annotation: = int .. py:method:: __add__(other) 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. .. py:method:: __eq__(other) Implementation of operator ``==``. Used to produce ranking, being greater means better result. Must be overridden in all subclasses. .. py:method:: __lt__(other) Implementation of operator ``<``. Used to produce ranking, being greater means better result. Must be overridden in all subclasses. .. py:method:: __str__() Return str(self). .. py:method:: __unicode__() Returns string representing score, suitable to display to the user. Must be overridden in all subclasses. .. py:method:: __repr__() Return repr(self). .. py:method:: _from_repr(value) :classmethod: Creates an instance based on data from :meth:`_to_repr`. Must be overridden in all subclasses. .. py:method:: _to_repr() 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 :meth:`__eq__` and :meth:`__lt__`, it will be used for sorting at db level. .. py:method:: to_int()