blob: b5c635562e5c5b749a81d8d50ca3b0bbf2799999 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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()
|