From 9d0e26aed39a5674cd222997f67f11c573dfbe78 Mon Sep 17 00:00:00 2001 From: aqquq <jannik.wurche@student.uni-halle.de> Date: Tue, 2 Jul 2024 18:47:56 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9C=20add=20comments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Pages/ResultView.elm | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Pages/ResultView.elm b/src/Pages/ResultView.elm index 96047dc..2db6e49 100644 --- a/src/Pages/ResultView.elm +++ b/src/Pages/ResultView.elm @@ -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 ] ]] -- GitLab