forked from ccs-amsterdam/compendium-checklist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.py
29 lines (22 loc) · 801 Bytes
/
graph.py
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
import csv
from collections import namedtuple
r = csv.reader(open("steps.csv"))
next(r) # skip header
Question = namedtuple("Question", ["id", "title", "explanation", "answers"])
Answer = namedtuple("Answer", ["icon", "answer", "long_answer", "next_step"])
seen_questions = set()
questions = {}
for row in r:
id = row[0] or "root"
if id not in questions:
questions[id] = Question(id, *row[1:3], [])
a = Answer(*row[3:])
questions[id].answers.append(a)
print('digraph G {graph [rankdir="lr"];')
for i, q in enumerate(questions.values()):
print(f"subgraph cluster0 {{")
print(f'{q.id} [label="{q.title}"];')
for i, a in enumerate(q.answers):
print(f'{q.id}_{i} [label="{a.answer}"]; {q.id} -> {q.id}_{i} -> {a.next_step};')
print(f"}}")
print("}")