Exemple #1
0
 def get_user_rankings(self, request):
     """Returns user rankings in descending order"""
     users = User.query().order(-User.performance).fetch()
     return RankingForms(
             items=[RankingForm(username=user.username,
                                performance=user.performance)
                    for user in users])
Exemple #2
0
    def get_high_scores(self, request):
        """Get high scores"""

        # Sor rankings and return the first number_of_results rankings2
        results = self.sort_rankings(self.determine_rankings()) \
                  [0:request.number_of_results]

        return RankingForms(rankings=results)
Exemple #3
0
    def get_user_rankings(self, request):
        """ get user rankings """
        q = User.query()
        q = q.order(-User.wins)

        rankings = []
        for u in q:
            rankings.append(RankingForm(user_name=u.name, wins=u.wins))
        return RankingForms(user_rankings=rankings)
Exemple #4
0
 def get_user_rankings(self, request):
     """Returns rankings of players, all or up to number_of_results"""
     users = User.query()
     if not users:
         raise endpoints.NotFoundException('No users in the database yet!')
     rankings = []
     rankings = rank_them(users=users,
                          number_of_results=request.number_of_results)
     return RankingForms(items=[ranking.to_form() for ranking in rankings])
Exemple #5
0
 def get_user_rankings(self, request):
     """Returns a list of the top players"""
     number_of_results = request.top
     # users = User.query().order(-User.wins).fetch(number_of_results, offset=0)
     # listed = []
     # for user in users:
     #     listed.append(user)
     # return JSONMessage(message="{}".format(listed))
     return RankingForms(items=[
         user.to_rankform()
         for user in User.query().order(-User.wins).fetch(number_of_results,
                                                          offset=0)
     ])
Exemple #6
0
    def get_user_rankings(self, request):
        # get ratio and save to each user.
        users = User.query()
        for user in users:
            scores = Score.query(Score.user == user.key).fetch()
            if scores:
                for score in scores:
                    if score.won == True:
                        user.wons += 1
                    else:
                        user.losts += 1
            user.put()

        return RankingForms(
            items=[user.to_rankingform() for user in User.query()])
Exemple #7
0
 def get_rankings(self, request):
     """Return the rankings. The order is based on the winning percentage and
      the average score of the user."""
     users = User.query().order(-User.winning_percentage).fetch()
     rankings_list = []
     for user in users:
         user_name = user.name
         winning_percentage = user.winning_percentage
         user_scores = Score.query(Score.user == user.key).fetch()
         if len(user_scores) == 0:
             average_score = 0.0
         else:
             sum_user_scores = sum([score.score for score in user_scores])
             print(sum_user_scores)
             average_score = sum_user_scores / float(len(user_scores))
         rankings_list.append(RankingForm(user_name=user_name,
                                      winning_percentage=winning_percentage,
                                      average_score=average_score))
     sorted(rankings_list, key=lambda x: (-x.winning_percentage,
                                          x.average_score))
     return RankingForms(items=rankings_list)
Exemple #8
0
 def get_user_rankings(self, request):
     """Returns Players in descending order. The one with
     most wins is on the top"""
     rankings = Ranking.query().order(-Ranking.number_of_wins).fetch()
     return RankingForms(items=[ranking.to_form() for ranking in rankings])
Exemple #9
0
    def get_rankings(self, request):
        """Get all user rankings"""

        return RankingForms(rankings=self.determine_rankings())