summaryrefslogtreecommitdiff
path: root/f1elo/model.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-05-02 15:54:03 +0200
committeremkael <emkael@tlen.pl>2016-05-02 15:54:03 +0200
commit9797bd898f435ba04475ab2e38597e59318474b9 (patch)
tree308c7fe9626947f058a4d20144b7b46708cc64a8 /f1elo/model.py
parent1d4f2c970b29f7870577a74d450e4ecc3113741c (diff)
* results log sorted
Diffstat (limited to 'f1elo/model.py')
-rw-r--r--f1elo/model.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/f1elo/model.py b/f1elo/model.py
index 7cd5e6d..c450353 100644
--- a/f1elo/model.py
+++ b/f1elo/model.py
@@ -3,6 +3,9 @@ from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import backref, relationship, sessionmaker
from sqlalchemy.types import Boolean, Date, Float, Integer, String
+from functools import total_ordering
+import sys
+
Base = declarative_base()
class Country(Base):
@@ -89,6 +92,7 @@ driver_entry = Table('driver_entries', Base.metadata,
Column('id', Integer, primary_key=True))
+@total_ordering
class Entry(Base):
__tablename__ = 'entries'
@@ -117,6 +121,25 @@ class Entry(Base):
def __repr__(self):
return ('#%s (%s) %s[%d]' % (self.car_no, ', '.join([driver.__repr__().decode('utf8') for driver in self.drivers]), self.result, self.result_group)).encode('utf8')
+ def __eq__(self, other):
+ return self.id == other.id
+
+ def __lt__(self, other):
+ try:
+ self_result = int(self.result)
+ except ValueError:
+ self_result = sys.maxint
+ try:
+ other_result = int(other.result)
+ except ValueError:
+ other_result = sys.maxint
+ if self_result == other_result:
+ if self.result_group == other.result_group:
+ return self.id < other.id
+ else:
+ return self.result_group < other.result_group
+ else:
+ return self_result < other_result
class Race(Base):
__tablename__ = 'races'