示例#1
0
    def get(self):
        logging.info('Home page requested')

        results = memcache.get('popular')

        if results is None:
            results = Achievement.query().order(
                -Achievement.numLiked,
                -Achievement.score).fetch(10)
            memcache.add('popular', results, time=60)

        self.template_values['achievements'] = results

        contribStats = memcache.get('contribStats')
        if contribStats is None:
            query = LeaderboardStats.query()
            query = query.filter(LeaderboardStats.statType == 'contribution')
            query = query.order(-LeaderboardStats.value)
            contribStats = query.fetch()

            memcache.add('contribStats', contribStats)

        self.template_values['contribStats'] = contribStats

        scoreStats = memcache.get('scoreStats')
        if scoreStats is None:
            query = LeaderboardStats.query()
            query = query.filter(LeaderboardStats.statType == 'score')
            query = query.order(-LeaderboardStats.value)
            scoreStats = query.fetch()

            memcache.add('scoreStats', scoreStats)

        self.template_values['scoreStats'] = scoreStats

        systemStats = memcache.get('systemStats')
        self.template_values['systemStats'] = systemStats

        template = jinja.get_template('home.html')
        self.response.out.write(template.render(self.template_values))
示例#2
0
    def get(self):
        logging.info('Generate LeaderboardStats')

        cheevers = Cheever.query().order(-Cheever.numScore).fetch(10)
        for pos in range(0, cheevers.__len__()):
            leaderboardPos_key = ndb.Key('LeaderboardStats', str(pos) + 's')
            leaderboardPos = leaderboardPos_key.get()
            if not leaderboardPos:
                leaderboardPos = LeaderboardStats(key=leaderboardPos_key)

            leaderboardPos.populate(
                username=cheevers[pos].username,
                statType='score',
                value=cheevers[pos].numScore
            )
            leaderboardPos.put()

        cheevers = Cheever.query().order(-Cheever.numContribs).fetch(10)
        for pos in range(0, cheevers.__len__()):
            leaderboardPos_key = ndb.Key('LeaderboardStats', str(pos) + 'st')
            leaderboardPos = leaderboardPos_key.get()
            if not leaderboardPos:
                leaderboardPos = LeaderboardStats(key=leaderboardPos_key)

            leaderboardPos.populate(
                username=cheevers[pos].username,
                statType='contribution',
                value=cheevers[pos].numContribs
            )

            leaderboardPos.put()

        memcache.delete('contribStats')
        memcache.delete('scoreStats')