got rubric creation working

This commit is contained in:
2023-07-31 16:27:38 -06:00
parent 70db40867c
commit 17734ab641
10 changed files with 276 additions and 80 deletions

View File

@@ -0,0 +1,37 @@
namespace CanvasModel.Assignments;
public record CanvasRubric
{
[JsonPropertyName("id")]
public ulong? Id { get; set; }
[JsonPropertyName("title")]
public required string Title { get; set; }
[JsonPropertyName("context_id")]
public ulong ContextId { get; set; }
[JsonPropertyName("context_type")]
public required string ContextType { get; set; }
[JsonPropertyName("points_possible")]
public double PointsPossible { get; set; }
[JsonPropertyName("reusable")]
public bool Reusable { get; set; }
[JsonPropertyName("read_only")]
public bool ReadOnly { get; set; }
// [JsonPropertyName("free_form_criterion_comments")]
// public bool? FreeFormCriterionComments { get; set; }
[JsonPropertyName("hide_score_total")]
public bool? HideScoreTotal { get; set; }
// [JsonPropertyName("data")]
// public required IEnumerable<CanvasRubricCriteria> Data { get; set; }
// assessments
// associations
}

View File

@@ -0,0 +1,35 @@
namespace CanvasModel.Assignments;
public record CanvasRubricAssociation
{
[JsonPropertyName("id")]
public ulong Id { get; set; }
[JsonPropertyName("rubrid_id")]
public ulong RubricId { get; set; }
[JsonPropertyName("association_id")]
public ulong AssociationId { get; set; }
[JsonPropertyName("association_type")]
public required string AssociationType { get; set; }
[JsonPropertyName("use_for_grading")]
public bool UseForGrading { get; set; }
[JsonPropertyName("summary_data")]
public string? SummaryDaata { get; set; }
[JsonPropertyName("purpose")]
public required string Purpose { get; set; }
[JsonPropertyName("hide_score_total")]
public bool? HideScoreTotal { get; set; }
[JsonPropertyName("hide_points")]
public bool HidePoints { get; set; }
[JsonPropertyName("hide_outcome-results")]
public bool HideOUtcomeResult { get; set; }
}

View File

@@ -15,16 +15,16 @@ public record AssignmentTemplate
return matches.Select(match => match.Groups[1].Value);
}
public static string GetHtml(AssignmentTemplate template, LocalAssignment assignment)
{
// public static string GetHtml(AssignmentTemplate template, LocalAssignment assignment)
// {
var html = Markdig.Markdown.ToHtml(template.Markdown);
// var html = Markdig.Markdown.ToHtml(template.Markdown);
foreach (KeyValuePair<string, string> entry in assignment.template_variables)
{
html = html.Replace($"%7B%7B{entry.Key}%7D%7D", entry.Value);
}
return html;
}
// foreach (KeyValuePair<string, string> entry in assignment.template_variables)
// {
// html = html.Replace($"%7B%7B{entry.Key}%7D%7D", entry.Value);
// }
// return html;
// }
}

View File

@@ -38,4 +38,41 @@ public record LocalAssignment
public DateTime due_at { get; init; }
public int points_possible { get; init; }
public IEnumerable<SubmissionType> submission_types { get; init; } = new SubmissionType[] { };
public string GetRubricHtml()
{
var output = "<h1>Rubric</h1><pre><code class=\"language-json\">[\n";
var lineStrings = rubric.Select(
item => $" {{\"label\": \"{item.Label}\", \"points\": {item.Points}}}"
);
output += string.Join(",\n", lineStrings);
output += "\n]</code></pre>";
return output;
}
public string GetDescriptionHtml(IEnumerable<AssignmentTemplate>? templates)
{
if (use_template && templates == null)
throw new Exception("cannot get description for assignment if templates not provided");
var rubricHtml = GetRubricHtml();
if (use_template)
{
var template = templates?.FirstOrDefault(t => t.Id == template_id);
if (template == null)
throw new Exception($"Could not find template with id {template_id}");
var html = Markdig.Markdown.ToHtml(template.Markdown);
foreach (KeyValuePair<string, string> entry in template_variables)
{
html = html.Replace($"%7B%7B{entry.Key}%7D%7D", entry.Value);
}
return html + "<hr>" + rubricHtml;
}
return Markdig.Markdown.ToHtml(description) + "<hr>" + rubricHtml;
}
}