示例#1
0
文件: game.py 项目: fizzix/Webolith
 def createChallengeLeaderboardEntries(self, state, tablenum):
     # first create a leaderboard if one doesn't exist for this challenge
     try:
         dc = DailyChallenge.objects.get(pk=state['challengeId'])
     except:
         return  # this shouldn't happen
     try:
         lb = DailyChallengeLeaderboard.objects.get(challenge=dc)
     except:
         # doesn't exist
         lb = DailyChallengeLeaderboard(challenge=dc, maxScore=state['numAnswersThisRound'])
         lb.save()
     wgm = WordwallsGameModel.objects.get(pk=tablenum)
     # now create an entry; if one exists, don't modify it, just return
     
     try:
         lbe = DailyChallengeLeaderboardEntry.objects.get(user=wgm.host, board=lb)
         # if it exists, we're here
         return  # TODO is there a cleaner way of doing this? this seems very ugly
         
     except DailyChallengeLeaderboardEntry.DoesNotExist:
         score = state['numAnswersThisRound'] - len(state['answerHash'])
         if 'timeRemaining' in state:
             timeRemaining = int(round(state['timeRemaining']))   # if there was time remaining, it would get written into the state
                                                             # inside the guess processing function
         else:
             timeRemaining = 0                               # else, nothing would write it into the state
         lbe = DailyChallengeLeaderboardEntry(user=wgm.host, score=score, board=lb, 
                                 timeRemaining=timeRemaining)
         lbe.save()
示例#2
0
    def create_challenge_leaderboard_entry(self, state, tablenum):
        """
        Create a challenge leaderboard entry for this particular game
        state and table number.

        """
        # First create a leaderboard if one doesn't exist for this challenge.
        try:
            dc = DailyChallenge.objects.get(pk=state["challengeId"])
        except DailyChallenge.DoesNotExist:
            return  # this shouldn't happen
        try:
            lb = DailyChallengeLeaderboard.objects.get(challenge=dc)
        except DailyChallengeLeaderboard.DoesNotExist:
            # doesn't exist
            lb = DailyChallengeLeaderboard(
                challenge=dc, maxScore=state["numAnswersThisRound"])
            # XXX: 500 here, integrity error, very rare.
            lb.save()
        wgm = WordwallsGameModel.objects.get(pk=tablenum)
        # Now create an entry; if one exists, don't modify it, just return.

        try:
            lbe = DailyChallengeLeaderboardEntry.objects.get(user=wgm.host,
                                                             board=lb)
            # If it exists, we're here. don't update the leaderboard
            # entry because we can only do the quiz once.
            return

        except DailyChallengeLeaderboardEntry.DoesNotExist:
            score = state["numAnswersThisRound"] - len(state["answerHash"])
            if "timeRemaining" in state:
                timeRemaining = int(round(state["timeRemaining"]))
                # If there was time remaining, it would get written into the
                # state inside the guess processing function.
            else:
                # Else, nothing would write it into the state.
                timeRemaining = 0
            qualify_for_award = state.get("qualifyForAward", False)
            wrong_answers = state.get("wrongAnswers", 0)
            lbe = DailyChallengeLeaderboardEntry(
                user=wgm.host,
                score=score,
                board=lb,
                wrong_answers=wrong_answers,
                timeRemaining=timeRemaining,
                qualifyForAward=qualify_for_award,
            )
            # XXX: 500 here, integrity error, much more common than lb.save
            lbe.save()
            if len(state["answerHash"]) > 0 and dc.name.name in (
                    "Today's 7s",
                    "Today's 8s",
            ):
                # if the user missed some 7s or 8s
                self.add_dc_missed_bingos(state, dc, wgm)
