Skip to content

Commit

Permalink
Populate letter grades for 3T2022 (#1754)
Browse files Browse the repository at this point in the history
  • Loading branch information
annagav authored Jul 17, 2023
1 parent 9669d31 commit 7070d81
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions courses/migrations/0038_populate_letter_grades_3T2022.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Generated by Django 3.2.18 on 2023-07-17 12:19
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 for 3T2022 semester"""
CourseRunGrade = apps.get_model("courses", "CourseRunGrade")
course_run_ids = [
"course-v1:MITxT+14.100x+3T2022",
"course-v1:MITxT+14.750x+3T2022",
"course-v1:MITxT+JPAL102x+3T2022",
"course-v1:MITxT+14.73x+3T2022",
"course-v1:MITxT+14.310x+3T2022",
]

grades = CourseRunGrade.objects.filter(
passed=True,
letter_grade__contains="Pass",
course_run__courseware_id__in=course_run_ids,
)
for grade in grades:
grade.letter_grade = convert_to_letter(grade.grade)
grade.set_by_admin = True
grade.save()


class Migration(migrations.Migration):

dependencies = [
("courses", "0037_update_programrequirements_add_elective_flag"),
]

operations = [
migrations.RunPython(populate_letter_grade, migrations.RunPython.noop),
]

0 comments on commit 7070d81

Please sign in to comment.