can persist distractors and load them

This commit is contained in:
2024-08-23 10:17:19 -06:00
parent d18cbcb9e8
commit cd958f90e6
3 changed files with 37 additions and 6 deletions

View File

@@ -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()
};

View File

@@ -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();