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 test_pretty_print_timespan_short_diff(self): timespan = 60 * 60 * 24 * 7 + 60 * 60 * 5 result = EDTime.pretty_print_timespan(timespan, short=False) self.assertEqual(result, u"7d:5h") result = EDTime.pretty_print_timespan(timespan, short=True) self.assertEqual(result, u"7d") timespan = 60 * 60 * 24 * 7 + 60 * 60 * 5 + 60 * 23 + 12 result = EDTime.pretty_print_timespan(timespan, short=False) self.assertEqual(result, u"7d:5h") result = EDTime.pretty_print_timespan(timespan, short=True) self.assertEqual(result, u"7d") timespan = 60 * 60 * 5 result = EDTime.pretty_print_timespan(timespan, short=False) self.assertEqual(result, u"5h") result = EDTime.pretty_print_timespan(timespan, short=True) self.assertEqual(result, u"5h") timespan = 60 * 60 * 5 + 60 * 12 + 23 result = EDTime.pretty_print_timespan(timespan, short=False) self.assertEqual(result, u"5h:12m") result = EDTime.pretty_print_timespan(timespan, short=True) self.assertEqual(result, u"5h")
def test_pretty_print_timespan(self): timespan = 60 * 60 * 24 * 7 result = EDTime.pretty_print_timespan(timespan) self.assertEqual(result, u"7d") timespan = 60 * 60 * 3 result = EDTime.pretty_print_timespan(timespan) self.assertEqual(result, u"3h") timespan = 60 * 34 result = EDTime.pretty_print_timespan(timespan) self.assertEqual(result, u"34m") timespan = 12 result = EDTime.pretty_print_timespan(timespan) self.assertEqual(result, u"12s") timespan = 0 result = EDTime.pretty_print_timespan(timespan) self.assertEqual(result, u"0s") timespan = -60 * 60 * 24 * 12 with self.assertRaises(ValueError): EDTime.pretty_print_timespan(timespan)