A fully working version of the scheduling language with added examples
This commit is contained in:
parent
ec42f74960
commit
ebfd85a666
126 changed files with 7235 additions and 981 deletions
45
examples/geraniums/renderer.py
Normal file
45
examples/geraniums/renderer.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import os
|
||||
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
from api.od import ODAPI
|
||||
from concrete_syntax.graphviz.make_url import show_graphviz
|
||||
from concrete_syntax.graphviz.renderer import make_graphviz_id
|
||||
|
||||
try:
|
||||
import graphviz
|
||||
HAVE_GRAPHVIZ = True
|
||||
except ImportError:
|
||||
HAVE_GRAPHVIZ = False
|
||||
|
||||
def render_geraniums_dot(od: ODAPI, file: str) -> str:
|
||||
__DIR__ = os.path.dirname(__file__)
|
||||
env = Environment(
|
||||
loader=FileSystemLoader(
|
||||
__DIR__
|
||||
)
|
||||
)
|
||||
env.trim_blocks = True
|
||||
env.lstrip_blocks = True
|
||||
template_dot = env.get_template("geraniums_renderer.j2")
|
||||
|
||||
id_count = 0
|
||||
id_map = {}
|
||||
render = {"geraniums": [], "pots": [], "planted": []}
|
||||
|
||||
for name, uuid in od.get_all_instances("Geranium"):
|
||||
render["geraniums"].append((id_count, name, od.get_slot_value(uuid, "flowering")))
|
||||
id_map[uuid] = id_count
|
||||
id_count += 1
|
||||
|
||||
for name, uuid in od.get_all_instances("Pot"):
|
||||
render["pots"].append((id_count, name, od.get_slot_value(uuid, "cracked")))
|
||||
id_map[uuid] = id_count
|
||||
id_count += 1
|
||||
|
||||
for name, uuid in od.get_all_instances("Planted"):
|
||||
render["planted"].append((id_map[od.get_source(uuid)], id_map[od.get_target(uuid)]))
|
||||
|
||||
with open(file, "w", encoding="utf-8") as f_dot:
|
||||
f_dot.write(template_dot.render(**render))
|
||||
return ""
|
||||
Loading…
Add table
Add a link
Reference in a new issue