def test_t_minus(self): nowish_ms = 1000 * calendar.timegm(time.gmtime()) ago_ms = nowish_ms - 1000 * 60 * 60 * 24 * 7 result = EDTime.t_minus(ago_ms) self.assertEqual(result, u"T-7d") ago_ms = nowish_ms - 1000 * 60 * 60 * (24 * 7 + 5) result = EDTime.t_minus(ago_ms) self.assertEqual(result, u"T-7d:5h") result = EDTime.t_minus(ago_ms, short=True) self.assertEqual(result, u"-7d")
def summarize(self, cmdr_id): if not cmdr_id: EDRLOG.log(u"No cmdr_id, no records for {}".format(cmdr_id), "INFO") return None 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 legal records for {}".format(cmdr_id), "INFO") return None EDRLOG.log(u"Got legal records for {}".format(cmdr_id), "INFO") overview = None (clean, wanted, bounties, recent_stats) = self.__process(records) timespan = EDTime.pretty_print_timespan(self.timespan, short=True, verbose=True) maxB = u"" lastB = u"" if recent_stats["maxBounty"]: max_bounty = EDFineOrBounty(recent_stats["maxBounty"]).pretty_print() maxB = _(u", max={} cr").format(max_bounty) if "last" in recent_stats and recent_stats["last"].get("value", None) and (recent_stats["last"].get("starSystem", "") not in ["", "unknown", "Unknown"]): tminus = EDTime.t_minus(recent_stats["last"]["timestamp"], short=True) last_bounty = EDFineOrBounty(recent_stats["last"]["value"]).pretty_print() lastB = _(u", last: {} cr in {} {}").format(last_bounty, recent_stats["last"]["starSystem"], tminus) # Translators: this is an overview of a cmdr's recent legal history for the 'last {}' days, number of clean and wanted scans, and optionally max and last bounties overview = _(u"[Past {}] clean:{} / wanted:{}{}{}").format(timespan, recent_stats["clean"], recent_stats["wanted"], maxB, lastB) return {"overview": overview, "clean": clean, "wanted": wanted, "bounties": bounties}
def debug_repr(self): result = [] result.append(u"{} ; last_check:{} ; touched: {}".format( EDTime.t_minus(self.timestamp * 1000), EDTime.t_minus(self.last_check_timestamp * 1000) if self.last_check_timestamp else "", self._touched)) for cmdr_name in self.players: timestamp, player = self.players[cmdr_name.lower()].values() now = EDTime.py_epoch_now() if player.targeted: timestamp = now result.append(u"{} at {}: {} {}".format( cmdr_name, EDTime.t_minus(timestamp * 1000), "[TGT]" if player.targeted else "", player.json())) return result