Skip to content

Commit

Permalink
Bugfix conjunctavgsurvey: submission needs assignment
Browse files Browse the repository at this point in the history
Also rewrote the code to be more readable (and literate).
  • Loading branch information
dbosk committed Jan 7, 2025
1 parent 5c870aa commit 51d7606
Showing 1 changed file with 65 additions and 25 deletions.
90 changes: 65 additions & 25 deletions src/canvaslms/grades/conjunctavgsurvey.nw
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def summarize(user, assignments_list):
for assignment in assignments_list:
try:
submission = assignment.get_submission(user,
include=["submission_history"])
include=["submission_history"])
submission.assignment = assignment
except ResourceDoesNotExist:
pf_grades.append("F")
continue
Expand All @@ -76,34 +77,73 @@ def summarize(user, assignments_list):
if grade is None:
grade = "F"

if grade in "ABCDE":
a2e_grades.append(grade)
elif grade in "PF":
pf_grades.append(grade)
elif grade == "Fx":
pf_grades.append("F")
else:
pf_grades.append("P")
<<add grade to the appropriate list>>
<<add grade date to the list [[dates]]>>

grade_date = submission.submitted_at or submission.graded_at
<<let [[final_grade]] be the final grade>>
<<let [[final_date]] be the final date>>

if grade_date:
grade_date = dt.date.fromisoformat(grade_date.split("T")[0])
dates.append(grade_date)
<<check that the data is correct>>

if all(map(lambda x: x == "P", pf_grades)):
final_grade = "P"
if a2e_grades:
final_grade = a2e_average(a2e_grades)
return (final_grade, final_date, graders)
@

if dates:
final_date = max(dates)
else:
final_date = None
final_grade = None
We look at the grade and add it to the appropriate list.
The grade Fx is treated as an F.
It's the only grade that should be more than one letter.
<<add grade to the appropriate list>>=
if grade in "ABCDE":
a2e_grades.append(grade)
elif grade in "PF":
pf_grades.append(grade)
elif grade == "Fx":
pf_grades.append("F")
else:
pf_grades.append("P")
@

if len(dates) < len(pf_grades) + len(a2e_grades):
final_grade = "F"
When we check, we check that all the P/F grades are P.
If that's the case, we can compute the average of the A--E grades---if there
are any.
If there are no A--E grades, the final grade is P.
<<let [[final_grade]] be the final grade>>=
if all(map(lambda x: x == "P", pf_grades)):
final_grade = "P"
if a2e_grades:
final_grade = a2e_average(a2e_grades)
else:
final_grade = "F"
@

return (final_grade, final_date, graders)
When it comes to the date, we want primarily the submission date.
If there is no submission date, we use the grade date.
(However, when we require the student to present their work, we should probably
use the grade date as that best represents the date of presenting.)
<<add grade date to the list [[dates]]>>
grade_date = submission.submitted_at or submission.graded_at

if grade_date:
grade_date = dt.date.fromisoformat(grade_date.split("T")[0])
dates.append(grade_date)
@

When we check the dates, we want the final date to be the most recent date.
If there are no dates, the student hasn't done anything, then we set the final
grade (and date) to [[None]] instead of F.
<<let [[final_date]] be the final date>>=
if dates:
final_date = max(dates)
else:
final_date = None
final_grade = None
@

Finally, as a check, we can check that the number of dates and number of grades
are the same.
Otherwise, they have passed everything they have done, but simply not done some
assignment.
<<check that the data is correct>>=
if len(dates) < len(pf_grades) + len(a2e_grades):
final_grade = "F"
@

0 comments on commit 51d7606

Please sign in to comment.