app/helpers/course_summaries_helper.rb
# Update student hashes with weighted grades for every marking scheme.
Update student hashes with weighted grades for every marking scheme.
Update student hashes with weighted grades for every marking scheme .
def calculate_course_grades(course, students)
    course.marking_schemes.find_each do |scheme|
      students.each do |_, student|
        student[:weighted_marks] ||= {}
        weighted = 0
        scheme.marking_weights.each do |mw|
          if mw.assessment.type == 'Assignment'
            max_mark = @max_marks[mw.assessment_id]
          else
            max_mark = @gef_max_marks[mw.assessment_id]
          end
          mark = student[:assessment_marks][mw.assessment_id]&.[](:mark)
          unless mw.weight.nil? || mark.nil? || max_mark.nil? || max_mark == 0
            weighted += mark * mw.weight / max_mark
          end
        end
        student[:weighted_marks][scheme.id] = { mark: weighted.round(2).to_f, name: scheme.name }
      end
    end
  end
def calculate_course_grades ( course , students ) course . marking_schemes . find_each do | scheme | students . each do | _ , student | student [ :weighted_marks ] ||= { } weighted = 0 scheme . marking_weights . each do | mw | if mw . assessment . type == 'Assignment' max_mark = @max_marks [ mw . assessment_id ] else max_mark = @gef_max_marks [ mw . assessment_id ] end mark = student [ :assessment_marks ] [ mw . assessment_id ] &. [] ( :mark ) unless mw . weight . nil? || mark . nil? || max_mark . nil? || max_mark == 0 weighted += mark * mw . weight / max_mark end end student [ :weighted_marks ] [ scheme . id ] = { mark : weighted . round ( 2 ) . to_f , name : scheme . name } end end end
Update student hashes with weighted grades for every marking scheme.
Update student hashes with weighted grades for every marking scheme .
course
<not_specific>
students
<not_specific>