Skip to content

Commit

Permalink
Course: Refactor assessment grades
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorNelson committed Jan 8, 2024
1 parent 25f4980 commit 1b8e8ef
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
21 changes: 11 additions & 10 deletions dojo_plugin/pages/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def query(module_id):
module_solves = {}

def result(user_id):
grades = []
assessment_grades = []

for assessment in assessments:
type = assessment.get("type")
Expand All @@ -119,7 +119,7 @@ def result(user_id):
challenge_count_required = int(challenge_count * percent_required)
user_date = date + datetime.timedelta(days=extension)

grades.append(dict(
assessment_grades.append(dict(
name=assessment_name(dojo, assessment),
date=str(user_date) + (" *" if extension else ""),
weight=weight,
Expand Down Expand Up @@ -153,7 +153,7 @@ def result(user_id):
credit = override
progress = f"{progress} *"

grades.append(dict(
assessment_grades.append(dict(
name=assessment_name(dojo, assessment),
date=str(user_date) + (" *" if extension else ""),
weight=weight,
Expand All @@ -162,33 +162,33 @@ def result(user_id):
))

if type == "manual":
grades.append(dict(
assessment_grades.append(dict(
name=assessment_name(dojo, assessment),
weight=assessment["weight"],
progress=assessment.get("progress", {}).get(str(user_id), ""),
credit=assessment.get("credit", {}).get(str(user_id), 0.0),
))

if type == "extra":
grades.append(dict(
assessment_grades.append(dict(
name=assessment_name(dojo, assessment),
progress=assessment.get("progress", {}).get(str(user_id), ""),
credit=assessment.get("credit", {}).get(str(user_id), 0.0),
))

overall_grade = (
sum(grade["credit"] * grade["weight"] for grade in grades if "weight" in grade) /
sum(grade["weight"] for grade in grades if "weight" in grade)
sum(grade["credit"] * grade["weight"] for grade in assessment_grades if "weight" in grade) /
sum(grade["weight"] for grade in assessment_grades if "weight" in grade)
)
extra_credit = (
sum(grade["credit"] for grade in grades if "weight" not in grade)
sum(grade["credit"] for grade in assessment_grades if "weight" not in grade)
)
overall_grade += extra_credit
overall_grade = round(overall_grade, 4)
letter_grade = get_letter_grade(dojo, overall_grade)

return dict(user_id=user_id,
grades=grades,
assessment_grades=assessment_grades,
overall_grade=overall_grade,
letter_grade=letter_grade)

Expand Down Expand Up @@ -393,8 +393,9 @@ def stream():
yield from (
",".join(str(value) if not isinstance(value, float) else f"{value:.2f}" for value in [
students[grade["user_id"]], grade["user_id"], grade["letter_grade"], grade["overall_grade"],
*[float(assessment["credit"]) for assessment in dojo.course["assessments"]],
*[float(assessment_grade["credit"]) for assessment_grade in grade["assessment_grades"]],
]) + "\n"
for grade in grades
)

headers = {"Content-Disposition": "attachment; filename=data.csv"}
Expand Down
18 changes: 9 additions & 9 deletions dojo_theme/templates/course.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ <h3>{{ name }} current overall grade in the class: <code style="font-size: 2em">
</tr>
</thead>
<tbody>
{% for grade in grades %}
{% if grade.credit is boolean %}
{% set credit = "✓" if grade.credit else "✕" %}
{% elif grade.credit is number %}
{% for assessment_grade in assessment_grades %}
{% if assessment_grade.credit is boolean %}
{% set credit = "✓" if assessment_grade.credit else "✕" %}
{% elif assessment_grade.credit is number %}
{% set credit = "%.2f%%" | format(100 * grade.credit) %}
{% endif %}
<tr>
<td>{{ grade.name }}</td>
<td>{{ grade.date }}</td>
<td>{{ grade.weight }}</td>
<td>{{ grade.progress }}</td>
<td>{{ assessment_grade.name }}</td>
<td>{{ assessment_grade.date }}</td>
<td>{{ assessment_grade.weight }}</td>
<td>{{ assessment_grade.progress }}</td>
<td>{{ credit }}</td>
</tr>
{% endfor %}
Expand All @@ -96,7 +96,7 @@ <h3>{{ name }} current overall grade in the class: <code style="font-size: 2em">
<b><label for="enter-name">{{ identity_name }}</label></b>
<small class="form-text text-muted">This will be shared with the admins of this dojo.</small>
<br>
<input class="form-control" id="identity" name="identity" type="text" value="{{ identity_value or "" }}">
<input class="form-control" id="identity" name="identity" type="text" value="{{ identity_value or '' }}">
</div>

<div id="identity-results" class="form-group">
Expand Down
18 changes: 9 additions & 9 deletions dojo_theme/templates/grades_admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ <h1>All Grades</h1>
</tr>
</thead>
<tbody>
{% for grade in user_grades.grades %}
{% for assessment_grade in user_grades.assessment_grades %}
<tr>
<td>{{ grade.name }}</td>
<td>{{ grade.date }}</td>
<td>{{ grade.weight }}</td>
<td>{{ grade.progress }}</td>
<td>{{ assessment_grade.name }}</td>
<td>{{ assessment_grade.date }}</td>
<td>{{ assessment_grade.weight }}</td>
<td>{{ assessment_grade.progress }}</td>
<td>
{% if grade.credit is boolean %}
{{ "✓" if grade.credit else "✕" }}
{% elif grade.credit is number %}
{{ "%.2f%%" | format(100 * grade.credit) }}
{% if assessment_grade.credit is boolean %}
{{ "✓" if assessment_grade.credit else "✕" }}
{% elif assessment_grade.credit is number %}
{{ "%.2f%%" | format(100 * assessment_grade.credit) }}
{% endif %}
</td>
</tr>
Expand Down

0 comments on commit 1b8e8ef

Please sign in to comment.