diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index c76bbd7b6..20cdc6659 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -382,6 +382,7 @@ class StudentWorkController < ApplicationController def set_program_score stundet_work = StudentWork.find_by_id params[:student_work_id] @course = stundet_work.homework_common.course + student_score_count = 0 if stundet_work && params[:results] && params[:results].class.to_s == "Array" homework_common = stundet_work.homework_common params[:results].each do |result| @@ -391,9 +392,28 @@ class StudentWorkController < ApplicationController student_work_test.student_work = stundet_work student_work_test.homework_test = homework_test student_work_test.result = result[:status] + if student_work_test.result == 0 + student_score_count += 1 + end student_work_test.save! end end + unless homework_common.homework_tests.empty? + stundet_work.student_score = student_score_count * 100.0 / homework_common.homework_tests.count + + if stundet_work.teacher_score.nil? + if stundet_work.teaching_asistant_score.nil? + stundet_work.final_score = stundet_work.student_score + else + final_ta_score = BigDecimal.new("#{stundet_work.teaching_asistant_score}") * BigDecimal.new("#{homework_common.homework_detail_programing.ta_proportion}") + final_s_score = BigDecimal.new("#{stundet_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{homework_common.homework_detail_programing.ta_proportion}")) + final_score = final_ta_score + final_s_score + stundet_work.final_score = format("%.1f",final_score.to_f) + end + end + + stundet_work.save! + end end end