Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Math Tutor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jannik Wurche
Math Tutor
Commits
9d0e26ae
Commit
9d0e26ae
authored
9 months ago
by
Jannik Wurche
Browse files
Options
Downloads
Patches
Plain Diff
add comments
parent
ae00c2ca
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Pages/ResultView.elm
+21
-6
21 additions, 6 deletions
src/Pages/ResultView.elm
with
21 additions
and
6 deletions
src/Pages/ResultView.elm
+
21
−
6
View file @
9d0e26ae
...
...
@@ -7,9 +7,11 @@ import Html.Events exposing (onClick)
import
Utils
.
HelperFunction
exposing
(
normalizeString
)
import
LaTeX
.
Expression
-- Main function to render the result view of the quiz.
resultView
:
Model
->
Html
Msg
resultView
model
=
let
-- Convert the answers to an HTML table.
content
=
answersToTable
model
.
quiz
.
questions
in
div
[
class
"
resultView"
]
...
...
@@ -21,35 +23,40 @@ resultView model =
,
a
[
class
"
btn"
,
href
"
/home"
,
onClick
ResetQuizID
]
[
text
"
neu"
]]
]
-- Convert
model.answers to a
table
-- Convert
list of questions to an HTML
table
.
answersToTable
:
List
Question
->
Html
Msg
answersToTable
q
=
table
[]
[
tbody
[]
(
List
.
map
answerToRow
q
)
]
-- Convert a single question to a table row.
answerToRow
:
Question
->
Html
Msg
answerToRow
q
=
let
key
=
"
Frage "
++
(
String
.
fromInt
(
q
.
id
+
1
))
-- Check if the user's answer is correct.
gotCorrect
=
evaluateQuestion
q
.
questionType
-- Create a colored div based on correctness.
colorDiv
=
if
gotCorrect
then
div
[
class
"
colorDiv correct"
]
[]
else
div
[
class
"
colorDiv false"
]
[]
-- Display the result based on question type.
result
=
case
q
.
questionType
of
MCQ
a
->
displayMcqResult
gotCorrect
a
.
correct
a
.
userSelection
SCQ
a
->
displayScqResult
gotCorrect
a
.
correct
a
.
userSelection
Input
a
->
displayInputResult
gotCorrect
a
.
correct
a
.
userSelection
task
=
div
[
class
"
task"
]
[
LaTeX
.
Expression
.
compile
q
.
task
]
in
-- Wrap the key, color div, and result in a table row.
tr
[]
[
td
[]
[
text
key
]
,
td
[]
[
colorDiv
]
,
td
[]
[
div
[]
[
task
,
result
]
]
]
-- Evaluate if the user's answer to a question is correct.
evaluateQuestion
:
QuestionType
->
Bool
evaluateQuestion
q
=
case
q
of
...
...
@@ -60,11 +67,12 @@ evaluateQuestion q =
str
=
if
a
.
sensitive
then
a
.
userSelection
else
(
normalizeString
a
.
userSelection
)
in
List
.
member
str
a
.
correct
-- Display result for Multiple Choice Questions (MCQ).
displayMcqResult
:
Bool
->
List
String
->
List
String
->
Html
Msg
displayMcqResult
gotCorrect
correctAnswers
userAnswers
=
let
thisWasCorrect
=
String
.
join
"
und "
correctAnswers
yourAnswer
=
String
.
join
"
und "
userAnswers
thisWasCorrect
=
String
.
join
"
und
"
correctAnswers
yourAnswer
=
String
.
join
"
und
"
userAnswers
feedback
=
if
gotCorrect
then
div
[
class
"
innerResult"
]
...
...
@@ -74,8 +82,10 @@ displayMcqResult gotCorrect correctAnswers userAnswers =
else
wrongAnswerDiv
thisWasCorrect
yourAnswer
in
-- Wrap the feedback in a result div.
div
[
class
"
result"
]
[
feedback
]
-- Display result for Single Choice Questions (SCQ).
displayScqResult
:
Bool
->
String
->
String
->
Html
Msg
displayScqResult
gotCorrect
correctAnswer
userAnswer
=
let
...
...
@@ -88,12 +98,14 @@ displayScqResult gotCorrect correctAnswer userAnswer =
else
wrongAnswerDiv
correctAnswer
userAnswer
in
-- Wrap the feedback in a result div.
div
[
class
"
result"
]
[
feedback
]
-- Display result for input-based questions.
displayInputResult
:
Bool
->
List
String
->
String
->
Html
Msg
displayInputResult
gotCorrect
correctAnswers
userAnswer
=
let
thisWasCorrect
=
String
.
join
"
oder "
correctAnswers
thisWasCorrect
=
String
.
join
"
oder
"
correctAnswers
feedback
=
if
gotCorrect
then
div
[
class
"
innerResult"
]
...
...
@@ -103,12 +115,15 @@ displayInputResult gotCorrect correctAnswers userAnswer =
else
wrongAnswerDiv
thisWasCorrect
userAnswer
in
-- Wrap the feedback in a result div.
div
[
class
"
result"
]
[
feedback
]
-- Check if all elements in list 'a' are present in list 'b'.
areAllIn
:
List
String
->
List
String
->
Bool
areAllIn
a
b
=
List
.
all
(
\
x
->
List
.
member
x
a
)
b
-- Display feedback for incorrect answers.
wrongAnswerDiv
:
String
->
String
->
Html
Msg
wrongAnswerDiv
correctAnswer
userAnswer
=
div
[
class
"
innerResult"
]
...
...
@@ -118,4 +133,4 @@ wrongAnswerDiv correctAnswer userAnswer =
,
div
[
class
"
vertical-line"
]
[]
,
div
[
class
"
answer"
]
[
p
[
class
"
answer"
]
[
text
"
Deine Antwort: "
]
,
p
[
class
"
follow"
]
[
LaTeX
.
Expression
.
compile
userAnswer
]
]]
\ No newline at end of file
,
p
[
class
"
follow"
]
[
LaTeX
.
Expression
.
compile
userAnswer
]
]]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment