mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
started to test markdown quiz format
This commit is contained in:
@@ -4,15 +4,15 @@ namespace LocalModels;
|
||||
|
||||
public record LocalQuiz
|
||||
{
|
||||
public string Id { get; init; } = "";
|
||||
public required string Id { get; init; }
|
||||
public ulong? CanvasId { get; init; } = null;
|
||||
public string Name { get; init; } = "";
|
||||
public string Description { get; init; } = "";
|
||||
public bool LockAtDueDate { get; init; }
|
||||
public required string Name { get; init; }
|
||||
public required string Description { get; init; }
|
||||
public bool LockAtDueDate { get; init; } = true;
|
||||
public DateTime? LockAt { get; init; }
|
||||
public DateTime DueAt { get; init; }
|
||||
public bool ShuffleAnswers { get; init; }
|
||||
public bool OneQuestionAtATime { get; init; }
|
||||
public bool ShuffleAnswers { get; init; } = true;
|
||||
public bool OneQuestionAtATime { get; init; } = false;
|
||||
public string? LocalAssignmentGroupId { get; init; }
|
||||
public int AllowedAttempts { get; init; } = -1; // -1 is infinite
|
||||
// public bool ShowCorrectAnswers { get; init; }
|
||||
@@ -34,4 +34,26 @@ public record LocalQuiz
|
||||
var yaml = serializer.Serialize(this);
|
||||
return yaml;
|
||||
}
|
||||
|
||||
public string ToMarkdown()
|
||||
{
|
||||
var questionMarkdownArray = Questions.Select(q => q.ToMarkdown()).ToArray();
|
||||
var questionDelimiter = Environment.NewLine + "---" + Environment.NewLine;
|
||||
var questionMarkdown = string.Join(questionDelimiter, questionMarkdownArray);
|
||||
|
||||
return $@"Name: {Name}
|
||||
Id: {Id}
|
||||
CanvasId: {CanvasId}
|
||||
LockAtDueDate: {LockAtDueDate.ToString().ToLower()}
|
||||
LockAt: {LockAt}
|
||||
DueAt: {DueAt}
|
||||
ShuffleAnswers: {ShuffleAnswers.ToString().ToLower()}
|
||||
OneQuestionAtATime: {OneQuestionAtATime.ToString().ToLower()}
|
||||
LocalAssignmentGroupId: {LocalAssignmentGroupId}
|
||||
AllowedAttempts: {AllowedAttempts}
|
||||
Description: {Description}
|
||||
---
|
||||
{questionMarkdown}
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,37 @@ public record LocalQuizQuestion
|
||||
{
|
||||
public ulong? CanvasId { get; set; }
|
||||
public string Id { get; set; } = "";
|
||||
public string Text { get; init; } = string.Empty;
|
||||
public string Text { get; init; } = string.Empty;
|
||||
public string HtmlText => Markdig.Markdown.ToHtml(Text);
|
||||
public string QuestionType { get; init; } = string.Empty;
|
||||
public int Points { get; init; }
|
||||
public IEnumerable<LocalQuizQuestionAnswer> Answers { get; init; } =
|
||||
Enumerable.Empty<LocalQuizQuestionAnswer>();
|
||||
public string ToMarkdown()
|
||||
{
|
||||
var answerArray = Answers.Select((answer, i) =>
|
||||
{
|
||||
var questionLetter = (char)(i + 97);
|
||||
var isMultipleChoice = QuestionType == "multiple_choice";
|
||||
|
||||
var correctIndicator = answer.Correct ? "*" : isMultipleChoice ? "" : " ";
|
||||
|
||||
|
||||
var questionTypeIndicator = isMultipleChoice
|
||||
? $"{correctIndicator}{questionLetter}) "
|
||||
: $"[{correctIndicator}] ";
|
||||
|
||||
var textWithSpecificNewline = answer.Text.Replace(Environment.NewLine, Environment.NewLine + " ");
|
||||
return $"{questionTypeIndicator}{textWithSpecificNewline}";
|
||||
});
|
||||
var answersText = string.Join(Environment.NewLine, answerArray);
|
||||
|
||||
return $@"Points: {Points}
|
||||
{Text}
|
||||
{answersText}
|
||||
---
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
public static class QuestionType
|
||||
|
||||
@@ -10,4 +10,5 @@ public record LocalQuizQuestionAnswer
|
||||
public string Text { get; init; } = string.Empty;
|
||||
|
||||
public string HtmlText => Markdig.Markdown.ToHtml(Text);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user