示例#3
0
    def createChallengeLeaderboardEntries(self, state, tablenum, wgm):
        # First create a leaderboard if one doesn't exist for this challenge.
        try:
            dc = DailyChallenge.objects.get(pk=state['challengeId'])
        except DailyChallenge.DoesNotExist:
            return  # this shouldn't happen
        try:
            lb = DailyChallengeLeaderboard.objects.get(challenge=dc)
        except DailyChallengeLeaderboard.DoesNotExist:
            # doesn't exist
            lb = DailyChallengeLeaderboard(
                challenge=dc, maxScore=state['numAnswersThisRound'])
            # XXX: 500 here, integrity error, very rare.
            lb.save()
        wgm = WordwallsGameModel.objects.get(pk=tablenum)
        # Now create an entry; if one exists, don't modify it, just return.

        try:
            lbe = DailyChallengeLeaderboardEntry.objects.get(user=wgm.host,
                                                             board=lb)
            # If it exists, we're here. don't update the leaderboard
            # entry because we can only do the quiz once.
            return

        except DailyChallengeLeaderboardEntry.DoesNotExist:
            score = state['numAnswersThisRound'] - len(state['answerHash'])
            if 'timeRemaining' in state:
                timeRemaining = int(round(state['timeRemaining']))
                # If there was time remaining, it would get written into the
                # state inside the guess processing function.
            else:
                # Else, nothing would write it into the state.
                timeRemaining = 0

            if 'qualifyForAward' in state:
                qualifyForAward = state['qualifyForAward']
            else:
                qualifyForAward = False  # i suppose this shouldn't happen

            lbe = DailyChallengeLeaderboardEntry(
                user=wgm.host,
                score=score,
                board=lb,
                timeRemaining=timeRemaining,
                qualifyForAward=qualifyForAward)
            # XXX: 500 here, integrity error, much more common than lb.save
            lbe.save()
            if (len(state['answerHash']) > 0
                    and dc.name.name in ("Today's 7s", "Today's 8s")):
                # if the user missed some 7s or 8s
                self.addDCMissedBingos(state, dc, wgm)
示例#4
0
    def createChallengeLeaderboardEntries(self, state, tablenum, wgm):
        # First create a leaderboard if one doesn't exist for this challenge.
        try:
            dc = DailyChallenge.objects.get(pk=state['challengeId'])
        except DailyChallenge.DoesNotExist:
            return  # this shouldn't happen
        try:
            lb = DailyChallengeLeaderboard.objects.get(challenge=dc)
        except DailyChallengeLeaderboard.DoesNotExist:
            # doesn't exist
            lb = DailyChallengeLeaderboard(
                challenge=dc, maxScore=state['numAnswersThisRound'])
            # XXX: 500 here, integrity error, very rare.
            lb.save()
        wgm = WordwallsGameModel.objects.get(pk=tablenum)
        # Now create an entry; if one exists, don't modify it, just return.

        try:
            lbe = DailyChallengeLeaderboardEntry.objects.get(
                user=wgm.host, board=lb)
            # If it exists, we're here. don't update the leaderboard
            # entry because we can only do the quiz once.
            return

        except DailyChallengeLeaderboardEntry.DoesNotExist:
            score = state['numAnswersThisRound'] - len(state['answerHash'])
            if 'timeRemaining' in state:
                timeRemaining = int(round(state['timeRemaining']))
                # If there was time remaining, it would get written into the
                # state inside the guess processing function.
            else:
                # Else, nothing would write it into the state.
                timeRemaining = 0

            if 'qualifyForAward' in state:
                qualifyForAward = state['qualifyForAward']
            else:
                qualifyForAward = False     # i suppose this shouldn't happen

            lbe = DailyChallengeLeaderboardEntry(
                user=wgm.host, score=score, board=lb,
                timeRemaining=timeRemaining, qualifyForAward=qualifyForAward)
            # XXX: 500 here, integrity error, much more common than lb.save
            lbe.save()
            if (len(state['answerHash']) > 0 and dc.name.name in
                    ("Today's 7s", "Today's 8s")):
                # if the user missed some 7s or 8s
                self.addDCMissedBingos(state, dc, wgm)