#!/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()

@@ -50,24 +50,193 @@
 oup%0A
-import api.
+from api.stats import (get_all_team_scores, get_group_scores,%0A                       get_problem_solves, get_regi
 st
+r
 at
-s
+ion_count,%0A                       get_top_teams_score_progressions)
 %0A%0A%0Ad
@@ -504,34 +504,24 @@
       cache(
-api.stats.
 get_registra
@@ -599,32 +599,16 @@
         
-cache(api.stats.
 get_all_
@@ -618,16 +618,17 @@
 m_scores
+(
 )%0A      
@@ -629,32 +629,16 @@
         
-cache(api.stats.
 get_all_
@@ -648,18 +648,17 @@
 m_scores
-, 
+(
 include_
@@ -741,34 +741,24 @@
       cache(
-api.stats.
 get_top_team
@@ -789,34 +789,24 @@
       cache(
-api.stats.
 get_top_team
@@ -826,30 +826,16 @@
 essions,
-%0A             
  include
@@ -982,99 +982,25 @@
     
-# cache(%0A            #      api.stats.get_top_teams_score_progressions,%0A            #      
+get_group_scores(
 gid=
@@ -1035,37 +1035,8 @@
 che(
-%0A                  api.stats.
 get_
@@ -1147,72 +1147,8 @@
 rue)
-%0A            cache(api.stats.get_group_scores, gid=group%5B'gid'%5D)
 %0A%0A  
@@ -1323,18 +1323,8 @@
 che(
-api.stats.
 get_

Update stats daemon to update ZSets and memoization as necessary