From d5b1a62a8d8423565e8a8a54ae09961e018a3eb2 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Mon, 26 Feb 2024 11:17:18 +0100 Subject: add --export-csv-unparam support --- bin/analyze-archive.py | 3 +++ bin/analyze-kconfig.py | 3 +++ bin/analyze-log.py | 3 +++ lib/cli.py | 24 ++++++++++++++++++++++++ lib/model.py | 3 +++ 5 files changed, 36 insertions(+) diff --git a/bin/analyze-archive.py b/bin/analyze-archive.py index 6fc014a..53a8c37 100755 --- a/bin/analyze-archive.py +++ b/bin/analyze-archive.py @@ -425,6 +425,9 @@ def main(): if args.info: dfatool.cli.print_info_by_name(model, by_name) + if args.export_csv_unparam: + dfatool.cli.export_csv_unparam(model, args.export_csv_unparam) + if args.export_pgf_unparam: dfatool.cli.export_pgf_unparam(model, args.export_pgf_unparam) diff --git a/bin/analyze-kconfig.py b/bin/analyze-kconfig.py index 44b7e24..d148641 100755 --- a/bin/analyze-kconfig.py +++ b/bin/analyze-kconfig.py @@ -353,6 +353,9 @@ def main(): if args.info: dfatool.cli.print_info_by_name(model, by_name) + if args.export_csv_unparam: + dfatool.cli.export_csv_unparam(model, args.export_csv_unparam) + if args.export_pgf_unparam: dfatool.cli.export_pgf_unparam(model, args.export_pgf_unparam) diff --git a/bin/analyze-log.py b/bin/analyze-log.py index db071fd..d6ae27a 100755 --- a/bin/analyze-log.py +++ b/bin/analyze-log.py @@ -120,6 +120,9 @@ def main(): if args.info: dfatool.cli.print_info_by_name(model, by_name) + if args.export_csv_unparam: + dfatool.cli.export_csv_unparam(model, args.export_csv_unparam) + if args.export_pgf_unparam: dfatool.cli.export_pgf_unparam(model, args.export_pgf_unparam) diff --git a/lib/cli.py b/lib/cli.py index 3b79fed..d07531c 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -370,6 +370,24 @@ def export_dot(model, dot_prefix): logger.info(f"Dot export of model saved to {filename}") +def export_csv_unparam(model, csv_prefix): + import csv + + for name in sorted(model.names): + filename = f"{csv_prefix}{name}.csv" + with open(filename, "w") as f: + writer = csv.writer(f) + writer.writerow( + ["measurement"] + model.parameters + sorted(model.attributes(name)) + ) + for i, param_tuple in enumerate(model.param_values(name)): + row = [i] + param_tuple + for attr in sorted(model.attributes(name)): + row.append(model.attr_by_name[name][attr].data[i]) + writer.writerow(row) + logger.info(f"CSV unparam data saved to {filename}") + + def export_pgf_unparam(model, pgf_prefix): for name in model.names: for attribute in model.attributes(name): @@ -466,6 +484,12 @@ def add_standard_arguments(parser): type=str, help="Export model and model quality to LaTeX dataref file", ) + parser.add_argument( + "--export-csv-unparam", + metavar="PREFIX", + type=str, + help="Export raw (parameter-independent) observations in CSV format to {PREFIX}{name}-{attribute}.csv", + ) parser.add_argument( "--export-pgf-unparam", metavar="PREFIX", diff --git a/lib/model.py b/lib/model.py index b92a50c..ffe1fb7 100644 --- a/lib/model.py +++ b/lib/model.py @@ -214,6 +214,9 @@ class AnalyticModel: def attributes(self, name): return self.attr_by_name[name].keys() + def param_values(self, name): + return self.by_name[name]["param"] + def param_index(self, param_name): if param_name in self.parameters: return self.parameters.index(param_name) -- cgit v1.2.3