-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Populate passing DEDP grades that were set to None by Admin (#1787)
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
courses/migrations/0040_populate_none_letter_grades_for_DEDP.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Generated by Django 3.2.18 on 2023-07-27 19:33 | ||
from django.db import migrations | ||
|
||
|
||
def convert_to_letter(grade): | ||
"""Convert a decimal number to letter grade""" | ||
if grade >= 0.825: | ||
return "A" | ||
elif grade >= 0.65: | ||
return "B" | ||
elif grade >= 0.55: | ||
return "C" | ||
elif grade >= 0.50: | ||
return "D" | ||
else: | ||
return "F" | ||
|
||
|
||
def populate_letter_grade(apps, schema_editor): | ||
"""Populate letter grades for DEDP courses that were set to None by admin""" | ||
CourseRunGrade = apps.get_model("courses", "CourseRunGrade") | ||
course_ids = [ | ||
"course-v1:MITxT+14.100x", | ||
"course-v1:MITxT+14.750x", | ||
"course-v1:MITxT+14.740x", | ||
"course-v1:MITxT+JPAL102x", | ||
"course-v1:MITxT+14.73x", | ||
"course-v1:MITxT+14.310x", | ||
"course-v1:MITxT+14.009x", | ||
] | ||
grades = CourseRunGrade.objects.filter( | ||
passed=True, | ||
course_run__course__readable_id__in=course_ids, | ||
letter_grade=None, | ||
set_by_admin=True, | ||
) | ||
for grade in grades: | ||
grade.letter_grade = convert_to_letter(grade.grade) | ||
grade.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("courses", "0039_program_program_type"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(populate_letter_grade, migrations.RunPython.noop), | ||
] |