def test_significant(self): bounty = EDBounty(12344) bounty.threshold = 12345 self.assertFalse(bounty.is_significant()) bounty = EDBounty(12345) bounty.threshold = 12345 self.assertTrue(bounty.is_significant()) bounty = EDBounty(12346) bounty.threshold = 12345 self.assertTrue(bounty.is_significant())
def summarize_recent_activity(self, star_system, powerplay=None): #TODO refactor/simplify this mess ;) summary = {} wanted_cmdrs = {} enemies = {} if self.has_recent_traffic(star_system): summary_sighted = [] recent_traffic = self.recent_traffic(star_system) if recent_traffic is not None: # Should always be true... simplify. TODO summary_traffic = collections.OrderedDict() for traffic in recent_traffic: previous_timestamp = summary_traffic.get( traffic["cmdr"], None) if traffic["timestamp"] < previous_timestamp: continue karma = traffic.get("karma", 0) if not karma > 0: karma = min(karma, traffic.get("dkarma", 0)) bounty = EDBounty(traffic.get("bounty", 0)) enemy = traffic.get("enemy", False) by_pledge = traffic.get("byPledge", None) if karma < 0 or bounty.is_significant(): wanted_cmdrs[traffic["cmdr"]] = [ traffic["timestamp"], karma ] elif powerplay and enemy and powerplay == by_pledge: enemies[traffic["cmdr"]] = [ traffic["timestamp"], karma ] else: summary_traffic[traffic["cmdr"]] = traffic["timestamp"] for cmdr in summary_traffic: summary_sighted.append(u"{} {}".format( cmdr, edtime.EDTime.t_minus(summary_traffic[cmdr], short=True))) if summary_sighted: # Translators: this is for the sitrep feature; it's a section to show sighted cmdrs in the system of interest summary[_c(u"sitrep section|✪ Sighted")] = summary_sighted if self.has_recent_crimes(star_system): summary_interdictors = [] summary_destroyers = [] recent_crimes = self.recent_crimes(star_system) if recent_crimes is not None: # Should always be true... simplify. TODO summary_crimes = collections.OrderedDict() for crime in recent_crimes: lead_name = crime["criminals"][0]["name"] if lead_name not in summary_crimes or crime[ "timestamp"] > summary_crimes[lead_name][0]: summary_crimes[lead_name] = [ crime["timestamp"], crime["offence"] ] for criminal in crime["criminals"]: previous_timestamp = wanted_cmdrs[ criminal["name"]][0] if criminal[ "name"] in wanted_cmdrs else None previous_timestamp = max( previous_timestamp, enemies[criminal["name"]] [0]) if criminal["name"] in enemies else None if previous_timestamp > crime["timestamp"]: continue karma = criminal.get("karma", 0) if not karma > 0: karma = min(karma, criminal.get("dkarma", 0)) bounty = EDBounty(traffic.get("bounty", 0)) enemy = traffic.get("enemy", False) by_pledge = traffic.get("byPledge", None) if karma < 0 or bounty.is_significant(): wanted_cmdrs[criminal["name"]] = [ crime["timestamp"], karma ] elif powerplay and enemy and powerplay == by_pledge: enemies[traffic["cmdr"]] = [ traffic["timestamp"], karma ] for criminal in summary_crimes: if summary_crimes[criminal][1] == "Murder": summary_destroyers.append(u"{} {}".format( criminal, edtime.EDTime.t_minus(summary_crimes[criminal][0], short=True))) elif summary_crimes[criminal][1] in [ "Interdicted", "Interdiction" ]: summary_interdictors.append(u"{} {}".format( criminal, edtime.EDTime.t_minus(summary_crimes[criminal][0], short=True))) if summary_interdictors: # Translators: this is for the sitrep feature; it's a section to show cmdrs who have been reported as interdicting another cmdr in the system of interest summary[_c(u"sitrep section|✪ Interdictors" )] = summary_interdictors if summary_destroyers: # Translators: this is for the sitrep feature; it's a section to show cmdrs who have been reported as responsible for destroying the ship of another cmdr in the system of interest; use a judgement-neutral term summary[_c( u"sitreps section|✪ Destroyers")] = summary_destroyers wanted_cmdrs = sorted(wanted_cmdrs.items(), key=operator.itemgetter(1), reverse=True) if wanted_cmdrs: summary_wanted = [] for wanted in wanted_cmdrs: summary_wanted.append(u"{} {}".format( wanted[0], edtime.EDTime.t_minus(wanted[1][0], short=True))) if summary_wanted: # Translators: this is for the sitrep feature; it's a section to show wanted cmdrs who have been sighted in the system of interest summary[_c(u"sitreps section|✪ Outlaws")] = summary_wanted enemies = sorted(enemies.items(), key=operator.itemgetter(1), reverse=True) if enemies: summary_enemies = [] for enemy in enemies: summary_enemies.append(u"{} {}".format( enemies[0], edtime.EDTime.t_minus(enemies[1][0], short=True))) if summary_enemies: # Translators: this is for the sitrep feature; it's a section to show enemy cmdrs who have been sighted in the system of interest summary[_c(u"sitreps section|✪ Enemies")] = summary_enemies return summary