Skip to content

Commit

Permalink
Add regressions_only output format (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrrr authored Sep 23, 2024
1 parent 266d6e5 commit 84e3e74
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions hunter/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class ReportType(Enum):
LOG = "log"
JSON = "json"
REGRESSIONS_ONLY = "regressions_only"

def __str__(self):
return self.value
Expand All @@ -34,6 +35,8 @@ def produce_report(self, test_name: str, report_type: ReportType):
return self.__format_log_annotated(test_name)
elif report_type == ReportType.JSON:
return self.__format_json(test_name)
elif report_type == ReportType.REGRESSIONS_ONLY:
return self.__format_regressions_only(test_name)
else:
from hunter.main import HunterError

Expand Down Expand Up @@ -83,3 +86,33 @@ def __format_json(self, test_name: str) -> str:
import json

return json.dumps({test_name: [cpg.to_json() for cpg in self.__change_points]})

def __format_regressions_only(self, test_name: str) -> str:
output = []
for cpg in self.__change_points:
regressions = []
for cp in cpg.changes:
metric = self.__series.metrics[cp.metric]
if metric.direction * cp.forward_change_percent() < 0:
regressions.append(
(
cp.metric,
cp.stats.mean_1,
cp.stats.mean_2,
cp.stats.forward_rel_change() * 100.0,
)
)

if regressions:
output.append(format_timestamp(cpg.time))
output.extend(
[
" {:16}:\t{:#8.3g}\t--> {:#8.3g}\t({:+6.1f}%)".format(*args)
for args in regressions
]
)

if output:
return f"Regressions in {test_name}:" + "\n" + "\n".join(output)
else:
return f"No regressions found in {test_name}."

0 comments on commit 84e3e74

Please sign in to comment.