mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
quizzes and assignments support negative and floating point values
This commit is contained in:
@@ -20,7 +20,7 @@ public record LocalAssignment : IModuleItem
|
||||
public string? LocalAssignmentGroupName { get; init; }
|
||||
public IEnumerable<string> SubmissionTypes { get; init; } = Array.Empty<string>();
|
||||
public IEnumerable<RubricItem> Rubric { get; init; } = Array.Empty<RubricItem>();
|
||||
public int PointsPossible => Rubric.Sum(r => r.IsExtraCredit ? 0 : r.Points);
|
||||
public double PointsPossible => Rubric.Sum(r => r.IsExtraCredit ? 0 : r.Points);
|
||||
|
||||
|
||||
public string GetDescriptionHtml()
|
||||
|
||||
@@ -89,12 +89,12 @@ public static class LocalAssignmentMarkdownParser
|
||||
|
||||
private static RubricItem parseIndividualRubricItemMarkdown(string rawMarkdown)
|
||||
{
|
||||
var pointsPattern = @"\s*-\s*(\d+)\s*pt(s)?:";
|
||||
var pointsPattern = @"\s*-\s*(-?\d+(?:\.\d+)?)\s*pt(s)?:";
|
||||
var match = Regex.Match(rawMarkdown, pointsPattern);
|
||||
if (!match.Success)
|
||||
throw new RubricMarkdownParseException($"points not found: {rawMarkdown}");
|
||||
|
||||
var points = int.Parse(match.Groups[1].Value);
|
||||
var points = double.Parse(match.Groups[1].Value);
|
||||
|
||||
var label = string.Join(": ", rawMarkdown.Split(": ").Skip(1));
|
||||
|
||||
|
||||
@@ -4,6 +4,6 @@ public record RubricItem
|
||||
{
|
||||
public static readonly string extraCredit = "(Extra Credit) ";
|
||||
public required string Label { get; set; }
|
||||
public required int Points { get; set; }
|
||||
public required double Points { get; set; }
|
||||
public bool IsExtraCredit => Label.Contains(extraCredit.ToLower(), StringComparison.CurrentCultureIgnoreCase);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public record LocalQuizQuestion
|
||||
public string Text { get; init; } = string.Empty;
|
||||
public string HtmlText => MarkdownService.Render(Text);
|
||||
public string QuestionType { get; init; } = string.Empty;
|
||||
public int Points { get; init; }
|
||||
public double Points { get; init; }
|
||||
public IEnumerable<LocalQuizQuestionAnswer> Answers { get; init; } =
|
||||
Enumerable.Empty<LocalQuizQuestionAnswer>();
|
||||
public string ToMarkdown()
|
||||
@@ -59,9 +59,9 @@ public record LocalQuizQuestion
|
||||
var textHasPoints = lines.Length > 0
|
||||
&& lines.First().Contains(": ")
|
||||
&& lines.First().Split(": ").Length > 1
|
||||
&& int.TryParse(lines.First().Split(": ")[1], out _);
|
||||
&& double.TryParse(lines.First().Split(": ")[1], out _);
|
||||
|
||||
int points = firstLineIsPoints && textHasPoints ? int.Parse(lines.First().Split(": ")[1]) : 1;
|
||||
double points = firstLineIsPoints && textHasPoints ? double.Parse(lines.First().Split(": ")[1]) : 1;
|
||||
|
||||
var linesWithoutPoints = firstLineIsPoints ? lines[1..] : lines;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user