mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
can persist distractors and load them
This commit is contained in:
@@ -103,4 +103,28 @@ Match the following terms & definitions
|
||||
var quiz = LocalQuiz.ParseMarkdown(rawMarkdownQuiz);
|
||||
quiz.Questions.First().Answers.First().MatchDistractors.Should().BeEquivalentTo(["this is the distractor"]);
|
||||
}
|
||||
[Fact]
|
||||
public void CanHaveDistractorsAndBePersisted()
|
||||
{
|
||||
var rawMarkdownQuiz = @"
|
||||
Name: Test Quiz
|
||||
ShuffleAnswers: true
|
||||
OneQuestionAtATime: false
|
||||
DueAt: 2023-08-21T23:59:00
|
||||
LockAt: 2023-08-21T23:59:00
|
||||
AssignmentGroup: Assignments
|
||||
AllowedAttempts: -1
|
||||
Description:
|
||||
---
|
||||
Match the following terms & definitions
|
||||
|
||||
^statement - a single command to be executed
|
||||
^ - this is the distractor
|
||||
";
|
||||
|
||||
var quiz = LocalQuiz.ParseMarkdown(rawMarkdownQuiz);
|
||||
var quizMarkdown = quiz.ToMarkdown();
|
||||
|
||||
quizMarkdown.Should().Contain("^ statement - a single command to be executed\n^ - this is the distractor");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using Akka.Util.Internal;
|
||||
|
||||
namespace LocalModels;
|
||||
|
||||
public record LocalQuizQuestion
|
||||
@@ -37,7 +39,10 @@ public record LocalQuizQuestion
|
||||
}
|
||||
else if (QuestionType == "matching")
|
||||
{
|
||||
return $"^ {answer.Text} - {answer.MatchedText}";
|
||||
var distractorText = answer.MatchDistractors?.Select(
|
||||
d => $"\n^ - {d}"
|
||||
).Join("") ?? "";
|
||||
return $"^ {answer.Text} - {answer.MatchedText}" + distractorText;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -184,15 +189,16 @@ public record LocalQuizQuestion
|
||||
if (questionType != "matching")
|
||||
return accumulator.Append(answer);
|
||||
|
||||
if(accumulator.Count() == 0)
|
||||
if (accumulator.Count() == 0)
|
||||
return accumulator.Append(answer);
|
||||
|
||||
if(answer.Text != "")
|
||||
if (answer.Text != "")
|
||||
return accumulator.Append(answer);
|
||||
|
||||
|
||||
var previousDistractors = accumulator.Last().MatchDistractors ?? [];
|
||||
var newLastAnswer = accumulator.Last() with {
|
||||
var newLastAnswer = accumulator.Last() with
|
||||
{
|
||||
MatchDistractors = previousDistractors.Append(answer.MatchedText ?? "").ToArray()
|
||||
};
|
||||
|
||||
|
||||
@@ -196,7 +196,8 @@ public class CanvasQuizService(
|
||||
.Select(a => new
|
||||
{
|
||||
answer_match_left = a.Text,
|
||||
answer_match_right = a.MatchedText
|
||||
answer_match_right = a.MatchedText,
|
||||
matching_answer_incorrect_matches = a.MatchDistractors,
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user