Skip to content

Commit 84e3e74

Browse files
authored
Add regressions_only output format (#21)
1 parent 266d6e5 commit 84e3e74

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

hunter/report.py

+33
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
class ReportType(Enum):
1313
LOG = "log"
1414
JSON = "json"
15+
REGRESSIONS_ONLY = "regressions_only"
1516

1617
def __str__(self):
1718
return self.value
@@ -34,6 +35,8 @@ def produce_report(self, test_name: str, report_type: ReportType):
3435
return self.__format_log_annotated(test_name)
3536
elif report_type == ReportType.JSON:
3637
return self.__format_json(test_name)
38+
elif report_type == ReportType.REGRESSIONS_ONLY:
39+
return self.__format_regressions_only(test_name)
3740
else:
3841
from hunter.main import HunterError
3942

@@ -83,3 +86,33 @@ def __format_json(self, test_name: str) -> str:
8386
import json
8487

8588
return json.dumps({test_name: [cpg.to_json() for cpg in self.__change_points]})
89+
90+
def __format_regressions_only(self, test_name: str) -> str:
91+
output = []
92+
for cpg in self.__change_points:
93+
regressions = []
94+
for cp in cpg.changes:
95+
metric = self.__series.metrics[cp.metric]
96+
if metric.direction * cp.forward_change_percent() < 0:
97+
regressions.append(
98+
(
99+
cp.metric,
100+
cp.stats.mean_1,
101+
cp.stats.mean_2,
102+
cp.stats.forward_rel_change() * 100.0,
103+
)
104+
)
105+
106+
if regressions:
107+
output.append(format_timestamp(cpg.time))
108+
output.extend(
109+
[
110+
" {:16}:\t{:#8.3g}\t--> {:#8.3g}\t({:+6.1f}%)".format(*args)
111+
for args in regressions
112+
]
113+
)
114+
115+
if output:
116+
return f"Regressions in {test_name}:" + "\n" + "\n".join(output)
117+
else:
118+
return f"No regressions found in {test_name}."

0 commit comments

Comments
 (0)