diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 796d541ca..7320820bd 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1153,7 +1153,7 @@ class CoursesController < ApplicationController sql_select = "" if groupid == 0 sql_select = "SELECT members.*,( - SELECT SUM(IF(student_works.final_score IS NULL,NULL,IF(student_works.final_score =0,0,IF((student_works.final_score - student_works.absence_penalty - student_works.late_penalty) < 0 , 0, student_works.final_score - student_works.absence_penalty - student_works.late_penalty)))) + SELECT SUM(student_works.work_score) FROM student_works,homework_commons WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{@course.id} @@ -1165,7 +1165,7 @@ class CoursesController < ApplicationController WHERE members.course_id = #{@course.id} ORDER BY score #{score_sort_by}" else sql_select = "SELECT members.*,( - SELECT SUM(IF(student_works.final_score IS NULL,NULL,IF(student_works.final_score =0,0,IF((student_works.final_score - student_works.absence_penalty - student_works.late_penalty) < 0 , 0, student_works.final_score - student_works.absence_penalty - student_works.late_penalty)))) + SELECT SUM(student_works.work_score) FROM student_works,homework_commons WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{@course.id} diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 31daba728..909c68715 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -5,7 +5,7 @@ class StudentWorkController < ApplicationController include ApplicationHelper require 'bigdecimal' require "base64" - before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:program_test_ex,:code_repeattest,:work_canrepeat,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students] + before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:program_test_ex,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students] before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment] before_filter :member_of_course, :only => [:new, :create, :show, :add_score, :praise_student_work] before_filter :author_of_work, :only => [:edit, :update, :destroy] @@ -81,8 +81,6 @@ class StudentWorkController < ApplicationController #根据传入的tIndex确定是第几次测试 #之后如果觉得很卡 可以改成将结果传回JS再以参数形式传回来 def program_test_ex - tStarttime = Time.now - is_test = params[:is_test] == 'true' resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T'),tseq:1,tcount:1,testid:1} #保存每测试一次返回的结果 @@ -100,17 +98,8 @@ class StudentWorkController < ApplicationController test = @homework.homework_tests[index - 1] #请求测试 - begin - result = test_realtime_ex(test, params[:src]) - rescue Timeout::Error - tEndtime = Time.now - tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000 - logger.debug "program_test_ex user wait time = #{tUsedtime} 毫秒" + result = test_realtime_ex(test, params[:src]) - #status 0:答案正确 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时 - CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>-3,:wait_time=>tUsedtime,:student_work_id=>student_work.id) - - end if result["status"].to_i != -2 #result["results"].first['output'] = result["results"].first['output'].gsub(" ","□") #result["results"].first['result'] = result["results"].first['result'].gsub(" ","□") @@ -125,19 +114,11 @@ class StudentWorkController < ApplicationController resultObj[:results] = result["results"].first #本次测试结果 resultObj[:error_msg] = result["error_msg"] #编译错误时的信息 - #该状态用于存入CodeTests - tmpstatus = -1 if result["status"].to_i == -2 #编译错误 resultObj[:results] = result["error_msg"] resultObj[:status] = -2 - tmpstatus = -2 elsif result["results"][0]["status"].to_i == 2 resultObj[:status] = 2 - tmpstatus = 2 - end - - if result["status"] == 0 - tmpstatus = 0 end unless student_work.save @@ -153,14 +134,6 @@ class StudentWorkController < ApplicationController end #每次从数据库取出上次的结果加上本次的结果再存入数据库 - if result["status"].to_i != -2 - result["results"].first['user_wait'] = tUsedtime - - if result["results"][0]["status"].to_i == 2 - result["status"] = 2 - end - end - status = result["status"] if index == 1 student_work_test = student_work.student_work_tests.build(status: status, @@ -189,19 +162,6 @@ class StudentWorkController < ApplicationController resultObj[:index] = student_work.student_work_tests.count end - #将每次用户等待时间都存起来以便管理界面显示用 - tEndtime = Time.now - tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000 - logger.debug "program_test_ex user wait time = #{tUsedtime} 毫秒" - - time_used = 0 - if result["status"].to_i != -2 - #至少一毫秒 - time_used = result["results"].first['time_used'] == 0 ? 1:result["results"].first['time_used'] - end - #0:答案正确 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时 - CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>time_used,:wait_time=>tUsedtime,:student_work_id=>student_work.id) - #渲染返回结果 render :json => resultObj end @@ -209,114 +169,6 @@ class StudentWorkController < ApplicationController end end - #找出该作业的所有提交作业 - def find_all_student_work_by_homeid() - all_studentwork = StudentWork.where("homework_common_id =#{@homework.id} and is_test = 0 ") - - all_studentwork - end - - def request_code_repeattest(src) - url = "#{Redmine::Configuration['jplag_server']}api/realtime_test.json" - - factor = [] - src.each do |test| - factor << {work_id: test.id, des: test.description,created_at:test.created_at.to_i} - end - - solutions = { - homeid:@homework.id, - language:@homework.homework_detail_programing.language, - factor: factor - } - uri = URI(url) - body = solutions.to_json - - logger.debug "send body" - logger.debug body - - res = Net::HTTP.new(uri.host, uri.port).start do |client| - request = Net::HTTP::Post.new(uri.path) - request.body = body - request["Content-Type"] = "application/json" - client.request(request) - end - - JSON.parse(res.body) - end - - #点击代码查重按钮 - def work_canrepeat - @homework_id = params[:homework] - @course_id = params[:course_id] - - all_studentwork = find_all_student_work_by_homeid() - - @work_count = all_studentwork.count - end - - #代码查重 status: 0完成 -2不需要查重 -1查重失败不支持该语言 - def code_repeattest - tStarttime = Time.now - logger.debug "code_repeattest start is #{tStarttime}}" - resultObj = {status: -2} - - @homework = HomeworkCommon.find params[:homework] - - all_studentwork = find_all_student_work_by_homeid() - - if all_studentwork == nil - resultObj[:status] = -2 - elsif all_studentwork.count <= 1 - resultObj[:status] = -2 - else - - #@homework.homework_detail_programing.language、id、description - logger.debug "time1 is #{Time.now.usec} " - result = request_code_repeattest(all_studentwork) - logger.debug "time2 is #{Time.now.usec} " - - resultObj[:status] = result['status'].to_i - # resultObj[:results] = result['results'] - - #Time.now, simi_id = simiworkid , simi_value = simivalue - if resultObj[:status] == 0 - @homework.simi_time = Time.now - resultObj[:comparetime] = @homework.simi_time - @homework.update_column('simi_time', @homework.simi_time) - - logger.debug "time3 is #{Time.now.usec} " - result['results'].each do |key,value| - @student_work = StudentWork.where("id =?", key.to_i).first - @student_work.update_column('simi_id', value['simiworkid'].to_i) - @student_work.update_column('simi_value', value['simivalue'].to_i) - # sqlstr = "update student_works set simi_id=#{value['simiworkid']},simi_value=#{value['simivalue']} where id=#{key.to_i} " - # dbh.execute(sqlstr) - end - logger.debug "time4 is #{Time.now.usec} " - end - end - tEndtime = Time.now - logger.debug "code_repeattest end is #{tEndtime}}" - tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000000+(tEndtime.usec - tStarttime.usec) - logger.debug "code_repeattest userd utime is #{tUsedtime}" - render :json => resultObj - end - - #上次代码查重时间 - def last_codecomparetime - resultObj = {status: 0} - @homework = HomeworkCommon.find params[:homework] - - #转换一下 - if @homework.simi_time != nil - resultObj[:comparetime] = Time.parse(@homework.simi_time.to_s).strftime("%Y-%m-%d %H:%M:%S") - else - resultObj[:comparetime] = 0 - end - - render :json => resultObj - end def index # 作业消息状态更新 @@ -372,11 +224,11 @@ class StudentWorkController < ApplicationController #开放作品 || 老师 || 超级管理员 || 禁用匿评&&作业截止&&已提交作品 显示所有列表 if @homework.is_open == 1 || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) if @order == 'lastname' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name elsif @order == 'student_id' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name else - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name end @show_all = true elsif User.current.member_of_course?(@course) @@ -386,10 +238,10 @@ class StudentWorkController < ApplicationController if pro.nil? @stundet_works = [] else - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:id => pro.student_work_id) + @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id) end else - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:user_id => User.current.id) + @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) end elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 if @homework.homework_type == 3 @@ -409,20 +261,20 @@ class StudentWorkController < ApplicationController if pro.nil? my_work = [] else - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:id => pro.student_work_id) + my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id) end else - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:user_id => User.current.id) + my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) end if my_work.empty? @stundet_works = [] else if @order == 'lastname' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name elsif @order == 'student_id' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name else - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name end @show_all = true end @@ -434,15 +286,15 @@ class StudentWorkController < ApplicationController return end - @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name).count + @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).where("users.id in #{student_in_group}").order("#{@order} #{@b_sort}"),@name).count else if @homework.is_open == 1 || @is_teacher || User.current.admin? || (User.current.member_of_course?(@course) && @homework.anonymous_comment == 1 && Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") && !@homework.student_works.where(:user_id => User.current.id).empty?) if @order == 'lastname' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name elsif @order == 'student_id' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name else - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name end @show_all = true elsif User.current.member_of_course?(@course) @@ -452,10 +304,10 @@ class StudentWorkController < ApplicationController if pro.nil? @stundet_works = [] else - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:id => pro.student_work_id) + @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id) end else - @stundet_works = @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:user_id => User.current.id) + @stundet_works = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) end elsif @homework.homework_detail_manual.comment_status == 2 #学生 && 开启匿评 看到匿评列表 if @homework.homework_type == 3 @@ -475,20 +327,20 @@ class StudentWorkController < ApplicationController if pro.nil? my_work = [] else - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:id => pro.student_work_id) + my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:id => pro.student_work_id) end else - my_work = @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").where(:user_id => User.current.id) + my_work = @homework.student_works.select("student_works.*,student_works.work_score as score").where(:user_id => User.current.id) end if my_work.empty? @stundet_works = [] else if @order == 'lastname' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins(:user).order("CONVERT(lastname USING gbk) COLLATE gbk_chinese_ci #{@b_sort}, login #{@b_sort}"),@name elsif @order == 'student_id' - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").joins("join user_extensions on student_works.user_id = user_extensions.user_id").order("#{@order} #{@b_sort}"),@name else - @stundet_works = search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("#{@order} #{@b_sort}"),@name + @stundet_works = search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name end @show_all = true end @@ -499,8 +351,7 @@ class StudentWorkController < ApplicationController render_403 return end - - @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as score").order("#{@order} #{@b_sort}"),@name).count + @student_work_count = (search_homework_member @homework.student_works.select("student_works.*,student_works.work_score as score").order("#{@order} #{@b_sort}"),@name).count end @score = @b_sort == "desc" ? "asc" : "desc" @@ -1311,6 +1162,7 @@ class StudentWorkController < ApplicationController if homework.teacher_priority == 1 #教师优先 if student_work.teacher_score student_work.final_score = student_work.teacher_score + student_work.work_score = student_work.teacher_score else if student_work.teaching_asistant_score.nil? student_work.final_score = student_work.student_score @@ -1323,6 +1175,8 @@ class StudentWorkController < ApplicationController final_score = final_ta_score + final_s_score student_work.final_score = format("%.2f",final_score.to_f) end + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score end else #不考虑教师评分 if student_work.teaching_asistant_score.nil? @@ -1336,11 +1190,14 @@ class StudentWorkController < ApplicationController final_score = final_ta_score + final_s_score student_work.final_score = format("%.2f",final_score.to_f) end + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score end elsif homework.homework_type == 2 && homework.homework_detail_programing #编程作业-----设定:系统评分必定不为空 if homework.teacher_priority == 1 #教师优先 if student_work.teacher_score student_work.final_score = student_work.teacher_score + student_work.work_score = student_work.teacher_score else if student_work.teaching_asistant_score.nil? #教辅未评分 if student_work.student_score.nil? @@ -1369,6 +1226,8 @@ class StudentWorkController < ApplicationController final_score = final_sy_score + final_ts_score + final_st_score student_work.final_score = format("%.2f",final_score.to_f) end + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score end else #不考虑教师评分 if student_work.teaching_asistant_score.nil? #教辅未评分 @@ -1398,6 +1257,8 @@ class StudentWorkController < ApplicationController final_score = final_sy_score + final_ts_score + final_st_score student_work.final_score = format("%.2f",final_score.to_f) end + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score end end end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 3a6b347b3..c10652c6f 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -850,7 +850,7 @@ module CoursesHelper # 学生按作业总分排序,取前8个 def hero_homework_score(course, score_sort_by) sql_select = "SELECT members.*,( - SELECT SUM(IF(student_works.final_score IS NULL,NULL,IF(student_works.final_score =0,0,IF((student_works.final_score - student_works.absence_penalty - student_works.late_penalty) < 0 , 0, student_works.final_score - student_works.absence_penalty - student_works.late_penalty)))) + SELECT SUM(work_score) FROM student_works,homework_commons WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{course.id} diff --git a/app/models/member.rb b/app/models/member.rb index cc227cf31..3cb70a8fe 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -150,7 +150,7 @@ class Member < ActiveRecord::Base #当前学生在指定作业内的得分 def homework_common_score homework_common - StudentWork.select("IF(final_score is null,null,IF(final_score = 0, 0, final_score - absence_penalty - late_penalty)) as final_score").where(:homework_common_id => homework_common.id,:user_id => self.user_id) + StudentWork.select("work_score").where(:homework_common_id => homework_common.id,:user_id => self.user_id) end def student_work_score_avg @@ -158,7 +158,7 @@ class Member < ActiveRecord::Base end def student_work_score_sum - sql_select = "SELECT (SUM(IF(student_works.final_score IS NULL,NULL,IF(student_works.final_score =0,0,IF((student_works.final_score - student_works.absence_penalty - student_works.late_penalty) < 0 , 0, student_works.final_score - student_works.absence_penalty - student_works.late_penalty))))) AS score + sql_select = "SELECT (SUM(student_works.work_score)) AS score FROM student_works,homework_commons WHERE student_works.homework_common_id = homework_commons.id AND homework_commons.course_id = #{self.course_id} diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 82b1ad4a1..3abd4276a 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -50,6 +50,7 @@ class StudentWork < ActiveRecord::Base if homework.teacher_priority == 1 #教师优先 if student_work.teacher_score student_work.final_score = student_work.teacher_score + student_work.work_score = student_work.teacher_score else if student_work.teaching_asistant_score.nil? student_work.final_score = student_work.student_score @@ -62,6 +63,8 @@ class StudentWork < ActiveRecord::Base final_score = final_ta_score + final_s_score student_work.final_score = format("%.2f",final_score.to_f) end + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score end else #不考虑教师评分 if student_work.teaching_asistant_score.nil? @@ -75,11 +78,14 @@ class StudentWork < ActiveRecord::Base final_score = final_ta_score + final_s_score student_work.final_score = format("%.2f",final_score.to_f) end + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score end elsif homework.homework_type == 2 && homework.homework_detail_programing #编程作业-----设定:系统评分必定不为空 if homework.teacher_priority == 1 #教师优先 if student_work.teacher_score student_work.final_score = student_work.teacher_score + student_work.work_score = student_work.teacher_score else if student_work.teaching_asistant_score.nil? #教辅未评分 if student_work.student_score.nil? @@ -108,6 +114,8 @@ class StudentWork < ActiveRecord::Base final_score = final_sy_score + final_ts_score + final_st_score student_work.final_score = format("%.2f",final_score.to_f) end + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score end else #不考虑教师评分 if student_work.teaching_asistant_score.nil? #教辅未评分 @@ -137,6 +145,8 @@ class StudentWork < ActiveRecord::Base final_score = final_sy_score + final_ts_score + final_st_score student_work.final_score = format("%.2f",final_score.to_f) end + score = student_work.final_score - student_work.absence_penalty - student_work.late_penalty if student_work.final_score + student_work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) if score end end end diff --git a/app/views/courses/_show_member_score.html.erb b/app/views/courses/_show_member_score.html.erb index 1fa9339e4..94d282cec 100644 --- a/app/views/courses/_show_member_score.html.erb +++ b/app/views/courses/_show_member_score.html.erb @@ -24,7 +24,7 @@ <% final_score = @member_score.homework_common_score(homework_common).first%> - <%= final_score.nil? || final_score.final_score.nil? ? "--" : format("%0.2f", final_score.final_score < 0 ? 0 : final_score.final_score) %> + <%= final_score.nil? || final_score.work_score.nil? ? "--" : format("%0.2f", final_score.work_score < 0 ? 0 : final_score.work_score) %> <% end %> diff --git a/app/views/praise_tread/_praise.html.erb b/app/views/praise_tread/_praise.html.erb index a1a34636f..d8a277592 100644 --- a/app/views/praise_tread/_praise.html.erb +++ b/app/views/praise_tread/_praise.html.erb @@ -1,11 +1,11 @@ <% if PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",activity.id,activity.class.to_s,User.current.id).empty? %> - + <% num = get_praise_num(activity) %> <%= num > 0 ? "(#{num})" : "" %> <% else %> - + 已赞 <% num = get_praise_num(activity) %> <%= num > 0 ? "(#{num})" : "" %> diff --git a/app/views/student_work/_evaluation_un_work.html.erb b/app/views/student_work/_evaluation_un_work.html.erb index 0a3796758..860c5936b 100644 --- a/app/views/student_work/_evaluation_un_work.html.erb +++ b/app/views/student_work/_evaluation_un_work.html.erb @@ -82,7 +82,11 @@ <% end %> - <% score = student_work.respond_to?("score") ? student_work.score : (student_work.final_score || 0) - student_work.absence_penalty - student_work.late_penalty%> + <% if student_work.homework_common && student_work.homework_common.teacher_priority == 1 && student_work.teacher_score %> + <% score = student_work.respond_to?("score") ? student_work.score : student_work.teacher_score %> + <% else %> + <% score = student_work.respond_to?("score") ? student_work.score : (student_work.final_score || 0) - student_work.absence_penalty - student_work.late_penalty%> + <% end %>
  • <%= score.nil? ? "--" : format("%.1f",score<0 ? 0 : score)%> <% unless score.nil?%> diff --git a/app/views/users/_homework_repository.html.erb b/app/views/users/_homework_repository.html.erb index a30e21a3f..1ed8ae688 100644 --- a/app/views/users/_homework_repository.html.erb +++ b/app/views/users/_homework_repository.html.erb @@ -14,11 +14,12 @@
    <% end %>
    \ No newline at end of file diff --git a/app/views/users/_homework_repository_list.html.erb b/app/views/users/_homework_repository_list.html.erb index 678bf65d7..2e483b3b3 100644 --- a/app/views/users/_homework_repository_list.html.erb +++ b/app/views/users/_homework_repository_list.html.erb @@ -30,6 +30,9 @@ <%= link_to "", user_search_homeworks_user_path(@user,:name=>search,:type => type,:is_import=>is_import,:property=>property,:order => "publish_time", :sort => @r_sort),:class => "#{@r_sort == 'desc' ? 'st_up' : 'st_down'} mt12 fl" ,:remote => true%> <% end%>
  • +
  • + 操作 +
  • <%=render :partial => 'homework_repository', :locals => {:homeworks => homeworks} %> diff --git a/app/views/users/user_homeworks.html.erb b/app/views/users/user_homeworks.html.erb index 2cd1f5b21..5eaf61569 100644 --- a/app/views/users/user_homeworks.html.erb +++ b/app/views/users/user_homeworks.html.erb @@ -41,7 +41,10 @@
  • 我的题库
  • -
  •  
  • +
  • + 申请题库 +
  • +
  •