eval_context.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import os
  2. from jinja2 import Environment, FileSystemLoader
  3. from api.od import ODAPI
  4. from framework.conformance import eval_context_decorator
  5. @eval_context_decorator
  6. def _render_geraniums_dot(od: ODAPI, file: str) -> str:
  7. __DIR__ = os.path.dirname(__file__)
  8. env = Environment(
  9. loader=FileSystemLoader(
  10. __DIR__
  11. )
  12. )
  13. env.trim_blocks = True
  14. env.lstrip_blocks = True
  15. template_dot = env.get_template("geraniums_renderer.j2")
  16. id_count = 0
  17. id_map = {}
  18. render = {"geraniums": [], "pots": [], "planted": []}
  19. for name, uuid in od.get_all_instances("Geranium"):
  20. render["geraniums"].append((id_count, name, od.get_slot_value(uuid, "flowering")))
  21. id_map[uuid] = id_count
  22. id_count += 1
  23. for name, uuid in od.get_all_instances("Pot"):
  24. render["pots"].append((id_count, name, od.get_slot_value(uuid, "cracked")))
  25. id_map[uuid] = id_count
  26. id_count += 1
  27. for name, uuid in od.get_all_instances("Planted"):
  28. render["planted"].append((id_map[od.get_source(uuid)], id_map[od.get_target(uuid)]))
  29. with open(file, "w", encoding="utf-8") as f_dot:
  30. f_dot.write(template_dot.render(**render))
  31. return ""
  32. eval_context = {
  33. "render_geraniums_dot": _render_geraniums_dot,
  34. }