<commit_before>#!/usr/bin/env python3


import api
import api.group
import api.stats


def run():
    """Run the stat caching daemon."""
    with api.create_app().app_context():
        def cache(f, *args, **kwargs):
            result = f(reset_cache=True, *args, **kwargs)
            return result

        print("Caching registration stats.")
        cache(api.stats.get_registration_count)

        print("Caching the public scoreboard entries...")
        cache(api.stats.get_all_team_scores)
        cache(api.stats.get_all_team_scores, include_ineligible=True)

        print("Caching the public scoreboard graph...")
        cache(api.stats.get_top_teams_score_progressions)
        cache(api.stats.get_top_teams_score_progressions,
              include_ineligible=True)

        print("Caching the scoreboard graph for each group...")
        for group in api.group.get_all_groups():
            # cache(
            #      api.stats.get_top_teams_score_progressions,
            #      gid=group['gid'])
            cache(
                  api.stats.get_top_teams_score_progressions,
                  gid=group['gid'],
                  include_ineligible=True)
            cache(api.stats.get_group_scores, gid=group['gid'])

        print("Caching number of solves for each problem.")
        for problem in api.problem.get_all_problems():
            print(problem["name"],
                  cache(api.stats.get_problem_solves, problem["pid"]))


if __name__ == '__main__':
    run()
<commit_msg>Update stats daemon to update ZSets and memoization as necessary<commit_after>#!/usr/bin/env python3


import api
import api.group
from api.stats import (get_all_team_scores, get_group_scores,
                       get_problem_solves, get_registration_count,
                       get_top_teams_score_progressions)


def run():
    """Run the stat caching daemon."""
    with api.create_app().app_context():
        def cache(f, *args, **kwargs):
            result = f(reset_cache=True, *args, **kwargs)
            return result

        print("Caching registration stats.")
        cache(get_registration_count)

        print("Caching the public scoreboard entries...")
        get_all_team_scores()
        get_all_team_scores(include_ineligible=True)

        print("Caching the public scoreboard graph...")
        cache(get_top_teams_score_progressions)
        cache(get_top_teams_score_progressions, include_ineligible=True)

        print("Caching the scoreboard graph for each group...")
        for group in api.group.get_all_groups():
            get_group_scores(gid=group['gid'])
            cache(get_top_teams_score_progressions,
                  gid=group['gid'],
                  include_ineligible=True)

        print("Caching number of solves for each problem.")
        for problem in api.problem.get_all_problems():
            print(problem["name"],
                  cache(get_problem_solves, problem["pid"]))


if __name__ == '__main__':
    run()

{'fraction_non_alphanumeric': 0.10324089542265286, 'fraction_numerical': 0.0006682258603407952, 'mean_word_length': 2.4935822637106186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5917737', 'n_tokens_mistral': 906, 'n_tokens_neox': 845, 'n_words': 179}