forked from ccs-amsterdam/compendium-checklist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmock.py
42 lines (33 loc) · 1.5 KB
/
mock.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
30
31
32
33
34
35
36
37
38
39
40
41
42
import csv
import logging
from collections import namedtuple
from jinja2 import Template
template = Template(open("mock_template.html").read())
PHASES = ["Getting Started", "Version Control for Your Program/Language", "Structure of Your Project Folders", "Checks Before Submitting Your Manuscript"]
class Question:
def __init__(self, phase, q, followup, followup_if, title, explanation, yes_explanation,
no_explanation, followup_box, info_box_header, info_box_content, **_):
self.phase = PHASES[int(phase) - 1]
self.q = q.replace(".", "_")
self.followup = followup.replace(".", "_")
self.followup_if = followup_if
self.title = title
self.explanation = explanation
self.yes_explanation = yes_explanation
self.no_explanation = no_explanation
self.info_box_header = info_box_header
self.info_box_content = info_box_content
self.followup_box = followup_box
phases = {phase: [] for phase in PHASES}
questions = [Question(**row) for row in csv.DictReader(open("steps_dichotomised.csv"))]
dependencies = {} # {q: 'yes'/'no': [deps]}
qdict = {q.q: q for q in questions}
for q in questions:
phases[q.phase].append(q)
if q.followup:
target = qdict[q.followup]
when = {"y": "yes", "n": "no"}[q.followup_if]
dependencies.setdefault(target.q, {}).setdefault(when, []).append(q.q)
if q.followup_box:
when = {"y": "yes", "n": "no"}[q.followup_box]
open("mock.html", "w").write(template.render(**locals()))