From 6de2e8ee503f538132f5745e9c3bc35df98a0b4a Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 22 Jun 2022 15:09:48 +0200 Subject: analyze-kconfig: add csv export --- bin/analyze-kconfig.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'bin') diff --git a/bin/analyze-kconfig.py b/bin/analyze-kconfig.py index a51451a..aea441e 100755 --- a/bin/analyze-kconfig.py +++ b/bin/analyze-kconfig.py @@ -25,6 +25,24 @@ from dfatool.model import AnalyticModel from dfatool.validation import CrossValidator +def write_csv(f, model, attr): + model_attr = model.attr_by_name[attr] + attributes = sorted(model_attr.keys()) + print(", ".join(model.parameters) + ", " + ", ".join(attributes), file=f) + + # 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( + lambda a: model_attr[a].by_param.get(tuple(param_tuple), list()), attributes + ) + print( + ", ".join(map(str, param_tuple)) + + ", " + + ", ".join(map(str, map(np.mean, param_data))), + file=f, + ) + + def main(): parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description=__doc__ @@ -56,6 +74,17 @@ def main(): metavar="VALUE_OR_MAP", help="Specify desired maximum standard deviation for decision tree generation, either as float (global) or /=[,/=,...]", ) + parser.add_argument( + "--export-csv", + type=str, + metavar="FILE", + help="Export observations aggregated by parameter to FILE", + ) + parser.add_argument( + "--export-csv-only", + action="store_true", + help="Exit after exporting observations to CSV file", + ) parser.add_argument( "--export-observations", type=str, @@ -289,6 +318,15 @@ def main(): logging.warning(f"Skipping LUT model: {e}") lut_model = None + if args.export_csv: + for name in model.names: + 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) + if args.export_csv_only: + return + fit_start_time = time.time() param_model, param_info = model.get_fitted() fit_duration = time.time() - fit_start_time -- cgit v1.2.3