Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regressions_only output format #21

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}."
Loading