-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexercise.html
More file actions
278 lines (215 loc) · 12.3 KB
/
exercise.html
File metadata and controls
278 lines (215 loc) · 12.3 KB
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
<!DOCTYPE html>
<html>
<head>
<title>LTL Tutor</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
<!-- Include Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<!-- Include Bootstrap JS and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script src="{{ url_for('static', filename='js/ltlhljs.js') }}"></script>
<script src="{{ url_for('static', filename='js/common-functionality.js') }}"></script>
<script src="{{ url_for('static', filename='js/checkanswers.js') }}"></script>
<script>
hljs.registerLanguage('ltl', ltlSyntaxDefs);
hljs.highlightAll();
</script>
<link rel="stylesheet" href="{{ url_for('static', filename='css/common.css') }}">
<meta name="description" content="Learn Linear Temporal Logic (LTL) with this interactive tutor.">
</head>
<body>
<div class="container">
{% include 'navbar.html' %}
<h6 id="exerciseName">{{ exercise_name }}</h6>
<div id="questions">
{% for q in questions %}
{%set qindex = loop.index %}
<div class="card mt-4 question">
<div class="card-header mb-2">
<div class="row">
<div class="col-12">
<p class="font-italic">
{% if q.description %}
{{ q.description }}
{% endif %}
</p>
</div>
</div>
<div class="row align-items-center">
<div class="col">
<p class="lead">
{% if q.type == "englishtoltl" %}
Which of the following LTL formulae best represents this English sentence?
{% elif q.type == "tracesatisfaction_mc" %}
Which of the following traces satisfies the following LTL formula?
{% elif q.type == "tracesatisfaction_yn" %}
Does this trace satisfy the following LTL formula?
{% else %}
<div class="alert alert-danger" role="alert">
<strong>Unrecognized Question type! {{ q.type }}</strong>
</div>
{% endif %}
</p>
</div>
<div class="col text-right">
<small class="text-muted"> Question {{ qindex }} of {{ questions | length}} </small>
</div>
</div>
</div>
<div class="card-body">
{% if q.feedback %}
<div id="{{ qindex }}feedback" class="predeterminedfeedback" style="display: none;"> {{ q.feedback |
safe}} </div>
{% endif %}
{% if q.type == "tracesatisfaction_yn" %}
<h5 id="{{ qindex }}question_text" class="card-title mb-2">
<pre><code class="actualQuestion language-ltl" data-gloss-frame="{{ q.gloss_frame | default('') }}"> {{ q.question}} </code></pre>
</h5>
<pre class="mermaid" id="q{{qindex}}_yn_trace"
aria-label="{{q.trace}}"> {{ q.mermaid | safe}} </pre>
<div class="text-muted d-none" id="{{ qindex }}alttrace_sat">Trace Alt:
<pre class="actualQuestionTrace"> {{ q.trace}}</pre>
</div>
{% elif q.type == "tracesatisfaction_mc" %}
<h5 id="{{ qindex }}question_text" class="card-title mb-2">
<pre><code class="actualQuestion language-ltl" data-gloss-frame="{{ q.gloss_frame | default('') }}">{{ q.question}}</code></pre>
</h5>
{% else %}
<h5 id="{{ qindex }}question_text" class="card-title mb-2 actualQuestion"
data-gloss-frame="{{ q.gloss_frame | default('') }}"
style="white-space: pre-wrap;">{{ q.question}}
</h5>
<div class="row mb-2 ml-2">
{% if q.type == "englishtoltl" %}
<button type="button" class="btn btn-link text-primary p-0" data-toggle="modal" data-target="#ltlToEngRaterModal-{{ qindex }}">
Is this English sentence confusing or unclear?
</button>
{% include 'ltltoengrater.html' %}
{% endif %}
</div>
{% endif %}
<ul class="list-group">
{% for option in q.options %}
<li class="list-group-item mb-2 d-flex">
<label class="form-check-label" for="{{ qindex }}option{{ loop.index }}">
<div class="form-check flex-grow-1">
<input class="form-check-input" type="radio" name="{{ qindex }}option"
id="{{ qindex }}option{{ loop.index }}" class="option"
value="{{ option.option }}" data-misconceptions="{{ option.misconceptions }}"
data-correct="{{ option.isCorrect }}" {% if option.generatedFromFormula %}
data-generatedfromformula=" {{ option.generatedFromFormula }} " {% endif %}>
{% if q.type == 'tracesatisfaction_mc' %}
<pre aria-label="{{option.option}}" class="mermaid"
id="traceforq{{ qindex }}option{{ loop.index }}"> {{ option.mermaid | safe}} </pre>
<div class="text-muted d-none"> Trace Alt:
<pre> {{ option.option }}</pre>
</div>
{% elif q.type == 'tracesatisfaction_yn' %}
<span class="text-justify">{{ option.option }}</span>
{% else %}
<pre><code class="language-ltl">{{ option.option }}</code></pre>
{% endif %}
</div>
</label>
</li>
{% endfor %}
</ul>
<button class="btn btn-primary checkanswer" onclick="{{q.type}}_getfeedback(this); enableNextButton(this); scrollToFeedback()" disabled>Check
Answer</button>
<!-- TODO: Disable this, and then re-enable -->
<button class="btn btn-primary next" disabled>Next Question</button>
</div>
</div>
{% endfor %}
</div>
<script>
function enableNextButton(checkAnswerButton) {
var parent = checkAnswerButton.parentNode;
var nextButton = parent.getElementsByClassName('next')[0];
nextButton.disabled = false;
}
</script>
<div id="feedback">
</div>
<div id="done" style="display: none;" class="card">
<div class="card-body">
<h6 class="card-title">Exercise completed! </h6>
<!-- <h6 class="card-subtitle mb-2 text-muted">You have completed the exercise</h6> -->
<p class="card-text">You got <span id="correctCount">0</span> questions correct and
<span id="incorrectCount">0</span> questions incorrect.
</p>
</div>
<!-- I'd like a long button here that says, back to dashboard -->
<div class="btn-group d-flex mb-3" role="group" aria-label="Navigation Buttons">
<button class="btn btn-lg btn-secondary" onclick="window.location.href='/'">Dashboard</button>
<button class="btn btn-lg btn-secondary ml-2" onclick="window.location.href='/profile'">See Your Profile</button>
</div>
<div class="card-body bg-light shadow rounded mb-3">
<h4 class="card-title">What Next?</h4>
<a href="/exercise/generate" class="btn btn-lg btn-primary btn-block">Generate another Exercise.</a>
<br>
<hr>
</div>
</div>
</div>
<script>
$(document).ready(function () {
mermaid.initialize({ startOnLoad: false });
const ui_load_timeout_delay = 150;
function renderMermaidDiagram(graphElements) {
mermaid.run({
nodes: graphElements
}).then((data) => {
//console.log("Mermaid diagram rendered for " + graphElements + " successfully");
// TODO: Should this stay?
// Loop over each graphElement and set the width of the child SVG
graphElements.forEach(function (element) {
let $element = $(element);
$element.width($element.find('svg').css('max-width'));
});
}).catch((err) => {
console.error("Error rendering mermaid diagram");
console.error(err);
});
};
// Hide all questions at the start
$('.question').hide();
// Show the first question
$('.question:first').show();
// Initialize mermaid for the first question
let first_question_to_render = $('.question:first').find('.mermaid').get();
renderMermaidDiagram(first_question_to_render);
// When the "Next" button is clicked, hide the current question and show the next one
$('.next').click(function () {
// Empty the feedback div
$('#feedback').empty();
$('#feedback').removeClass();
var nextQuestion = $(this).closest('.question').hide().next('.question');
if (nextQuestion.length) {
nextQuestion.show();
let to_render = nextQuestion.find('.mermaid').get();
renderMermaidDiagram(to_render);
} else {
// If there are no more questions, show the "done" section
$('#done').show();
}
});
// Disable all "Check Answer" buttons initially
$('.checkanswer').prop('disabled', true);
// Add event listeners to radio buttons
$('input[type="radio"]').on('change', function () {
// Find the parent question card
const questionCard = $(this).closest('.question');
// Enable the "Check Answer" button within the same question card
questionCard.find('.checkanswer').prop('disabled', false);
});
});
</script>
{% include 'footer.html' %}
</body>
</html>