Module: Gaku::Grading::Calculations::InstanceMethods
- Defined in:
- lib/gaku/grading/calculations.rb
Instance Method Summary collapse
- #add_to_portion_attendance(student, exam, portion, score = nil) ⇒ Object
- #calculate_deviation ⇒ Object
- #calculate_exam_averages ⇒ Object
- #calculate_rank_and_grade ⇒ Object
- #calculate_totals ⇒ Object
- #grade_calculate(grading_method) ⇒ Object
- #grading_method_one(exam) ⇒ Object
- #grading_method_two(exam) ⇒ Object
- #initial_student_rank(exam) ⇒ Object
- #rank(exam) ⇒ Object
- #rank_calculate ⇒ Object
- #rank_nums(rank_levels) ⇒ Object
- #rank_score(exam, rank_nums) ⇒ Object
Instance Method Details
#add_to_portion_attendance(student, exam, portion, score = nil) ⇒ Object
35 36 37 38 |
# File 'lib/gaku/grading/calculations.rb', line 35 def add_to_portion_attendance(student, exam, portion, score = nil) score ||= portion.student_score(student) @student_portion_attendance[student.id][score.id] = [score.attendances.last.try(:id), score.attendances.last.try(:attendance_type).try(:color_code)] end |
#calculate_deviation ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/gaku/grading/calculations.rb', line 49 def calculate_deviation @deviation = Hash.new { |hash,key| hash[key] = {} } @standard_deviation = 0.0 @deviation_member = 0.0 @exams.each do |exam| @students.each do |student| if exam.use_weighting add_to_weighted_standard_deviation(exam, student) else add_to_standard_deviation(exam, student) end end standard_deviation(@standard_deviation) @students.each do |student| @deviation[student.id][exam.id] = 0.0 add_to_deviation_member(exam, student) add_to_deviation(exam, student) end end end |
#calculate_exam_averages ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/gaku/grading/calculations.rb', line 40 def calculate_exam_averages @students.each do |student| @exams.each do |exam| add_to_exam_averages(exam, student) add_to_weight_averages(exam, student) if exam.use_weighting end end end |
#calculate_rank_and_grade ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/gaku/grading/calculations.rb', line 71 def calculate_rank_and_grade @grades = Hash.new { |hash,key| hash[key] = {} } @scores = [] populate_student_scores # WIP Grade Calculation -----↓ # @grading_method = GradingMethod.find(exam.grading_method_id) # puts "@grading_method-------------" # puts @grading_method.name # eval @grading_method.method grading_method = 1 grade_calculate(grading_method) # Rank Calculation -----↓ rank_calculate end |
#calculate_totals ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/gaku/grading/calculations.rb', line 8 def calculate_totals @student_total_scores = Hash.new { |hash,key| hash[key] = {} } @student_total_weights = Hash.new { |hash,key| hash[key] = {} } @completion = Hash.new { |hash,key| hash[key] = {} } @exam_averages = Hash.new [] @exam_weight_averages = Hash.new [] @weighting_score = true @student_portion_attendance = Hash.new { |hash,key| hash[key] = {} } @students.each do |student| @exams.each do |exam| caluculate_completion(exam) @student_total_scores[student.id][exam.id] = 0.0 @student_total_weights[student.id][exam.id] = 0.0 exam.exam_portions.each do |portion| if have_portion_score?(student, portion) add_to_student_total_score(student, exam, portion) add_to_student_total_weight(student,exam, portion) if exam.use_weighting add_to_portion_attendance(student, exam, portion) else score = create_new_portion_score(student,portion) add_to_portion_attendance(student, exam, portion, score) end end end end end |
#grade_calculate(grading_method) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/gaku/grading/calculations.rb', line 189 def grade_calculate(grading_method) @gradePoint = 10 @grade_levels_deviation = [10000000000, 66, 62, 58, 55, 59, 45, 37, 0] @grade_levels_percent = [5, 5, 10, 10, 30, 10, 100] @exams.each do |exam| case grading_method when 1 grading_method_one(exam) when 2 grading_method_two(exam) end end end |
#grading_method_one(exam) ⇒ Object
204 205 206 207 208 209 210 211 212 213 |
# File 'lib/gaku/grading/calculations.rb', line 204 def grading_method_one(exam) @grade_levels_deviation.each_with_index do |glevel, i| @students.each do |student| if @grade_levels_deviation[i] > @deviation[student.id][exam.id] && @grade_levels_deviation[i+1] <= @deviation[student.id][exam.id] @grades[exam.id][student.id] = @gradePoint end end @gradePoint -= 1 end end |
#grading_method_two(exam) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/gaku/grading/calculations.rb', line 215 def grading_method_two(exam) scoresMem = @scores.clone gradeNums = [] @grade_levels_percent.each do |glevel| gradeNums.push((@students.length * (glevel.to_f / 100)).ceil) end gradeNums.each do |gnum| i = 0 while i < gnum && scoresMem.length != 0 @grades[exam.id][scoresMem.shift[1]] = gradePoint i += 1 end @gradePoint -= 1 end end |
#initial_student_rank(exam) ⇒ Object
249 250 251 |
# File 'lib/gaku/grading/calculations.rb', line 249 def initial_student_rank(exam) @students.each {|student| @ranks[exam.id][student.id] = 3 } end |
#rank(exam) ⇒ Object
266 267 268 269 270 271 272 273 274 |
# File 'lib/gaku/grading/calculations.rb', line 266 def rank(exam) @scores.each do |score| if @grades[exam.id][score[1]] == 3 @ranks[exam.id][score[1]] = 2 elsif @grades[exam.id][score[1]] < 3 @ranks[exam.id][score[1]] = 1 end end end |
#rank_calculate ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/gaku/grading/calculations.rb', line 231 def rank_calculate @rank_point = 5 @ranks = Hash.new { |hash,key| hash[key] = {} } rank_levels = [15, 20] @exams.each do |exam| initial_student_rank(exam) rank_nums = rank_nums(rank_levels) rank_score(exam,rank_nums) rank(exam) end end |
#rank_nums(rank_levels) ⇒ Object
243 244 245 246 247 |
# File 'lib/gaku/grading/calculations.rb', line 243 def rank_nums(rank_levels) rank_nums = [] rank_levels.each {|rlevel| rank_nums.push((@students.length * (rlevel.to_f / 100)).ceil)} rank_nums end |
#rank_score(exam, rank_nums) ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/gaku/grading/calculations.rb', line 253 def rank_score(exam,rank_nums) rank_nums.each do |rnum| i = 0 while i < rnum && @scores.length != 0 scoreMem = @scores.shift @ranks[exam.id][scoreMem[1]] = @rank_point rnum += 1 if @scores.length != 0 && scoreMem[0] == @scores[0][0] i += 1 end @rank_point -= 1 end end |