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_groups_stances(self): """ Verifies the function only return stances from groups.""" array = self.generate_collect_type_stance_array() result = util.collect_group_stances(array) for stance in result: self.assertEquals(stance.source_db, db_constants.GROUPS)