Пример #1
0
    def add_vote_for_question(self, party, sway_points, state_abbreviation,
                              question):
        # Add vote for question
        # @TODO: could optimize to O(1) by pre-populating states
        states = question.state_scores
        for state in states:
            if state.state_abbreviation == state_abbreviation:
                state.party_score_votes[party] += 1
                state.party_score_sway[party] += sway_points
                question.put()
                return

        # State had no votes previously
        states.append(
            State(
                state_abbreviation = state_abbreviation,
                college_votes = self.get_college_votes_for_state_abbreviation( \
                    state_abbreviation),
                party_score_votes = [0, 0],
                party_score_sway = [0, 0]
            )
        )

        states[-1].party_score_votes[party] += 1
        states[-1].party_score_sway[party] += sway_points

        # Increment question vote count
        question.vote_count += 1
        question.put()
Пример #2
0
 def load_states(self):
     # Load states
     logging.info('load_states:')
     states = self.bootstrap_json["states"]
     for state in states:
         state = State(state_abbreviation=state["state_abbreviation"],
                       college_votes=int(state["college_votes"]),
                       party_score_votes=[0, 0],
                       party_score_sway=[0, 0])
         state.put()