Example #1
0
 def GET(self):
     clist = memcache.get("clist")
     if clist is None:
         clist = sorted(Challenge.all(), key=lambda c: len(c.active_golfers), reverse=1)
         memcache.set("clist", clist)
     render = web.template.render("templates")
     return render.index(clist)
Example #2
0
 def POST(self):
     """Update Golfer table from Challenge data."""
     logging.info('top()')
     challenges = list(Challenge.all())
     logging.info('gathering active golfers')
     handles = set(h for c in challenges for h in c.active_golfers)
     ranksum = sum(len(c.active_golfers) for c in challenges)
     golfers = dict((h, Golfer(key_name='@'+h, handle=h, global_rank=ranksum))
                    for h in handles)
     logging.info('global rank sum %d' % ranksum)
     logging.info('calculating global rank for each golfer')
     for c in challenges:
         n = len(c.active_golfers)
         for i, h in enumerate(c.active_golfers):
             golfers[h].global_rank -= n - i - 1
     logging.info('calculating rank for each golfer')
     glist = golfers.values()
     db.put(glist)
     logging.info('done updating golfer ranking')
Example #3
0
def json_challenges():
    return json.dumps(dict(
        (c.handle, {
            'title':c.title,
            'active_golfers':len(c.active_golfers),
        }) for c in Challenge.all()))