-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_prop_quizzes.py
82 lines (65 loc) · 2.76 KB
/
generate_prop_quizzes.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from shutil import copytree, ignore_patterns
import json
PROPS = [
"prop2",
"prop3",
"prop4",
"prop5",
"prop6",
"prop32",
"prop33",
"prop35",
"prop36",
# "prop34",
]
PROP_32_N_QUESTIONS = 4
PROP_34_N_QUESTIONS = 1
PROP_3_OPTION_VALUES = [[1, -1, 0], [1, -1, 0], [-1, 1, 0], [0, 0, 0]]
PROP_6_OPTION_VALUES = [[-1, 1, 0], [1, -1, 0], [1, -1, 0], [0, 0, 0]]
PROP_35_OPTION_VALUES = [[1, -1, 0], [1, -1, 0], [-1, 1, 0], [0, 0, 0]]
def generate_port_value_numbers_obj(option_value_nums):
return {
"type": "Number",
"value": [{"type": "Number", "value": value} for value in option_value_nums],
}
def write_graph_file(fp, json_obj):
with open(fp, mode="w", encoding="utf-8") as write_file:
json.dump(json_obj, write_file)
def set_n_questions(prop, n_questions):
effect_graph_file = f"{prop}/Graph/graph.json"
with open(effect_graph_file, mode="r", encoding="utf-8") as read_file:
effect_graph = json.load(read_file)
graph_node_list = effect_graph["containers"][0]["graph"]["nodeList"]
for node in graph_node_list:
if node["name"] == "Check quiz completion":
subgraph_node_list = node["subContainer"]["graph"]["nodeList"]
for node in subgraph_node_list:
if node["name"] == "n_questions":
node["variable"]["initialValue"] = n_questions
write_graph_file(effect_graph_file, effect_graph)
def set_option_values(prop, option_values):
effect_graph_file = f"{prop}/Graph/graph.json"
with open(effect_graph_file, mode="r", encoding="utf-8") as read_file:
effect_graph = json.load(read_file)
graph_node_list = effect_graph["containers"][0]["graph"]["nodeList"]
for node in graph_node_list:
if node["name"] == "Set options":
node["inputPorts"][2]["portValue"] = generate_port_value_numbers_obj(
option_values.pop(0)
)
if node["name"] == "Next question":
subgraph_node_list = node["subContainer"]["graph"]["nodeList"]
for node in subgraph_node_list:
if node["name"] == "Set options":
node["inputPorts"][2]["portValue"] = (
generate_port_value_numbers_obj(option_values.pop(0))
)
write_graph_file(effect_graph_file, effect_graph)
for prop in PROPS:
copytree("./effect-template", f"{prop}/")
set_n_questions("prop32", PROP_32_N_QUESTIONS)
# set_n_questions("prop34", PROP_34_N_QUESTIONS)
set_option_values("prop3", PROP_3_OPTION_VALUES)
set_option_values("prop6", PROP_6_OPTION_VALUES)
set_option_values("prop35", PROP_35_OPTION_VALUES)
print("REMINDER: Remember to edit prop 34")