Source code for oioioi.mp.score

from functools import total_ordering

from oioioi.contests.scores import ScoreValue


@total_ordering
[docs]class FloatScore(ScoreValue):
[docs] symbol = 'float'
def __init__(self, value): assert isinstance(value, float) or isinstance(value, int) self.value = float(value)
[docs] def __add__(self, other): if not isinstance(other, FloatScore): return FloatScore(self.value + other) return FloatScore(self.value + other.value)
[docs] def __mul__(self, other): if not isinstance(other, FloatScore): return FloatScore(self.value * other) return FloatScore(self.value * other.value)
[docs] __rmul__ = __mul__
[docs] def __eq__(self, other): if not isinstance(other, FloatScore): return self.value == other return self.value == other.value
[docs] def __lt__(self, other): if not isinstance(other, FloatScore): return self.value < other return self.value < other.value
[docs] def __str__(self): return str(self.value)
[docs] def __unicode__(self): return str(self.value)
[docs] def __repr__(self): return "FloatScore(%s)" % (self.value,)
@classmethod
[docs] def _from_repr(cls, value): return cls(float(value))
[docs] def _to_repr(self): return '%017.2f' % self.value
[docs] def to_int(self): return int(self.value)