def generate_leaders(*, leader_factory=None):
"""Creates a generator for the leaderboard.
Generates a 4-tuple containing the ranking, score, user object, and
registration information of the leader. The result is a namedtuple.
"""
if leader_factory is None:
leader_factory = Leader
cursor = db.get_cursor()
cursor.execute("""
SELECT "serial", "score"
FROM "user"
ORDER BY "score" DESC
""")
for ranking, (serial, score) in enumerate(cursor, 1):
user = User(serial=serial)
registration = registrations.get_registration(serial=serial)
yield leader_factory(
ranking=ranking, score=score,
user=user, registration=registration,
)
评论列表
文章目录