diff options
-rwxr-xr-x | bin/analyze-log.py | 13 | ||||
-rw-r--r-- | lib/cli.py | 23 |
2 files changed, 32 insertions, 4 deletions
diff --git a/bin/analyze-log.py b/bin/analyze-log.py index 0b66bdf..50b5648 100755 --- a/bin/analyze-log.py +++ b/bin/analyze-log.py @@ -301,7 +301,7 @@ def main(): if args.export_dot: dfatool.cli.export_dot(model, args.export_dot) - if args.export_dref: + if args.export_dref or args.export_pseudo_dref: dref = model.to_dref( static_quality, lut_quality, @@ -321,9 +321,14 @@ def main(): mutual_information[param] ) - dfatool.cli.export_dataref( - args.export_dref, dref, precision=args.dref_precision - ) + if args.export_pseudo_dref: + dfatool.cli.export_pseudo_dref( + args.export_pseudo_dref, dref, precision=args.dref_precision + ) + if args.export_dref: + dfatool.cli.export_dataref( + args.export_dref, dref, precision=args.dref_precision + ) if args.export_json: with open(args.export_json, "w") as f: @@ -331,6 +331,23 @@ def model_quality_table( print(buf) +def export_pseudo_dref(dref_file, dref, precision=None): + with open(dref_file, "w") as f: + for k, v in sorted(os.environ.items(), key=lambda kv: kv[0]): + if k.startswith("DFATOOL_"): + print(f"% {k}='{v}'", file=f) + for arg in sys.argv: + print(f"% {arg}", file=f) + for k, v in sorted(dref.items()): + k = k.replace("/", "I").replace("-", "").replace(" ", "") + if type(v) is tuple: + v = v[0] + if type(v) in (float, np.float64) and precision is not None: + print("\\def\\" + k + "{" + f"{v:.{precision}f}" + "}") + else: + print("\\def\\" + k + "{" + str(v) + "}") + + def export_dataref(dref_file, dref, precision=None): with open(dref_file, "w") as f: for k, v in sorted(os.environ.items(), key=lambda kv: kv[0]): @@ -493,6 +510,12 @@ def add_standard_arguments(parser): help="Export tree-based model to {PREFIX}{name}-{attribute}.dot", ) parser.add_argument( + "--export-pseudo-dref", + metavar="FILE", + type=str, + help="Export model and model quality to LaTeX def file (sort of like dataref)", + ) + parser.add_argument( "--export-dref", metavar="FILE", type=str, |