diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-11-05 14:36:50 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-11-06 09:55:33 +0100 |
| commit | 53be8ed80cf8b92e011b34ea8bf2e602adb8621e (patch) | |
| tree | 09746e897fee561b828e96155802dafae197a902 | |
| parent | 0ff0c25636bcebe5481b7dcad6132fda0cb704ee (diff) | |
| download | geldschieberbot-53be8ed80cf8b92e011b34ea8bf2e602adb8621e.tar.gz geldschieberbot-53be8ed80cf8b92e011b34ea8bf2e602adb8621e.zip | |
add simple script generating graphviz from a balance
| -rwxr-xr-x | plot.py | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -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() |
