示例#1
0
def __attribute_sway_points_for_user(current_question, user):
    # At least one vote on current question
    if len(user.votes) > 0 \
            and user.votes[-1].question.id() == current_question.key.id():
        user.sway_points += sway_points["submit_answer"]

        # Voted for winning party
        state = State.get_state_by_abbreviation(\
                    user.votes[-1].state_abbreviation)
        last_winning_party = 1 if current_question.college_score[1] > \
                             current_question.college_score[0] else 0

        # Voted on party that won last question
        if user.votes[-1].party == last_winning_party:
            user.votes[-1].winning_vote = True
            user.sway_points += sway_points["submit_winning_answer"]
            # Voted for winning party twice in a row
            if len(user.votes) == 2 and user.votes[-2].winning_vote == True:
                user.sway_points += sway_points["streak_bonus"]
            # Return used sway points
            user.sway_points += int(user.votes[-1].sway_points * \
                                    sway_points["refund"])
        else:
            user.votes[-1].winning_vote = False

        # Update user in database
        user.put()
示例#2
0
def __attribute_sway_points_for_user(current_question, user):
    # At least one vote on current question
    if len(user.votes) > 0 \
            and user.votes[-1].question.id() == current_question.key.id():
        user.sway_points += sway_points["submit_answer"]
        
        # Voted for winning party
        state = State.get_state_by_abbreviation(\
                    user.votes[-1].state_abbreviation)
        last_winning_party = 1 if current_question.college_score[1] > \
                             current_question.college_score[0] else 0

        # Voted on party that won last question
        if user.votes[-1].party == last_winning_party:
            user.votes[-1].winning_vote = True
            user.sway_points += sway_points["submit_winning_answer"]
             # Voted for winning party twice in a row
            if len(user.votes) == 2 and user.votes[-2].winning_vote == True:
                user.sway_points += sway_points["streak_bonus"]
            # Return used sway points
            user.sway_points += int(user.votes[-1].sway_points * \
                                    sway_points["refund"])
        else:
            user.votes[-1].winning_vote = False

        # Update user in database
        user.put()
示例#3
0
    def test_model_state(self):
        # Load fixtures
        load_fixture('tests/states.json', kind={'State': State})
        load_fixture('tests/questions.json',
                     kind={
                         'Question': Question,
                         'State': State
                     })

        question_entity = Question.get_current_question()
        State.update_state_scores_for_completed_question(question_entity)

        state_entity = State.get_state_by_abbreviation("CA")
        assert state_entity.party_score_votes[0] == 0
        assert state_entity.party_score_votes[1] == 1
        assert state_entity.party_score_sway[0] == 5
        assert state_entity.party_score_sway[1] == 500
        assert state_entity.last_winning_party == 1

        state_entity = State.get_state_by_abbreviation("WA")
        assert state_entity.party_score_votes[0] == 0
        assert state_entity.party_score_votes[1] == 1
        assert state_entity.party_score_sway[0] == 50
        assert state_entity.party_score_sway[1] == 100
        assert state_entity.last_winning_party == 1

        # Random winner is allocated for state drawing
        state_entity = State.get_state_by_abbreviation("TX")
        assert state_entity.party_score_votes[0] == 1 or \
               state_entity.party_score_votes[1] == 1
        assert state_entity.party_score_sway[0] == 80
        assert state_entity.party_score_sway[1] == 70
        assert state_entity.last_winning_party != None

        # What happens when state hasn't been voted on?
        state_entity = State.get_state_by_abbreviation("NY")
        assert state_entity.party_score_votes[0] == 0 or \
               state_entity.party_score_votes[1] == 0
        assert state_entity.last_winning_party != None

        assert State.is_valid_state("CA") == True
        assert State.is_valid_state("WA") == True
        assert State.is_valid_state("INVALID") == False
示例#4
0
    def test_model_state(self):
        # Load fixtures
        load_fixture('tests/states.json', kind={'State': State})
        load_fixture('tests/questions.json', 
                        kind={'Question': Question,'State': State})

        question_entity = Question.get_current_question()
        State.update_state_scores_for_completed_question(question_entity)

        state_entity = State.get_state_by_abbreviation("CA")
        assert state_entity.party_score_votes[0] == 0
        assert state_entity.party_score_votes[1] == 1
        assert state_entity.party_score_sway[0] == 5
        assert state_entity.party_score_sway[1] == 500
        assert state_entity.last_winning_party == 1

        state_entity = State.get_state_by_abbreviation("WA")
        assert state_entity.party_score_votes[0] == 0
        assert state_entity.party_score_votes[1] == 1
        assert state_entity.party_score_sway[0] == 50
        assert state_entity.party_score_sway[1] == 100
        assert state_entity.last_winning_party == 1

        # Random winner is allocated for state drawing
        state_entity = State.get_state_by_abbreviation("TX")
        assert state_entity.party_score_votes[0] == 1 or \
               state_entity.party_score_votes[1] == 1
        assert state_entity.party_score_sway[0] == 80
        assert state_entity.party_score_sway[1] == 70
        assert state_entity.last_winning_party != None

        # What happens when state hasn't been voted on?
        state_entity = State.get_state_by_abbreviation("NY")
        assert state_entity.party_score_votes[0] == 0 or \
               state_entity.party_score_votes[1] == 0
        assert state_entity.last_winning_party != None

        assert State.is_valid_state("CA") == True
        assert State.is_valid_state("WA") == True
        assert State.is_valid_state("INVALID") == False