stats.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:xgovctf 作者: alphagov 项目源码 文件源码
def get_all_team_scores():
    """
    Gets the score for every team in the database.

    Returns:
        A list of dictionaries with name and score
    """

    teams = api.team.get_all_teams()
    db = api.api.common.get_conn()

    result = []
    for team in teams:
        team_query = db.submissions.find({'tid': team['tid'], 'eligible': True, 'correct': True})
        if team_query.count() > 0:
            lastsubmit = team_query.sort('timestamp', direction=pymongo.DESCENDING)[0]['timestamp']
        else:
            lastsubmit = datetime.datetime.now()
        score = get_score(tid=team['tid'])
        if score > 0:
            result.append({
                "name": team['team_name'],
                "tid": team['tid'],
                "school": team["school"],
                "score": score,
                "lastsubmit": lastsubmit
            })
    time_ordered = sorted(result, key=lambda entry: entry['lastsubmit'])
    time_ordered_time_removed = [{'name': x['name'], 'tid': x['tid'], 'school': x['school'], 'score': x['score']} for x in time_ordered]
    return sorted(time_ordered_time_removed, key=lambda entry: entry['score'], reverse=True)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号