def _update_regular_stances(decision): """ Updates the various stances within decision. In particular, this function calculates norms, determines the stances groups have on the issue, and determines split groups, credos, voting records, etc. Arguments: decision: The decision object to update """ logger.LOGGER.info("Updating regular stances...") fors = decision.for_stances agns = decision.agn_stances bill = PymongoDB.get_db().find_one(db_constants.BILLS, queries.bill_query(decision.bill)) logger.LOGGER.info("Updating norms...") decision.for_norms = stance_analyze.collect_normative_stances(fors) decision.agn_norms = stance_analyze.collect_normative_stances(agns) if bill is None: logger.LOGGER.error("Decision bill not found.") else: logger.LOGGER.info("Updating bill norms...") decision.for_bill_norms = stance_analyze.collect_normative_stances(bill.stances_for) decision.agn_bill_norms = stance_analyze.collect_normative_stances(bill.stances_agn) logger.LOGGER.info("Updating group stances...") decision.groups_for = util.collect_group_stances(fors) decision.groups_agn = util.collect_group_stances(agns) # Equality is defined by seeing if a stance has the same source as another. # This is needed to detect split groups. However, the stances are not # equal to each other in the normal sense. Hence, the intersection is done # twice to get all unique stances. eq_fun = lambda stance1, stance2: stance1.source == stance2.source for_intersect = util.intersection(decision.groups_for, decision.groups_agn, eq_fun) agn_intersect = util.intersection(decision.groups_agn, decision.groups_for, eq_fun) decision.split_group = for_intersect + agn_intersect if decision.split_group: logger.LOGGER.info("Split group detected.") for_bills = util.collect_bill_stances(fors) agn_bills = util.collect_bill_stances(agns) if for_bills and agn_bills: logger.LOGGER.info("Split record detected.") decision.split_record = for_bills + agn_bills for_credo = util.collect_credo_stances(fors) agn_credo = util.collect_credo_stances(agns) if for_credo and agn_credo: logger.LOGGER.info("Split credo detected.") decision.split_credo = for_credo + agn_credo logger.LOGGER.info("Regular stances update complete.")
def test_collect_normative_stances_no_result(self): """Verifies function return nothing if there are no normative stances.""" agn_norm_stance = Stance() agn_norm_stance.issue = "decision_analyze_test_norm" agn_norm_stance.side = outcomes.CON result = stance_analyze.collect_normative_stances([agn_norm_stance, agn_norm_stance]) self.assertEquals(len(result), 0)
def test_collect_normative_stances_no_duplicates(self): """Verifies function return does not contain duplicates.""" stance = Stance() stance.issue = "decision_analyze_test_norm" stance.side = outcomes.PRO result = stance_analyze.collect_normative_stances([stance, stance]) self.assertEquals(len(result), 1) self.assertEquals(result[0], stance)
def test_collect_normative_stances(self): """Verifies function returns only normative stances.""" stance = Stance() stance.issue = "decision_analyze_test_norm" stance.side = outcomes.PRO agn_norm_stance = Stance() agn_norm_stance.issue = "decision_analyze_test_norm" agn_norm_stance.side = outcomes.CON result = stance_analyze.collect_normative_stances([stance, agn_norm_stance]) self.assertEquals(len(result), 1) self.assertEquals(result[0], stance)