-
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.
add migration to fix letter grade set by 0033
- Loading branch information
1 parent
0263c52
commit f851bd8
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
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,60 @@ | ||
# Generated by Django 3.2.18 on 2023-06-30 20:33 | ||
|
||
import datetime | ||
|
||
import pytz | ||
from django.db import migrations | ||
|
||
from courses.models import Program | ||
|
||
|
||
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): | ||
"""Fix the letter grade for the DEDP courses prior to 3T2022 | ||
that was set by 0033_populate_letter_grades""" | ||
CourseRunGrade = apps.get_model("courses", "CourseRunGrade") | ||
Course = apps.get_model("courses", "Course") | ||
|
||
dedp_program = Program.objects.filter(readable_id="program-v1:MITx+DEDP").first() | ||
|
||
if dedp_program is not None: | ||
dedp_course_ids = [course[0].id for course in dedp_program.courses] | ||
# Good Economics for Hard Times need to be added | ||
dedp_course_ids.append( | ||
Course.objects.filter(readable_id="course-v1:MITxT+14.009x").first() | ||
) | ||
else: | ||
dedp_course_ids = [] | ||
|
||
grades = CourseRunGrade.objects.filter( | ||
passed=True, | ||
set_by_admin=True, | ||
course_run__course_id__in=dedp_course_ids, | ||
course_run__start_date__lt=datetime.datetime(2022, 9, 1, tzinfo=pytz.UTC), | ||
) | ||
for grade in grades: | ||
grade.letter_grade = convert_to_letter(grade.grade) | ||
grade.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("courses", "0035_merge_related_name_and_backfill_enrollments"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(populate_letter_grade, migrations.RunPython.noop), | ||
] |