mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
working on parsing markdown as a quiz
This commit is contained in:
1
.vscode/extensions.json
vendored
1
.vscode/extensions.json
vendored
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
"csharpier.csharpier-vscode"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -145,4 +145,32 @@ oneline question
|
|||||||
";
|
";
|
||||||
markdown.Should().Contain(expectedQuestionString);
|
markdown.Should().Contain(expectedQuestionString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestCanParseMarkdownQuizWithNoQuestions()
|
||||||
|
{
|
||||||
|
var rawMarkdownQuiz = @"
|
||||||
|
Name: Test Quiz
|
||||||
|
LockAtDueDate: true
|
||||||
|
ShuffleAnswers: true
|
||||||
|
OneQuestionAtATime: false
|
||||||
|
DueAt: 2023-08-21T23:59:00
|
||||||
|
LockAt: 2023-08-21T23:59:00
|
||||||
|
AssignmentGroup: Assignments
|
||||||
|
AllowedAttempts: -1
|
||||||
|
Description: this is the
|
||||||
|
multi line
|
||||||
|
description
|
||||||
|
";
|
||||||
|
var quiz = LocalQuiz.ParseMarkdown(rawMarkdownQuiz);
|
||||||
|
|
||||||
|
quiz.Name.Should().Be("Test Quiz");
|
||||||
|
quiz.LockAtDueDate.Should().Be(true);
|
||||||
|
quiz.ShuffleAnswers.Should().Be(true);
|
||||||
|
quiz.OneQuestionAtATime.Should().BeFalse();
|
||||||
|
quiz.AllowedAttempts.Should().Be(-1);
|
||||||
|
quiz.Description.Should().Be(@"this is the
|
||||||
|
multi line
|
||||||
|
description");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -249,7 +249,7 @@ public static partial class AssignmentSyncronizationExtensions
|
|||||||
var moduleTasks = localCourse.Modules.Select(async m =>
|
var moduleTasks = localCourse.Modules.Select(async m =>
|
||||||
{
|
{
|
||||||
var assignmentTasks = m.Assignments.Select(
|
var assignmentTasks = m.Assignments.Select(
|
||||||
(a) => localCourse.SyncAssignmentToCanvas(canvasCourseId, a, canvasAssignments, canvas)
|
async (a) => await localCourse.SyncAssignmentToCanvas(canvasCourseId, a, canvasAssignments, canvas)
|
||||||
);
|
);
|
||||||
var assignments = await Task.WhenAll(assignmentTasks);
|
var assignments = await Task.WhenAll(assignmentTasks);
|
||||||
return m with { Assignments = assignments };
|
return m with { Assignments = assignments };
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ public static partial class ModuleSyncronizationExtensions
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
var anyUpdated = false;
|
var anyUpdated = false;
|
||||||
foreach (var localAssignment in localModule.Assignments)
|
foreach (var localAssignment in localModule.Assignments.Where(a => a.DueAt > DateTime.Now))
|
||||||
{
|
{
|
||||||
var canvasModuleItemContentIds = canvasModulesItems[moduleCanvasId].Select(i => i.ContentId);
|
var canvasModuleItemContentIds = canvasModulesItems[moduleCanvasId].Select(i => i.ContentId);
|
||||||
if (!canvasModuleItemContentIds.Contains(localAssignment.CanvasId))
|
if (!canvasModuleItemContentIds.Contains(localAssignment.CanvasId))
|
||||||
@@ -135,7 +135,7 @@ public static partial class ModuleSyncronizationExtensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var localQuiz in localModule.Quizzes)
|
foreach (var localQuiz in localModule.Quizzes.Where(q => q.DueAt > DateTime.Now))
|
||||||
{
|
{
|
||||||
|
|
||||||
var canvasModuleItemContentIds = canvasModulesItems[moduleCanvasId].Select(i => i.ContentId);
|
var canvasModuleItemContentIds = canvasModulesItems[moduleCanvasId].Select(i => i.ContentId);
|
||||||
|
|||||||
@@ -23,8 +23,12 @@ public static partial class QuizSyncronizationExtensions
|
|||||||
{
|
{
|
||||||
var moduleTasks = localCourse.Modules.Select(async m =>
|
var moduleTasks = localCourse.Modules.Select(async m =>
|
||||||
{
|
{
|
||||||
var quizTasks = m.Quizzes.Select(
|
|
||||||
(q) => localCourse.SyncQuizToCanvas(canvasId, q, canvasQuizzes, canvas)
|
var quizTasks = m.Quizzes
|
||||||
|
.Select(
|
||||||
|
async (q) => q.DueAt > DateTime.Now
|
||||||
|
? await localCourse.SyncQuizToCanvas(canvasId, q, canvasQuizzes, canvas)
|
||||||
|
: q
|
||||||
);
|
);
|
||||||
var quizzes = await Task.WhenAll(quizTasks);
|
var quizzes = await Task.WhenAll(quizTasks);
|
||||||
return m with { Quizzes = quizzes };
|
return m with { Quizzes = quizzes };
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
using YamlDotNet.Serialization;
|
using YamlDotNet.Serialization;
|
||||||
|
|
||||||
namespace LocalModels;
|
namespace LocalModels;
|
||||||
@@ -56,4 +57,61 @@ Description: {Description}
|
|||||||
{questionMarkdown}
|
{questionMarkdown}
|
||||||
";
|
";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LocalQuiz ParseMarkdown(string input)
|
||||||
|
{
|
||||||
|
|
||||||
|
var splitInput = input.Split(Environment.NewLine + Environment.NewLine);
|
||||||
|
var settings = splitInput[0];
|
||||||
|
|
||||||
|
var name = extractLabelValue(settings, "Name");
|
||||||
|
var lockAtDueDate = bool.Parse(extractLabelValue(settings, "LockAtDueDate"));
|
||||||
|
var shuffleAnswers = bool.Parse(extractLabelValue(settings, "ShuffleAnswers"));
|
||||||
|
var oneQuestionAtATime = bool.Parse(extractLabelValue(settings, "OneQuestionAtATime"));
|
||||||
|
var allowedAttempts = int.Parse(extractLabelValue(settings, "AllowedAttempts"));
|
||||||
|
var dueAt = DateTime.Parse(extractLabelValue(settings, "DueAt"));
|
||||||
|
var lockAt = DateTime.Parse(extractLabelValue(settings, "LockAt"));
|
||||||
|
var description = extractDescription(settings);
|
||||||
|
|
||||||
|
// var assignmentGroup = ExtractLabelValue(settings, "AssignmentGroup");
|
||||||
|
return new LocalQuiz()
|
||||||
|
{
|
||||||
|
Id = "id-" + name,
|
||||||
|
Name = name,
|
||||||
|
Description = description,
|
||||||
|
LockAtDueDate = lockAtDueDate,
|
||||||
|
LockAt = lockAt,
|
||||||
|
DueAt = dueAt,
|
||||||
|
ShuffleAnswers = shuffleAnswers,
|
||||||
|
OneQuestionAtATime = oneQuestionAtATime,
|
||||||
|
// LocalAssignmentGroupId = "someId",
|
||||||
|
AllowedAttempts = allowedAttempts,
|
||||||
|
Questions = new LocalQuizQuestion[] { }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
static string extractLabelValue(string input, string label)
|
||||||
|
{
|
||||||
|
string pattern = $@"{label}: (.*?)\n";
|
||||||
|
Match match = Regex.Match(input, pattern);
|
||||||
|
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
return match.Groups[1].Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
static string extractDescription(string input)
|
||||||
|
{
|
||||||
|
string pattern = "Description: (.*?)$";
|
||||||
|
Match match = Regex.Match(input, pattern, RegexOptions.Singleline);
|
||||||
|
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
return match.Groups[1].Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user