<commit_before>""" Module for getting scoreboard information """

import api

from api.common import cache, APIException
from datetime import datetime, timezone

_get_problem_names = lambda problems: [problem['name'] for problem in problems]

end = datetime(2020, 5, 7, 3, 59, 59)

@api.cache.memoize()
def get_score(tid=None, uid=None):
    """
    Get the score for a user or team.

    Args:
        tid: The team id
        uid: The user id
    Returns:
        The users's or team's score
    """

    score = sum([problem['score'] for problem in api.problem.get_solved_problems(tid=tid, uid=uid)])

    return score

def get_group_scores(gid=None, name=None):
    """
    Get the group scores.

    Args:
        gid: The group id
        name: The group name
    Returns:
        A dictionary of tid:score mappings
    """

    members = [api.team.get_team(tid=tid) for tid in api.group.get_group(gid, name)['members']]

    result = []
    for team in members:
        result.append({
            "name": team['team_name'],
            "score": get_score(tid=team['tid'])
        })

    return sorted(result, key=lambda entry: entry['score'], reverse=True)

def get_group_average_score(gid=None, name=None):
    """
    Get the average score of teams in a group.

    Args:
        gid: The group id
        name: The group name
    Returns:
        The total score of the group
    """

    group_scores = get_group_scores(gid=gid, name=name)
    total_score = sum([entry['score'] for entry in group_scores])
    return int(total_score / len(group_scores)) if len(group_scores) > 0 else 0

@api.cache.memoize()
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()

    result = []
    for team in teams:
        result.append({
            "name": team['team_name'],
            "score": get_score(tid=team['tid'])
        })

    return sorted(result, key=lambda entry: entry['score'], reverse=True)

def get_all_user_scores():
    """
    Gets the score for every user in the database.

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

    users = api.user.get_all_users()

    result = []
    for user in users:
        result.append({
            "name": user['username'],
            "score": get_score(uid=user['uid'])
        })

    return sorted(result, key=lambda entry: entry['score'], reverse=True)

@api.cache.memoize(timeout=120, fast=True)
def get_problems_by_category():
    """
    Gets the list of all problems divided into categories

    Returns:
        A dictionary of category:[problem list]
    """

    result = {cat: _get_problem_names(api.problem.get_all_problems(category=cat))
                            for cat in api.problem.get_all_categories()}

    return result

def get_team_member_stats(tid):
    members = api.team.get_team_members(tid=tid)

    return {member['username']: _get_problem_names(api.problem.get_solved_problems(uid=member['uid']))}

def get_score_over_time(uid=None, tid=None, category=None):
    """
    Finds the score and time after each correct submission of a team or user.
    NOTE: this is slower than get_score. Do not use this for getting current score.

    Args:
        uid: the uid of the user
        tid: the tid of the user
        category: category filter
    Returns:
        A list of dictionaries containing score and time
    """

    correct_submissions = api.problem.get_submissions(uid=uid, tid=tid, category=category, correctness=True)

    result = []
    score = 0

    for submission in sorted(correct_submissions, key=lambda sub: sub["timestamp"]):
        score += api.problem.get_problem(pid=submission["pid"])["score"]
        result.append({
            "score": score,
            "time": int(submission["timestamp"].replace(tzinfo=timezone.utc).timestamp())
        })

    return result<commit_msg>get member information was only returning information for a single member<commit_after>""" Module for getting scoreboard information """

import api

from api.common import cache, APIException
from datetime import datetime, timezone

_get_problem_names = lambda problems: [problem['name'] for problem in problems]

end = datetime(2020, 5, 7, 3, 59, 59)

@api.cache.memoize()
def get_score(tid=None, uid=None):
    """
    Get the score for a user or team.

    Args:
        tid: The team id
        uid: The user id
    Returns:
        The users's or team's score
    """

    score = sum([problem['score'] for problem in api.problem.get_solved_problems(tid=tid, uid=uid)])

    return score

def get_group_scores(gid=None, name=None):
    """
    Get the group scores.

    Args:
        gid: The group id
        name: The group name
    Returns:
        A dictionary of tid:score mappings
    """

    members = [api.team.get_team(tid=tid) for tid in api.group.get_group(gid, name)['members']]

    result = []
    for team in members:
        result.append({
            "name": team['team_name'],
            "score": get_score(tid=team['tid'])
        })

    return sorted(result, key=lambda entry: entry['score'], reverse=True)

def get_group_average_score(gid=None, name=None):
    """
    Get the average score of teams in a group.

    Args:
        gid: The group id
        name: The group name
    Returns:
        The total score of the group
    """

    group_scores = get_group_scores(gid=gid, name=name)
    total_score = sum([entry['score'] for entry in group_scores])
    return int(total_score / len(group_scores)) if len(group_scores) > 0 else 0

@api.cache.memoize()
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()

    result = []
    for team in teams:
        result.append({
            "name": team['team_name'],
            "score": get_score(tid=team['tid'])
        })

    return sorted(result, key=lambda entry: entry['score'], reverse=True)

def get_all_user_scores():
    """
    Gets the score for every user in the database.

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

    users = api.user.get_all_users()

    result = []
    for user in users:
        result.append({
            "name": user['username'],
            "score": get_score(uid=user['uid'])
        })

    return sorted(result, key=lambda entry: entry['score'], reverse=True)

@api.cache.memoize(timeout=120, fast=True)
def get_problems_by_category():
    """
    Gets the list of all problems divided into categories

    Returns:
        A dictionary of category:[problem list]
    """

    result = {cat: _get_problem_names(api.problem.get_all_problems(category=cat))
                            for cat in api.problem.get_all_categories()}

    return result

def get_team_member_stats(tid):
    members = api.team.get_team_members(tid=tid)

    return {member['username']: _get_problem_names(api.problem.get_solved_problems(uid=member['uid'])) for member in members}

def get_score_over_time(uid=None, tid=None, category=None):
    """
    Finds the score and time after each correct submission of a team or user.
    NOTE: this is slower than get_score. Do not use this for getting current score.

    Args:
        uid: the uid of the user
        tid: the tid of the user
        category: category filter
    Returns:
        A list of dictionaries containing score and time
    """

    correct_submissions = api.problem.get_submissions(uid=uid, tid=tid, category=category, correctness=True)

    result = []
    score = 0

    for submission in sorted(correct_submissions, key=lambda sub: sub["timestamp"]):
        score += api.problem.get_problem(pid=submission["pid"])["score"]
        result.append({
            "score": score,
            "time": int(submission["timestamp"].replace(tzinfo=timezone.utc).timestamp())
        })

    return result
{'fraction_non_alphanumeric': 0.1115547791365111, 'fraction_numerical': 0.004242575492887447, 'mean_word_length': 2.8404408241494967, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5602347', 'n_tokens_mistral': 2511, 'n_tokens_neox': 2350, 'n_words': 717}