Example #1
0
def match_stances(member, bill, side):
    """This function filters the member's stances by the stances that are
    implied by voting for a given side of a bill. In other words, it determines
    which stances a member has that might suggest that the member would vote
    for the given side of the bill.

    Arguments:
        member: the member whose stances will be filtered
        bill: the bill whose stances will be used to filter the member stances
        side: the side of the bill to examine (e.g. FOR or AGN)

    Return:
        A list that contains only those member stances that are the same as
        those implied by voting on the given side of the bill.
    """
    logger.LOGGER.info("Considering implications of voting %s bill %s..." % (side, bill.bill_number))
    logger.LOGGER.info("Matching member stances with bill stances...")

    stances = []
    if side == outcomes.FOR:
        stances = _match_stances_helper(member, bill.stances_for)
    elif side == outcomes.AGN:
        stances = _match_stances_helper(member, bill.stances_agn)
    else:
        logger.LOGGER.error("Invalid side to match: %s" % side)

    stance_analyze.sort_stances(stances, member)
    logger.LOGGER.info("Considering %s implications completed." % side)
    return stances
Example #2
0
    def test_sort_stances_key_not_given(self):
        """Verifies sort when the member key is not defined."""
        stances = self.generate_stance_array()
        member = Member()

        stance_analyze.sort_stances(stances, member)
        for i in range(0, len(stances) - 1):
            self.assertEqual(stances[i]._sort_key, stance_sort_key.EQUITY)
            self.assertTrue(stances[i].sort_key >= stances[i + 1].sort_key)