Skip to content

Commit

Permalink
add migration to fix letter grade set by 0033
Browse files Browse the repository at this point in the history
  • Loading branch information
rachellougee committed Jun 30, 2023
1 parent 0263c52 commit f851bd8
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions courses/migrations/0036_update_letter_grades_for_dedp.py
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),
]

0 comments on commit f851bd8

Please sign in to comment.