예제 #1
0
def get_rankings():
    rankings = []

    players = SiteUser.all()
    for player in players:

        wins = 0
        losses = 0
        for x in player.games:
            if x.game.game_state == 'complete':
                if x.is_winner:
                    wins += 1
                else:
                    losses += 1

        win_average = wins / (wins + losses) if (wins + losses) != 0 else 0

        rankings.append((player.username, wins, losses, win_average))

    # Sort by wins. If equal, breka ties with win frequency.
    # Sort by losses if both are equal (people with more
    # experience are ranked higher)
    rankings.sort(key=lambda tuple: (tuple[1], tuple[3], tuple[2]),
                  reverse=True)

    return rankings
예제 #2
0
def get_rankings():
    rankings = []

    players = SiteUser.all()
    for player in players:

        wins = 0
        losses = 0
        for x in player.games:
            if x.game.game_state == 'complete':
                if x.is_winner:
                    wins += 1
                else:
                    losses += 1

        win_average = wins / (wins + losses) if (wins + losses) != 0 else 0

        rankings.append((player.username, wins, losses, win_average))

    # Sort by wins. If equal, breka ties with win frequency.
    # Sort by losses if both are equal (people with more
    # experience are ranked higher)
    rankings.sort(
        key=lambda tuple: (tuple[1], tuple[3], tuple[2]), reverse=True)

    return rankings
예제 #3
0
    def get(self):
        """Send a reminder email to each User with an email about games.
        Called every hour using a cron job"""

        app_id = app_identity.get_application_id()
        users = SiteUser.all()

        num_created = 1

        for user in users:
            if user.email is not None and user.email != "":
                for usergame in user.games:

                    should_send_email = False

                    subject = ""
                    body = ""

                    username = user.username
                    gamename = usergame.game.game_name

                    if usergame.game.game_state == "created":
                        should_send_email = True
                        subject = ("Reminder: You haven't started playing" +
                                   " your snakes and ladders game! " +
                                   str(num_created))
                        body = ("Hi there " + username + ". Please view your" +
                                " game " + gamename + " and get some people " +
                                "playing.")

                    elif (usergame.game.game_state == "playing" and
                          (usergame.player_num ==
                           usergame.game.current_player_num)):
                        should_send_email = True
                        subject = ("Reminder: Keep playing snakes and" +
                                   " ladders! You have an unfinished game. " +
                                   str(num_created))
                        body = ("Hi there " + username + ". Please view your" +
                                " game " + gamename + " and play your turn.")

                    if should_send_email:
                        num_created += 1
                        # This will send test emails:
                        # from, to, subject, body
                        mail.send_mail(
                            'noreply@{}.appspotmail.com'.format(app_id),
                            user.email,
                            subject,
                            body)

        self.response.set_status(204)
예제 #4
0
    def get(self):
        """Send a reminder email to each User with an email about games.
        Called every hour using a cron job"""

        app_id = app_identity.get_application_id()
        users = SiteUser.all()

        num_created = 1

        for user in users:
            if user.email is not None and user.email != "":
                for usergame in user.games:

                    should_send_email = False

                    subject = ""
                    body = ""

                    username = user.username
                    gamename = usergame.game.game_name

                    if usergame.game.game_state == "created":
                        should_send_email = True
                        subject = ("Reminder: You haven't started playing" +
                                   " your snakes and ladders game! " +
                                   str(num_created))
                        body = ("Hi there " + username + ". Please view your" +
                                " game " + gamename + " and get some people " +
                                "playing.")

                    elif (usergame.game.game_state == "playing"
                          and (usergame.player_num
                               == usergame.game.current_player_num)):
                        should_send_email = True
                        subject = ("Reminder: Keep playing snakes and" +
                                   " ladders! You have an unfinished game. " +
                                   str(num_created))
                        body = ("Hi there " + username + ". Please view your" +
                                " game " + gamename + " and play your turn.")

                    if should_send_email:
                        num_created += 1
                        # This will send test emails:
                        # from, to, subject, body
                        mail.send_mail(
                            'noreply@{}.appspotmail.com'.format(app_id),
                            user.email, subject, body)

        self.response.set_status(204)
예제 #5
0
    def post(self):
        delete_users, delete_posts = self.getThese("delete_users",
                                                   "delete_posts")

        if delete_users is not None:
            users = SiteUser.all()
            for user in users:
                user.delete()

        if delete_posts is not None:
            posts = BlogPost.all()
            print "Post is", posts
            for one_post in posts:
                one_post.delete()

        self.render("admin.html", True)
예제 #6
0
    def post(self):
        delete_users, delete_posts = self.getThese(
            "delete_users",
            "delete_posts")

        if delete_users is not None:
            users = SiteUser.all()
            for user in users:
                user.delete()

        if delete_posts is not None:
            posts = BlogPost.all()
            print "Post is", posts
            for one_post in posts:
                one_post.delete()

        self.render("admin.html", True)