コード例 #1
0
 def __readable_outlaw_sighting(self, sighting, one_liner=False):
     EDRLOG.log(u"sighting: {}".format(sighting), "DEBUG")
     if not sighting:
         return None
     t_minus = edtime.EDTime.t_minus(sighting["timestamp"], short=True)
     if one_liner:
         cmdr = (sighting["cmdr"][:29] + u'…') if len(sighting["cmdr"]) > 30 else sighting["cmdr"]
         starSystem = (sighting["starSystem"][:50] + u'…') if len(sighting["starSystem"]) > 50 else sighting["starSystem"]    
         if sighting.get("bounty", None) > 0:
             neat_bounty = EDBounty(sighting["bounty"]).pretty_print()
             # Translators: this is a one-liner for the recently sighted outlaws; Keep it short! T{t:<2} is to show how long ago e.g. T-4H (4 hours ago) 
             return _(u"T{t:<2}: {name} in {system}, wanted for {bounty}").format(t=t_minus, name=cmdr, system=starSystem, bounty=neat_bounty)
         else:
             # Translators: this is a one-liner for the recently sighted outlaws; Keep it short! T{t:<2} is to show how long ago e.g. T-4H (4 hours ago) 
             return _(u"T{t:<2}: {name} in {system}").format(t=t_minus, name=cmdr, system=starSystem)
     
     readable = []
     
     # Translators: this is for a recently sighted outlaw; T{t} is to show how long ago, e.g. T-2h43m 
     location = _(u"T{t} {name} sighted in {system}").format(t=t_minus, name=sighting["cmdr"], system=sighting["starSystem"])
     if sighting["place"] and sighting["place"] != sighting["starSystem"]:
         if sighting["place"].startswith(sighting["starSystem"]+" "):
             # Translators: this is a continuation of the previous item (location of recently sighted outlaw) and shows a place in the system (e.g. supercruise, Cleve Hub) 
             location += _(u", {place}").format(place=sighting["place"].partition(sighting["starSystem"]+" ")[2])
         else:
             location += _(u", {place}").format(place=sighting["place"])
     readable.append(location)
     if sighting["ship"] != "Unknown":
         # Translators: this is for the recently sighted outlaw feature; it shows which ship they were flying at the time
         readable.append(_(u"Spaceship: {}").format(sighting["ship"]))
     if sighting.get("bounty", None) > 0:
         neat_bounty = EDBounty(sighting["bounty"]).pretty_print()
         # Translators: this is for the recently sighted outlaw feature; it shows their bounty if any
         readable.append(_(u"Wanted for {} credits").format(neat_bounty))
     return readable
コード例 #2
0
ファイル: edrlegalrecords.py プロジェクト: Niteship/edr
    def summarize_recents(self, cmdr_id):
        self.__update_records_if_stale(cmdr_id)
        records = self.records.get(cmdr_id)["records"] if self.records.has_key(
            cmdr_id) else None
        if not records:
            EDRLOG.log(u"No recent legal records for {}".format(cmdr_id),
                       "INFO")
            return None

        EDRLOG.log(u"Got legal records for {}".format(cmdr_id), "INFO")
        summary = None
        counters = {"clean": 0, "wanted": 0}
        bounties = {
            "max": None,
            "last": {
                "value": None,
                "starSystem": None,
                "timestamp": None
            }
        }
        for record in records:
            counters["wanted"] += record["counters"]["wanted"]
            counters["clean"] += record["counters"]["clean"]
            bounties["max"] = max(record["bounties"]["max"], bounties["max"])
            if (record["bounties"]["last"]["timestamp"] >=
                    bounties["last"]["timestamp"]):
                bounties["last"] = record["bounties"]["last"]
        timespan = edtime.EDTime.pretty_print_timespan(self.timespan,
                                                       short=True,
                                                       verbose=True)
        if bounties["max"] or bounties["last"]["value"]:
            tminus = edtime.EDTime.t_minus(bounties["last"]["timestamp"],
                                           short=True)
            max_bounty = EDBounty(bounties["max"]).pretty_print()
            last_bounty = EDBounty(bounties["last"]["value"]).pretty_print()
            # Translators: this is a summary of a cmdr's recent legal history for the 'last {}' days, number of clean and wanted scans, max and last bounties
            summary = _(
                u"[Last {}] clean:{} / wanted:{} max={} cr, {} cr in {} {}"
            ).format(timespan, counters["clean"], counters["wanted"],
                     max_bounty, last_bounty, bounties["last"]["starSystem"],
                     tminus)
        else:
            # Translators: this is a summary of a cmdr's recent legal history for the 'last {}' days, number of clean and wanted scans
            summary = _(u"[Last {}] clean:{} / wanted:{}").format(
                timespan, counters["clean"], counters["wanted"])
        return summary
コード例 #3
0
ファイル: edrsystems.py プロジェクト: Niteship/edr
    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
コード例 #4
0
ファイル: test_edbounty.py プロジェクト: glock2how/edr
    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())
コード例 #5
0
ファイル: test_edbounty.py プロジェクト: glock2how/edr
    def test_pretty_print(self):
        bounty = EDBounty(999)
        self.assertEqual(bounty.pretty_print(), "999")

        bounty = EDBounty(1000)
        self.assertEqual(bounty.pretty_print(), "1.0 k")

        bounty = EDBounty(9999)
        self.assertEqual(bounty.pretty_print(), "10.0 k")

        bounty = EDBounty(12345)
        self.assertEqual(bounty.pretty_print(), "12 k")

        bounty = EDBounty(99999)
        self.assertEqual(bounty.pretty_print(), "99 k")

        bounty = EDBounty(100000)
        self.assertEqual(bounty.pretty_print(), "100 k")