-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcq2h5p-old.sh
executable file
·365 lines (355 loc) · 9.29 KB
/
mcq2h5p-old.sh
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#/bin/bash
#####
# remove the old h5p.json, content.json, if they exist
#####
if [ -f "./h5p.json" ]; then rm ./h5p.json; fi
if [ -f "./content.json" ]; then rm ./content.json; fi
sleep 3s # pause for a while
#####
# * read the control parameters in the control.txt file; these are
# TITLE: the title of the H5P, set to "THIS IS THE TITLE" as default
# AUTHOR: the name in the author field, set to "I am The Author" as default
# LICENSE: the license, set to ODC PDDL as default
# INTRODUCTION: some blurb about the H5P
# PASS_PERCENTAGE: set to 50% as default
# DISABLE_BACKWARDS_NAVIGATION: set to false as default
# RANDOM_QUESTIONS: set to true as default
# POOL_SIZE: set to five (5) as default as there are 10 questions total
# N_QUESTIONS: there are 10 questions in the myMCQuestions.txt file
#
# * print to stdout the value of these parameters
#
#####
echo -e "The following control parameters were set for the H5P to be made:"
n_lines=1
while read line
do
echo $line
export "$line"
n_lines=`expr $nlines_n + 1`
done < ./control.txt
#####
# create h5p.json based on the values of the control parameters read for
# TITLE, AUTHOR, and LICENSE
#####
cat > h5p.json << EOT
{
"title": $TITLE,
"language": "und",
"mainLibrary": "H5P.QuestionSet",
"embedTypes": [
"div"
],
"authors": [
{
"name": $AUTHOR,
"role": "Author"
}
],
"license": $LICENSE,
"defaultLanguage": "en",
"preloadedDependencies": [
{
"machineName": "H5P.MultiChoice",
"majorVersion": "1",
"minorVersion": "14"
},
{
"machineName": "FontAwesome",
"majorVersion": "4",
"minorVersion": "5"
},
{
"machineName": "EmbeddedJS",
"majorVersion": "1",
"minorVersion": "0"
},
{
"machineName": "H5P.JoubelUI",
"majorVersion": "1",
"minorVersion": "3"
},
{
"machineName": "H5P.Transition",
"majorVersion": "1",
"minorVersion": "0"
},
{
"machineName": "Drop",
"majorVersion": "1",
"minorVersion": "0"
},
{
"machineName": "Tether",
"majorVersion": "1",
"minorVersion": "0"
},
{
"machineName": "H5P.FontIcons",
"majorVersion": "1",
"minorVersion": "0"
},
{
"machineName": "H5P.Question",
"majorVersion": "1",
"minorVersion": "4"
},
{
"machineName": "H5P.QuestionSet",
"majorVersion": "1",
"minorVersion": "17"
},
{
"machineName": "H5P.Video",
"majorVersion": "1",
"minorVersion": "5"
},
{
"machineName": "flowplayer",
"majorVersion": "1",
"minorVersion": "0"
},
{
"machineName": "H5P.MathDisplay",
"majorVersion": "1",
"minorVersion": "0"
}
]
}
EOT
#####
# create the top part of the content.json; uses the values of
# INTRODUCTION, PASS_PERCENTAGE, DISABLE_BACKWARDS_NAVIGATION,
# RANDOM_QUESTIONS, and POOL_SIZE
#####
cat >> content.json << EOT
{
"introPage": {
"showIntroPage": true,
"startButtonText": "Start Quiz",
"title": $TITLE,
"introduction": "<p>${INTRODUCTION:1:-1}<br>\n </p>\n"
},
"progressType": "dots",
"passPercentage": $PASS_PERCENTAGE,
"disableBackwardsNavigation": $DISABLE_BACKWARDS_NAVIGATION,
"randomQuestions": $RANDOM_QUESTIONS,
"endGame": {
"showResultPage": true,
"showSolutionButton": true,
"showRetryButton": true,
"noResultMessage": "Finished",
"message": "Your result:",
"overallFeedback": [
{
"from": 0,
"to": 100
}
],
"solutionButtonText": "Show solution",
"retryButtonText": "Retry",
"finishButtonText": "Finish",
"showAnimations": false,
"skippable": false,
"skipButtonText": "Skip video"
},
"override": {
"checkButton": true,
"showSolutionButton": "on",
"retryButton": "on"
},
"texts": {
"prevButton": "Previous question",
"nextButton": "Next question",
"finishButton": "Finish",
"textualProgress": "Question: @current of @total questions",
"jumpToQuestion": "Question %d of %total",
"questionLabel": "Question",
"readSpeakerProgress": "Question @current of @total",
"unansweredText": "Unanswered",
"answeredText": "Answered",
"currentQuestionText": "Current question"
},
"poolSize": $POOL_SIZE,
"questions": [
EOT
i=1 # line number from input.txt
q=0 # indicator if the question part in an item has been processed
n=1 # counter for pool size
declare -a arrline
while read line
do
#echo $i
#echo "n = " $n
# if this is a question line, write question
if [ "$q" == "0" ]; then
#echo "$line"
#echo "JSON for question part being written"
arrline=(`echo -e $line`)
line=`unset arrline[0]; echo ${arrline[*]}`
cat >> content.json << EOT
{
"library": "H5P.MultiChoice 1.14",
"params": {
"question": "$line",
"answers": [
EOT
q=`expr $q + 1` # indicator q set to 1
elif [ "${line:0:1}" == "" ]; then # blank line or end of question
#echo "$line"
#echo "JSON for end of question, after last choice has been processed"
cat >> content.json << EOT
}
],
"behaviour": {
"enableRetry": true,
"enableSolutionsButton": true,
"enableCheckButton": true,
"type": "auto",
"singlePoint": false,
"randomAnswers": true,
"showSolutionsRequiresInput": true,
"confirmCheckDialog": false,
"confirmRetryDialog": false,
"autoCheck": false,
"passPercentage": 100,
"showScorePoints": true
},
"media": {
"disableImageZooming": false
},
"overallFeedback": [
{
"from": 0,
"to": 100
}
],
"UI": {
"checkAnswerButton": "Check",
"showSolutionButton": "Show solution",
"tryAgainButton": "Retry",
"tipsLabel": "Show tip",
"scoreBarLabel": "You got :num out of :total points",
"tipAvailable": "Tip available",
"feedbackAvailable": "Feedback available",
"readFeedback": "Read feedback",
"wrongAnswer": "Wrong answer",
"correctAnswer": "Correct answer",
"shouldCheck": "Should have been checked",
"shouldNotCheck": "Should not have been checked",
"noInput": "Please answer before viewing the solution",
"a11yCheck": "Check the answers. The responses will be marked as correct, incorrect, or unanswered.",
"a11yShowSolution": "Show the solution. The task will be marked with its correct solution.",
"a11yRetry": "Retry the task. Reset all responses and start the task over again."
},
"confirmCheck": {
"header": "Finish ?",
"body": "Are you sure you wish to finish ?",
"cancelLabel": "Cancel",
"confirmLabel": "Finish"
},
"confirmRetry": {
"header": "Retry ?",
"body": "Are you sure you wish to retry ?",
"cancelLabel": "Cancel",
"confirmLabel": "Confirm"
}
},
"subContentId": "`uuidgen`",
"metadata": {
"contentType": "Multiple Choice",
"license": "U",
"title": "Untitled Multiple Choice"
}
EOT
# if this is NOT the last question in the pool
if [ "$n" -lt "$N_QUESTIONS" ]; then
cat >> content.json << EOT
},
EOT
else # this is for the last choice for the last question in the pool
cat >> content.json << EOT
}
EOT
fi
q=0 # set q to zero for next question line to be written
n=`expr $n + 1` # increase counter for pool size
# if this is a correct answer choice ...
elif [ "${line:0:1}" == "*" ]; then
#echo "$line"
#echo "write JSON for a correct answer choice"
#if this is the first of the given choices
if [ "$q" == "1" ]; then
cat >> content.json << EOT
{
"text": "${line#'*'}",
"correct": true,
"tipsAndFeedback": {}
EOT
q=`expr $q + 1`
else # if (q=2) this is NOT the first of the given choices
cat >> content.json << EOT
},
{
"text": "${line#'*'}",
"correct": true,
"tipsAndFeedback": {}
EOT
fi
else # this must be a wrong answer line
#echo "$line"
#echo "write JSON for wrong answer line"
#if this is the first of the given choices
if [ "$q" == "1" ]; then
cat >> content.json << EOT
{
"text": "${line}",
"correct": false,
"tipsAndFeedback": {}
EOT
q=`expr $q + 1`
else # if (q=2) this is NOT the first of the given choices
cat >> content.json << EOT
},
{
"text": "${line}",
"correct": false,
"tipsAndFeedback": {}
EOT
fi
fi
i=`expr $i + 1`
done < $1
cat >> content.json << EOT
]
}
EOT
#####
# uncomment the next two lines to minify the JSON files
#####
#script -q -c "jq -c -M < ./h5p.json"; sed -n '2p' typescript > h5p.json
#script -q -c "jq -c -M < ./content.json"; sed -n '2p' typescript > content.json
#####
# set color tags (not all needed)
####
BLACK='\e[1;30m'
RED='\e[1;31m'
GREEN='\e[1;32m'
YELLOW='\e[1;33m'
BLUE='\e[1;34m'
BOLD='\e[1;39m'
BLINK='\e[5m'
OBLINK='\e[25m'
NORM='\e[0m'
mv ./h5p.json ./myNewH5P-mcq-old
mv ./content.json ./myNewH5P-mcq-old/content
if [ -e "./myNewH5P-mcq-old.h5p" ]; then rm ./myNewH5P-mcq-old.h5p; fi
cd myNewH5P-mcq-old
zip -r -D -X ../myNewH5P-mcq-old.h5p * >/dev/null
cd $OLDPWD
echo -e "\nThe h5p.json file was created in this directory: ${BOLD}${YELLOW}./myNewH5P-mcq-old/h5p.json${NORM}"
echo -e "The content.json that was created is in: ${BOLD}${YELLOW}./myNewH5P-mcq-old/content/content.json${NORM}"
echo -e "The newly created multiple-choice H5P is in this directory: ${BOLD}${YELLOW}./myNewH5P-mcq-old.h5p${NORM}\n"
###
##
#