From ffa44e06b51c59f3490265a93a0ac2027596d645 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 23 Aug 2022 07:57:33 +0200 Subject: analyze-kconfig: add --csv-precision option for --csv-export --- bin/analyze-kconfig.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'bin') diff --git a/bin/analyze-kconfig.py b/bin/analyze-kconfig.py index aea441e..1ff98cf 100755 --- a/bin/analyze-kconfig.py +++ b/bin/analyze-kconfig.py @@ -25,11 +25,16 @@ from dfatool.model import AnalyticModel from dfatool.validation import CrossValidator -def write_csv(f, model, attr): +def write_csv(f, model, attr, precision=None): model_attr = model.attr_by_name[attr] attributes = sorted(model_attr.keys()) print(", ".join(model.parameters) + ", " + ", ".join(attributes), file=f) + if precision is not None: + data_wrapper = lambda x: f"{x:.{precision}f}" + else: + data_wrapper = str + # by convention, model_attr[attr].param_values is the same regardless of 'attr' for param_tuple in model_attr[attributes[0]].param_values: param_data = map( @@ -38,7 +43,7 @@ def write_csv(f, model, attr): print( ", ".join(map(str, param_tuple)) + ", " - + ", ".join(map(str, map(np.mean, param_data))), + + ", ".join(map(data_wrapper, map(np.mean, param_data))), file=f, ) @@ -74,6 +79,12 @@ def main(): metavar="VALUE_OR_MAP", help="Specify desired maximum standard deviation for decision tree generation, either as float (global) or /=[,/=,...]", ) + parser.add_argument( + "--csv-precision", + type=int, + metavar="NDIGITS", + help="Precision (number of decimal digits) for CSV export", + ) parser.add_argument( "--export-csv", type=str, @@ -323,7 +334,7 @@ def main(): target = f"{args.export_csv}-{name}.csv" print(f"Exporting aggregated data to {target}") with open(target, "w") as f: - write_csv(f, model, name) + write_csv(f, model, name, args.csv_precision) if args.export_csv_only: return -- cgit v1.2.3