diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 89f67ddf4..ae33ccb07 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -55,12 +55,34 @@ class StudentWorkController < ApplicationController render :json => resultObj end - $test_result = {} - $test_status = {} + #行尾空格替换成□ + def space_replace_1(str) + for i in 0 .. str.size + tChar = str[i] + if tChar != ' ' && tChar != "\n" + sFlag = false + eFlag = false + elsif tChar == ' ' && sFlag == false + tStart = i + sFlag = true + elsif tChar == "\n" + tEnd = i - 1 + if sFlag == true + for j in tStart .. tEnd + str[j] = "□" + end + sFlag = false + end + end + end + end + +#由于负载问题 不要使用全局变量 #根据传入的tIndex确定是第几次测试 +#之后如果觉得很卡 可以改成将结果传回JS再以参数形式传回来 def program_test_ex is_test = params[:is_test] == 'true' - resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T'),tseq:1,tcount:1} #保存每测试一次返回的结果 + resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T'),tseq:1,tcount:1,testid:1} #保存每测试一次返回的结果 student_work = find_or_save_student_work(is_test) @@ -77,14 +99,24 @@ class StudentWorkController < ApplicationController #请求测试 result = test_realtime_ex(test, params[:src]) - logger.debug result + + if result["status"].to_i != -2 + #result["results"].first['output'] = result["results"].first['output'].gsub(" ","□") + #result["results"].first['result'] = result["results"].first['result'].gsub(" ","□") + end + + space_replace_1(result["results"].first['output']) + space_replace_1(result["results"].first['result']) + + logger.debug result #-1 默认值 0全部正确并结束 2 超时 -2 编译错误 resultObj[:status] = -1 - resultObj[:results] = result["results"][0] #本次测试结果 + resultObj[:results] = result["results"].first #本次测试结果 resultObj[:error_msg] = result["error_msg"] #编译错误时的信息 if result["status"].to_i == -2 #编译错误 + resultObj[:results] = result["error_msg"] resultObj[:status] = -2 elsif result["results"][0]["status"].to_i == 2 resultObj[:status] = 2 @@ -93,25 +125,6 @@ class StudentWorkController < ApplicationController unless student_work.save resultObj[:status] = 200 else - - #索引 - work_id = student_work.id - - #测试第一个时初始化下全局变量 - if index == 1 - $test_result[work_id] = [] #保存本次测试的结果 输入输出 - $test_status[work_id] = 0 #保存本次测试的结果 正确还是错误 - end - - if result["status"].to_i == -2 - $test_result[work_id] = [result["error_msg"]] - $test_status[work_id] = -2 - else - #存下每次的结果 只有每次都为0才全部正确 - $test_status[work_id] = result["status"] != 0 ? result["status"]:$test_status[work_id] - $test_result[work_id][index - 1] = resultObj[:results] - end - student_work.name = params[:title] student_work.description = params[:src] @@ -121,20 +134,33 @@ class StudentWorkController < ApplicationController student_work.late_penalty = 0 end + #每次从数据库取出上次的结果加上本次的结果再存入数据库 + status = result["status"] + if index == 1 + student_work_test = student_work.student_work_tests.build(status: status, + results: [resultObj[:results]],src: params[:src]) + student_work_test.save! + resultObj[:testid] = student_work_test.id + else + #先从数据库取出result + student_work_test = StudentWorkTest.find(params[:testid]) + results = student_work_test.results + results << resultObj[:results] + student_work_test.results = results + student_work_test.status = (result["status"] != 0 ? result["status"] : student_work_test.status) + student_work_test.save! + status = student_work_test.status + resultObj[:testid] = student_work_test.id + end + #超时或编译错误则直接返回了并存入数据库 if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size - if $test_status[work_id] == 0 + if status == 0 resultObj[:status] = 0 end - - student_work_test = student_work.student_work_tests.build(status: $test_status[work_id], - results: $test_result[work_id],src: params[:src]) - student_work.save + student_work.save! resultObj[:time] = student_work_test.created_at.to_s(:db) resultObj[:index] = student_work.student_work_tests.count - - $test_result[work_id] = nil - $test_status[work_id] = nil end #渲染返回结果 diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index df5c872f8..4e11e153e 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -130,7 +130,7 @@ module StudentWorkHelper def revise_attachment_status homework, attach date = Time.parse(format_time(attach.created_on.to_s)).strftime("%Y-%m-%d") status = "" - if homework.homework_detail_manual && ((homework.anonymous_comment == 0 &&homework.homework_detail_manual.evaluation_start.to_s <= date) || (homework.anonymous_comment == 1 && homework.end_time < date)) + if homework.homework_detail_manual && ((homework.anonymous_comment == 0 &&homework.homework_detail_manual.evaluation_start.to_s <= date) || (homework.anonymous_comment == 1 && homework.end_time.to_s < date)) status = "此时其他同学作品已公开" else status = "此时其他同学作品尚未公开" diff --git a/app/views/courses/_recommendation.html.erb b/app/views/courses/_recommendation.html.erb index 63803a5b9..1db2edf57 100644 --- a/app/views/courses/_recommendation.html.erb +++ b/app/views/courses/_recommendation.html.erb @@ -7,8 +7,8 @@

<%=link_to e_course.name, course_path(e_course.id), :class => "hidden fl w170" %>

- <% if course_file_num > 0 %> - <%= l(:project_module_attachments) %>(<%= link_to course_file_num, course_files_path(e_course), :class => "linkBlue2" %>) + <% if visable_attachemnts_incourse(e_course).count > 0 %> + <%= l(:project_module_attachments) %>(<%= link_to visable_attachemnts_incourse(e_course).count, course_files_path(e_course), :class => "linkBlue2" %>) <% end %> <% if e_course.homework_commons.where("publish_time <= '#{Date.today}'").count > 0 %> <%= l(:label_homework_commont) %>(<%= link_to e_course.homework_commons.where("publish_time <= '#{Date.today}'").count, homework_common_index_path(:course=>e_course.id), :class => "linkBlue2" %>) diff --git a/app/views/layouts/_project_info.html.erb b/app/views/layouts/_project_info.html.erb index d94cbdcc7..30f527595 100644 --- a/app/views/layouts/_project_info.html.erb +++ b/app/views/layouts/_project_info.html.erb @@ -1,6 +1,7 @@ <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> <% teacher_num = TeacherAndAssistantCount(@course) %> <% student_num = studentCount(@course) %> +<% course_file_num = visable_attachemnts_incourse(@course).count %>