def populate_all_grades(self): """ calling this method calls Grade.populate_grade on each combination of enrolled_student + marking_period + course_section """ for student in self.enrollments.all(): for marking_period in self.marking_period.all(): Grade.populate_grade(student=student, marking_period=marking_period, course_section=self)
def test_scaled_multiple_mp_average(self): test_data = [ [[self.data.mp1.id, self.data.mp2.id, self.data.mps1x.id], Decimal(1.9)], [[self.data.mp3.id, self.data.mp4.id, self.data.mps2x.id], Decimal(2.1)], ] for x in test_data: average = Grade.get_scaled_multiple_mp_average(self.data.student, x[0], rounding=1) self.assertAlmostEqual(average, x[1])
def get_scaled_multiple_mp_average_by_indices(self, indices, rounding=2): """ Get a scaled mulitple marking period average for this student Requires that the property mps be set previously. This function exists mainly for appy based report cards where speed, and simplicity (in the template) are important. """ from ecwsp.grades.models import Grade mps = [ self.mps[i] for i in indices ] return Grade.get_scaled_multiple_mp_average(self, mps, rounding)
def handle(self, *args, **options): this_folder = os.path.dirname(os.path.realpath(__file__)) output_file_path = this_folder + "/grades.txt" lines = [] with open(output_file_path, "r") as f: for line in f: line = line.strip('\n') lines.append(line) with transaction.atomic(): new_grades = [] for line in lines: grade_data = line.split(',') course_section_id = int(grade_data[0]) if grade_data[1] == "None": marking_period_id = None else: marking_period_id = int(grade_data[1]) student_id = int(grade_data[2]) if grade_data[3] == "None": grade_decimal = None else: grade_decimal = Decimal(grade_data[3]) if grade_data[4] == "False": override_final = False else: override_final = True # the filter below should only return 1 response since # the combo of section, student, and period is guaranteed # to be unique in our db. We could just use a get_or_create # but the get() and the save() each time takes forver num_updated = Grade.objects.filter( course_section_id=course_section_id, marking_period_id=marking_period_id, student_id=student_id).update( override_final=override_final, grade=grade_decimal) if num_updated == 0: # the grade didn't exist, so the update above did nothing, # let's just create a new grade and save it at the end # using the bulk_create method which is much faster # than calling save() each time new_grade = Grade( course_section_id=course_section_id, marking_period_id=marking_period_id, student_id=student_id, grade=grade_decimal, override_final=override_final, ) new_grades.append(new_grade) Grade.objects.bulk_create(new_grades)
def validate_grade(self, value): Grade.validate_grade(value) return value
def validate_grade(self, attrs, source): value = attrs[source] Grade.validate_grade(value) return attrs
def test_current_vs_older(self): self.student = Student(first_name='Billy', last_name='Bob', username='******', id=12345) self.student.save() self.year = SchoolYear(name='2011-2012', start_date='2011-09-10', end_date='2012-06-15', grad_date='2012-06-17', id=2011) self.year.save() self.mp = MarkingPeriod(name="tri1 2011", start_date='2011-09-10', end_date='2012-06-15', school_year=self.year, monday=True, friday=True) self.mp.save() self.mp2 = MarkingPeriod(name="tri2 2012", start_date='2011-09-10', end_date='2012-06-15', school_year=self.year, monday=True, friday=True) self.mp2.save() self.mp3 = MarkingPeriod(name="tri3 2012", start_date='2011-09-10', end_date='2012-06-15', school_year=self.year, monday=True, friday=True) self.mp3.save() courses = [ Course(fullname='Algebra', shortname='alg', id=12, credits=4), Course(fullname='English', shortname='eng', id=13, credits=4), Course(fullname='History', shortname='hist', id=14, credits=4) ] course_sections = [] for course in courses: course.save() course_section = CourseSection(course=course, name=course.fullname) course_section.save() course_sections.append(course_section) course_sections[0].marking_period.add(self.mp) course_sections[1].marking_period.add(self.mp2) course_sections[2].marking_period.add(self.mp3) grades = [ Grade(student=self.student, course_section=course_sections[0], grade=86.78, marking_period=self.mp), Grade(student=self.student, course_section=course_sections[1], grade=94.73, marking_period=self.mp2), Grade(student=self.student, course_section=course_sections[2], grade=77.55, marking_period=self.mp3) ] for grade in grades: grade.save() course_enrollments = [ CourseEnrollment(user=self.student, course_section=course_sections[0], grade=grades[0]), CourseEnrollment(user=self.student, course_section=course_sections[1], grade=grades[1]), CourseEnrollment(user=self.student, course_section=course_sections[2], grade=grades[2]) ] for course_enrollment in course_enrollments: course_enrollment.save() StudentYearGrade.objects.create(student=self.student, year=self.year) syg = self.student.studentyeargrade_set.get(year=self.year) current = syg.calculate_grade_and_credits( date_report=datetime.date.today()) older = syg.calculate_grade_and_credits() self.assertEqual(current, older)