From b8a0da6898296f3ce7b1ca0b2b9986b3be7cab93 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sat, 27 Apr 2019 18:50:04 +1000 Subject: [PATCH] graph: add graphviz script --- graph.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 graph.py diff --git a/graph.py b/graph.py new file mode 100755 index 0000000..00a0a93 --- /dev/null +++ b/graph.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import json +import typing +import os + + +def as_graphviz(recipes: dict): + print("digraph G {") + for result, method in recipes.items(): + for variation in method: + for input in variation["input"]: + print(f"{input} -> {result}") + print("}") + + +if __name__ == '__main__': + root = os.path.dirname(__file__) + recipe_root = os.path.join(root, 'data', 'recipes') + + recipes = dict() + + for dirname, dirs, files in os.walk(recipe_root): + for f in files: + path = os.path.join(dirname, f) + name, _ = os.path.splitext(f) + with open(path, 'r') as src: + variations = json.load(src) + + recipes[name] = variations + + as_graphviz(recipes)