respdiff/sumstat,statcmp: improve handling of empty reports

parent a430de76
Pipeline #39692 passed with stage
in 51 seconds
......@@ -31,21 +31,35 @@ def read_stats(filename: str) -> SummaryStatistics:
raise ValueError(exc)
def read_report(filename: str) -> Optional[DiffReport]:
def _handle_empty_report(exc: Exception, skip_empty: bool):
if skip_empty:
logging.debug('%s Omitting...', exc)
else:
logging.error(str(exc))
raise ValueError(exc)
def read_report(filename: str, skip_empty: bool = False) -> Optional[DiffReport]:
try:
return DiffReport.from_json(filename)
except (FileNotFoundError, InvalidFileFormat) as exc:
logging.warning('%s Omitting...', exc)
_handle_empty_report(exc, skip_empty)
return None
def load_summaries(reports: Sequence[DiffReport]) -> Sequence[Summary]:
def load_summaries(
reports: Sequence[DiffReport],
skip_empty: bool = False
) -> Sequence[Summary]:
summaries = []
for report in reports:
if report.summary is None:
logging.warning('Empty diffsum in "%s"! Omitting...', report.fileorigin)
continue
summaries.append(report.summary)
_handle_empty_report(
ValueError('Empty diffsum in "{}"!'.format(report.fileorigin)),
skip_empty)
else:
summaries.append(report.summary)
return summaries
......@@ -94,6 +108,11 @@ def add_arg_report(parser: ArgumentParser) -> None:
help='JSON report file(s)')
def add_arg_report_filename(parser: ArgumentParser) -> None:
parser.add_argument('report', type=str, nargs='*',
help='JSON report file(s)')
def get_datafile(args: Namespace, key: str = 'datafile', check_exists: bool = True) -> str:
datafile = getattr(args, key, None)
if datafile is None:
......
......@@ -236,11 +236,14 @@ def main():
help='Set plot label. It is also used for the filename.')
args = parser.parse_args()
reports = [report for report in args.report if report is not None]
summaries = cli.load_summaries(reports)
sumstats = args.stats
field_weights = args.cfg['report']['field_weights']
try:
summaries = cli.load_summaries(args.report)
except ValueError:
sys.exit(1)
passed = plot_overview(sumstats, field_weights, summaries, args.label)
if not passed:
......
......@@ -16,12 +16,17 @@ def _log_threshold(stats, label):
def main():
cli.setup_logging()
parser = argparse.ArgumentParser(description='generate statistics file from reports')
cli.add_arg_report(parser)
cli.add_arg_report_filename(parser)
cli.add_arg_stats_filename(parser)
args = parser.parse_args()
reports = [report for report in args.report if report is not None]
summaries = cli.load_summaries(reports)
reports = []
for filename in args.report:
report = cli.read_report(filename, skip_empty=True)
if report is not None:
reports.append(report)
summaries = cli.load_summaries(reports, skip_empty=True)
if not summaries:
logging.critical('No summaries found in reports!')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment