From 068ea7fe86354ff6fe2440e1dbfe563a1471238b Mon Sep 17 00:00:00 2001 From: Maksim Andrianov Date: Thu, 28 May 2020 16:25:14 +0300 Subject: [PATCH] [python][generator] Improved output. --- tools/python/maps_generator/checks/check.py | 29 +++++++++++++++---- .../maps_generator/checks/check_sections.py | 3 ++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/tools/python/maps_generator/checks/check.py b/tools/python/maps_generator/checks/check.py index fb04e0119f..b8e65bb431 100644 --- a/tools/python/maps_generator/checks/check.py +++ b/tools/python/maps_generator/checks/check.py @@ -25,6 +25,15 @@ ROW_TO_STR = { } +def norm(value): + if isinstance(value, (int, float)): + return abs(value) + elif hasattr(value, "__len__"): + return len(value) + + assert False, type(value) + + class Check(ABC): def __init__(self, name: str): self.name = name @@ -125,11 +134,19 @@ class CompareCheck(Check): if silent_if_no_results and self.result.arrow == Arrow.zero: return "" + rel = 0.0 + if self.result.arrow != Arrow.zero: + rel = ( + norm(self.result.diff) + * 100.0 + / max(norm(self.result.previous), norm(self.result.current)) + ) + return ( - f"{self.name}: {ROW_TO_STR[self.result.arrow]} " - f"{self.diff_format(self.result.diff)} " - f"[previous: {self.format(self.result.previous)}, " - f"current: {self.format(self.result.current)}]" + f"{self.name}: {ROW_TO_STR[self.result.arrow]} {rel:.2f}% " + f"[{self.format(self.result.previous)} → " + f"{self.format(self.result.current)}: " + f"{self.diff_format(self.result.diff)}]" ) @@ -172,7 +189,7 @@ class CompareCheckSet(Check): def formatted_string(self, silent_if_no_results=False, filt=None, _offset=0) -> str: sets = filter(lambda c: isinstance(c, CompareCheckSet), self._with_result()) checks = filter(lambda c: isinstance(c, CompareCheck), self._with_result()) - checks = sorted(checks, key=lambda c: c.get_result().diff, reverse=True) + checks = sorted(checks, key=lambda c: norm(c.get_result().diff), reverse=True) if filt is None: filt = self.filt @@ -208,7 +225,7 @@ class CompareCheckSet(Check): return "" head += lines - return "\n".join(head) + return "\n".join(head) + "\n" def _with_result(self): return (c for c in self.checks if c.get_result() is not None) diff --git a/tools/python/maps_generator/checks/check_sections.py b/tools/python/maps_generator/checks/check_sections.py index 8a6b4d6678..e708b172e7 100644 --- a/tools/python/maps_generator/checks/check_sections.py +++ b/tools/python/maps_generator/checks/check_sections.py @@ -26,6 +26,9 @@ class SectionNames: return self.sections > other.sections assert False, type(other) + def __len__(self): + return len(self.sections) + def __str__(self): return str(self.sections)