def _initialize_decision(decision, member, bill): """Initializes a decision object with information about the member and bill. Extracts stances for the member based on the bill and the member's relations. Arguments: decision: the decision object to initialize member: a Member object corresponding to the member who will vote bill: a Bill object of the bill to be voted on. """ logger.LOGGER.info("Initializing decision...") decision.member = member._id decision.bill = bill._id if not member.stances: member_analyze.extract_voting_stances(member) if not member.pro_rel_stances: member_analyze.infer_relations_stances(member) logger.LOGGER.info("Analyzing alternative positions...") decision.for_stances = member_analyze.match_stances(member, bill, outcomes.FOR) decision.agn_stances = member_analyze.match_stances(member, bill, outcomes.AGN) logger.LOGGER.info("Initialization complete.")
def test_match_stances_for(self): """ Verifies stances are matched by the bill FOR stances.""" member = self.generate_member_with_stances() bill = Bill() bill.stances_for = member.credo bill.stances_agn = member.pro_rel_stances result = member_analyze.match_stances(member, bill, outcomes.FOR) for entry in result: self.assertTrue(entry in bill.stances_for)
def test_match_stances_agn(self): """ Verifies the returned stances are sorted by importance.""" member = Member() member.stance_sort_key = stance_sort_key.EQUITY credo_stance = Stance() credo_stance.issue = "Credo" credo_stance.side = outcomes.PRO credo_stance.importance = importance.B stances_stance1 = Stance() stances_stance1.issue = "Stances" stances_stance1.side = outcomes.CON stances_stance1.importance = importance.D stances_stance2 = Stance() stances_stance2.issue = "An Outcomes" stances_stance2.side = outcomes.PRO stances_stance2.importance = importance.A pro_rel_stance = Stance() pro_rel_stance.issue = "Pro-Relation" pro_rel_stance.side = outcomes.PRO pro_rel_stance.importance = importance.C member.credo.append(credo_stance) member.stances.append(stances_stance1) member.stances.append(stances_stance2) member.pro_rel_stances.append(pro_rel_stance) bill = Bill() bill.stances_for = member.credo + member.stances bill.stances_agn = member.pro_rel_stances result = member_analyze.match_stances(member, bill, outcomes.FOR) sorted_answer = [stances_stance2, credo_stance, stances_stance1] self.assertEqual(result, sorted_answer)