mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 07:38:33 -06:00
only working with dates at at string level on the model
This commit is contained in:
@@ -13,10 +13,17 @@ public record LocalQuizQuestion
|
||||
public double Points { get; init; }
|
||||
public IEnumerable<LocalQuizQuestionAnswer> Answers { get; init; } =
|
||||
Enumerable.Empty<LocalQuizQuestionAnswer>();
|
||||
public IEnumerable<string> MatchDistractors { get; init; } = [];
|
||||
public string ToMarkdown()
|
||||
{
|
||||
var answerArray = Answers.Select(getAnswerMarkdown);
|
||||
var answersText = string.Join("\n", answerArray);
|
||||
|
||||
|
||||
var distractorText = MatchDistractors
|
||||
.Select(d => $"\n^ - {d}")
|
||||
.Join("");
|
||||
|
||||
var answersText = string.Join("\n", answerArray) + distractorText;
|
||||
var questionTypeIndicator = QuestionType == "essay" || QuestionType == "short_answer" ? QuestionType : "";
|
||||
|
||||
return $@"Points: {Points}
|
||||
@@ -39,10 +46,7 @@ public record LocalQuizQuestion
|
||||
}
|
||||
else if (QuestionType == "matching")
|
||||
{
|
||||
var distractorText = answer.MatchDistractors?.Select(
|
||||
d => $"\n^ - {d}"
|
||||
).Join("") ?? "";
|
||||
return $"^ {answer.Text} - {answer.MatchedText}" + distractorText;
|
||||
return $"^ {answer.Text} - {answer.MatchedText}";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -98,12 +102,22 @@ public record LocalQuizQuestion
|
||||
? getAnswers(linesWithoutPoints, questionIndex, questionType)
|
||||
: [];
|
||||
|
||||
var distractors = questionType == "matching"
|
||||
? answers.Where(a => a.Text == "").Select(a => a.MatchedText ?? "").ToArray()
|
||||
: [];
|
||||
|
||||
var answersWithoutDistractors = questionType == "matching"
|
||||
? answers.Where(a => a.Text != "").ToArray()
|
||||
: answers;
|
||||
|
||||
|
||||
return new LocalQuizQuestion()
|
||||
{
|
||||
Text = description,
|
||||
Points = points,
|
||||
Answers = answers,
|
||||
QuestionType = questionType
|
||||
Answers = answersWithoutDistractors,
|
||||
QuestionType = questionType,
|
||||
MatchDistractors = distractors
|
||||
};
|
||||
}
|
||||
|
||||
@@ -184,27 +198,6 @@ public record LocalQuizQuestion
|
||||
|
||||
var answers = answerLines
|
||||
.Select((a, i) => LocalQuizQuestionAnswer.ParseMarkdown(a, questionType))
|
||||
.Aggregate([], (IEnumerable<LocalQuizQuestionAnswer> accumulator, LocalQuizQuestionAnswer answer) =>
|
||||
{
|
||||
if (questionType != "matching")
|
||||
return accumulator.Append(answer);
|
||||
|
||||
if (accumulator.Count() == 0)
|
||||
return accumulator.Append(answer);
|
||||
|
||||
if (answer.Text != "")
|
||||
return accumulator.Append(answer);
|
||||
|
||||
|
||||
var previousDistractors = accumulator.Last().MatchDistractors ?? [];
|
||||
var newLastAnswer = accumulator.Last() with
|
||||
{
|
||||
MatchDistractors = previousDistractors.Append(answer.MatchedText ?? "").ToArray()
|
||||
};
|
||||
|
||||
return accumulator.Reverse().Skip(1).Reverse().Append(newLastAnswer);
|
||||
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
return answers;
|
||||
|
||||
@@ -9,7 +9,6 @@ public record LocalQuizQuestionAnswer
|
||||
public string Text { get; init; } = string.Empty;
|
||||
|
||||
public string? MatchedText { get; init; }
|
||||
public IEnumerable<string>? MatchDistractors { get; init; }
|
||||
|
||||
public string HtmlText => MarkdownService.Render(Text);
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using CanvasModel.Quizzes;
|
||||
|
||||
using LocalModels;
|
||||
|
||||
using RestSharp;
|
||||
|
||||
namespace Management.Services.Canvas;
|
||||
@@ -16,7 +18,7 @@ public class CanvasQuizService(
|
||||
CanvasServiceUtils utils,
|
||||
ICanvasAssignmentService assignments,
|
||||
ILogger<CanvasQuizService> logger
|
||||
): ICanvasQuizService
|
||||
) : ICanvasQuizService
|
||||
{
|
||||
private readonly IWebRequestor webRequestor = webRequestor;
|
||||
private readonly CanvasServiceUtils utils = utils;
|
||||
@@ -164,6 +166,7 @@ public class CanvasQuizService(
|
||||
|
||||
var url = $"courses/{canvasCourseId}/quizzes/{canvasQuizId}/questions";
|
||||
var answers = getAnswers(q);
|
||||
|
||||
var body = new
|
||||
{
|
||||
question = new
|
||||
@@ -172,9 +175,12 @@ public class CanvasQuizService(
|
||||
question_type = q.QuestionType + "_question",
|
||||
points_possible = q.Points,
|
||||
position,
|
||||
matching_answer_incorrect_matches = string.Join("\n", q.MatchDistractors),
|
||||
answers
|
||||
}
|
||||
};
|
||||
Console.WriteLine(JsonSerializer.Serialize(q));
|
||||
Console.WriteLine(JsonSerializer.Serialize(body));
|
||||
var request = new RestRequest(url);
|
||||
request.AddBody(body);
|
||||
|
||||
@@ -197,7 +203,6 @@ public class CanvasQuizService(
|
||||
{
|
||||
answer_match_left = a.Text,
|
||||
answer_match_right = a.MatchedText,
|
||||
matching_answer_incorrect_matches = a.MatchDistractors,
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user