mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 14:34:21 +01:00
Fixing score and place for team pages
This commit is contained in:
@@ -111,18 +111,23 @@ class Teams(db.Model):
|
|||||||
|
|
||||||
def score(self):
|
def score(self):
|
||||||
score = db.func.sum(Challenges.value).label('score')
|
score = db.func.sum(Challenges.value).label('score')
|
||||||
stuff = db.session.query(Solves.teamid, score).join(Teams).join(Challenges).filter(Teams.banned == None, Teams.id==self.id).group_by(Solves.teamid).one()
|
team = db.session.query(Solves.teamid, score).join(Teams).join(Challenges).filter(Teams.banned == None, Teams.id==self.id).group_by(Solves.teamid).first()
|
||||||
print stuff
|
if team:
|
||||||
return stuff[1] if stuff[1] else 0
|
return team.score
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
def place(self):
|
def place(self):
|
||||||
score = db.func.sum(Challenges.value).label('score')
|
score = db.func.sum(Challenges.value).label('score')
|
||||||
quickest = db.func.max(Solves.date).label('quickest')
|
quickest = db.func.max(Solves.date).label('quickest')
|
||||||
teams = db.session.query(Solves.teamid).join(Teams).join(Challenges).filter(Teams.banned == None).group_by(Solves.teamid).order_by(score.desc(), quickest).all()
|
teams = db.session.query(Solves.teamid).join(Teams).join(Challenges).filter(Teams.banned == None).group_by(Solves.teamid).order_by(score.desc(), quickest).all()
|
||||||
#http://codegolf.stackexchange.com/a/4712
|
#http://codegolf.stackexchange.com/a/4712
|
||||||
i = teams.index((self.id,)) + 1
|
try:
|
||||||
k = i%10
|
i = teams.index((self.id,)) + 1
|
||||||
return "%d%s"%(i,"tsnrhtdd"[(i/10%10!=1)*(k<4)*k::4])
|
k = i % 10
|
||||||
|
return "%d%s" % (i, "tsnrhtdd"[(i / 10 % 10 != 1) * (k < 4) * k::4])
|
||||||
|
except ValueError:
|
||||||
|
return 0
|
||||||
|
|
||||||
class Solves(db.Model):
|
class Solves(db.Model):
|
||||||
__table_args__ = (db.UniqueConstraint('chalid', 'teamid'), {})
|
__table_args__ = (db.UniqueConstraint('chalid', 'teamid'), {})
|
||||||
|
|||||||
Reference in New Issue
Block a user