From 53be8ed80cf8b92e011b34ea8bf2e602adb8621e Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 5 Nov 2025 14:36:50 +0100 Subject: add simple script generating graphviz from a balance --- plot.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 plot.py diff --git a/plot.py b/plot.py new file mode 100755 index 0000000..b5c6355 --- /dev/null +++ b/plot.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +"""Plot a balance""" +Balance = dict[str, dict[str, int]] + + +def plot(balance: Balance, exclude=None) -> str: + """Plot a given balance""" + + g = 'digraph balance {\n' + for u, b in balance.items(): + if exclude and u in exclude: + continue + + for other, val in b.items(): + if exclude and other in exclude: + continue + + if val > 0: + g += f'{u} -> {other} [label={val/100:.2f}];\n' + + return g + '}' + + +def main(): + """Entry point listing minimize steps of a particular state file""" + import json + import argparse + + parser = argparse.ArgumentParser() + parser.add_argument('state_file', default='state.json', nargs='?') + parser.add_argument('-x', '--exclude', nargs='*') + args = parser.parse_args() + with open(args.state_file, 'r', encoding='utf-8') as state_file: + balance = json.load(state_file)['balance'] + print(plot(balance, exclude=args.exclude)) + + +if __name__ == '__main__': + main() -- cgit v1.2.3