initial commit
This commit is contained in:
49
src/apworld_tester/pipeline/batch/reporter.py
Normal file
49
src/apworld_tester/pipeline/batch/reporter.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""Saying what each finished world did."""
|
||||
|
||||
from apworld_tester.core.display.progress import Progress
|
||||
from apworld_tester.core.model.verdict import Verdict
|
||||
|
||||
|
||||
class Reporter:
|
||||
"""One run's progress callback.
|
||||
|
||||
Holds its own bar rather than a module variable: two runs in one
|
||||
process would otherwise share a bar and a tally.
|
||||
"""
|
||||
|
||||
def __init__(self, config, bar=False):
|
||||
self.config = config
|
||||
self.wants_bar = bar
|
||||
self.bar = None
|
||||
|
||||
@staticmethod
|
||||
def marker(report):
|
||||
return ("cached" if report.get("skipped")
|
||||
else f"{report.get('elapsed_seconds')}s")
|
||||
|
||||
def verdicts(self, report):
|
||||
text = f"{report['outcome']}"
|
||||
multi = report.get("multi_outcome")
|
||||
return f"{text} / multi:{multi}" if multi else text
|
||||
|
||||
def drawn(self, index, total, report):
|
||||
if self.bar is None or self.bar.total != total:
|
||||
self.bar = Progress(total=total, config=self.config)
|
||||
self.bar.update(
|
||||
index=index,
|
||||
key=report.get("outcome") or "?",
|
||||
text=report.get("game") or "",
|
||||
fallback_line=(f"[{index}/{total}] {report['game']}: "
|
||||
f"{self.verdicts(report)} ({self.marker(report)})"),
|
||||
)
|
||||
|
||||
def printed(self, index, total, report):
|
||||
print(f"[{index}/{total}] {report.get('game')}: "
|
||||
f"{Verdict(report, self.config).label} ({self.marker(report)})",
|
||||
flush=True)
|
||||
|
||||
def __call__(self, index, total, report):
|
||||
if self.wants_bar:
|
||||
self.drawn(index, total, report)
|
||||
else:
|
||||
self.printed(index, total, report)
|
||||
Reference in New Issue
Block a user