diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 17111b3f3..b1d16debb 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -37,16 +37,6 @@ class MessagesController < ApplicationController # Show a topic and its replies def show -=begin - if @course - topic_id = params[:r]?params[:r]:params[:id] - parent_id = params[:id] - url = course_boards_path(@course,:topic_id => topic_id,:parent_id=>parent_id); - redirect_to url - return; - end -=end - @isReply = true page = params[:page] # Find the page of the requested reply @@ -54,16 +44,7 @@ class MessagesController < ApplicationController offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i]) page = 1 + offset / REPLIES_PER_PAGE end - @reply_count = @topic.children.count - # @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page - # @replies = @topic.children. - # includes(:author, :attachments, {:board => :project}). - # reorder("#{Message.table_name}.created_on DESC"). - # limit(@reply_pages.per_page). - # offset(@reply_pages.offset). - # all - @reply = Message.new(:subject => "RE: #{@message.subject}") if @course messages_replies = @topic.children. diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 6c86abf82..89f67ddf4 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -5,14 +5,14 @@ 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,: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] before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :set_score_rule, :forbidden_anonymous_comment] before_filter :is_logged, :only => [:index] - ### + ### def program_test is_test = params[:is_test] == 'true' resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T')} @@ -49,13 +49,102 @@ class StudentWorkController < ApplicationController resultObj[:time] = student_work_test.created_at.to_s(:db) resultObj[:index] = student_work.student_work_tests.count end - end end render :json => resultObj end + $test_result = {} + $test_status = {} +#根据传入的tIndex确定是第几次测试 + 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} #保存每测试一次返回的结果 + + student_work = find_or_save_student_work(is_test) + + resultObj[:tcount] = @homework.homework_tests.size + + unless student_work + resultObj[:status] = 100 + else + if @homework.homework_type == 2 && @homework.homework_detail_programing + #找到第index个测试的输入输出 + index = params[:tIndex].to_i + resultObj[:tseq] = index + test = @homework.homework_tests[index - 1] + + #请求测试 + result = test_realtime_ex(test, params[:src]) + logger.debug result + + #-1 默认值 0全部正确并结束 2 超时 -2 编译错误 + resultObj[:status] = -1 + resultObj[:results] = result["results"][0] #本次测试结果 + resultObj[:error_msg] = result["error_msg"] #编译错误时的信息 + + if result["status"].to_i == -2 #编译错误 + resultObj[:status] = -2 + elsif result["results"][0]["status"].to_i == 2 + resultObj[:status] = 2 + end + + 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] + + if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") + student_work.late_penalty = @homework.late_penalty + else + student_work.late_penalty = 0 + end + + #超时或编译错误则直接返回了并存入数据库 + if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size + if $test_status[work_id] == 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 + 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 + + #渲染返回结果 + render :json => resultObj + end + end + end + end + + def index # 作业消息状态更新 @homework.course_messages.each do |homework_message| @@ -996,7 +1085,6 @@ class StudentWorkController < ApplicationController student_work end - def test_realtime(student_work, src) url = "#{Redmine::Configuration['judge_server']}api/realtime_test.json" @@ -1020,6 +1108,28 @@ class StudentWorkController < ApplicationController JSON.parse(res.body) end + def test_realtime_ex(test, src) + url = "#{Redmine::Configuration['judge_server']}api/realtime_test.json" + + factor = [] + factor << {input: test.input, output: test.output} + + solutions = { + src:src, + language:@homework.homework_detail_programing.language, + factor: factor + } + uri = URI(url) + body = solutions.to_json + 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 set_final_score homework,student_work if homework && homework.homework_detail_manual diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 37c7deb4c..64531a6f4 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -24,40 +24,20 @@ module CoursesHelper def find_excelletn_course keywords, current_course # 获取tag匹配结果ID a_tags = [] - # kc = keywords.to_a - Course.visible.where("is_excellent =? and is_public =?", 1, 1).each do |ec| + Course.where("is_excellent =? and is_public =?", 1, 1).each do |ec| if ec.tags.any?{|value| current_course.name.include?(value.to_s)} a_tags << ec.id end end - # sql = "SELECT distinct c.* FROM `courses` c, tags t, taggings ts where t.id = ts.tag_id and ts.taggable_id = c.id and c.is_excellent = 1 and is_delete = 0 and - # ts.taggable_type = 'Course' and t.name like '%#{keywords}%'" - # a_tags = Course.find_by_sql(sql).select{|course| course.is_public ==1 unless User.current.member_of_course?(course)} - # 通过elastic结果获取精品课程 - a_courses = [] - #courses = Course.search(keywords) - #courses.each do |c| - # a_courses << c.id - #end - a_courses << a_tags unless a_tags.length == 0 # 课程本身不能搜索显示自己 - excellent_ids = a_courses.flatten.uniq.delete_if{|i| i == current_course.id} - limit = 5 - excellent_ids.length.to_i + excellent_ids = a_tags.uniq.delete_if{|i| i == current_course.id} sql = "SELECT distinct c.id FROM course_activities cs, courses c where cs.course_id = c.id - and c.is_excellent =1 and c.is_public = 1 and c.id != #{current_course.id} order by cs.updated_at desc;" - default_ecourse_ids = Course.find_by_sql(sql).flatten - # REDO:时间紧,待优化 - default_ids =[] - default_ecourse_ids.each do |de| - default_ids << de.id - end - default_ids = default_ids - excellent_ids - #default_ecourse = Course.where("id is not in (?)", ids).find_by_sql(sql).flatten.delete_if{|i| i == current_course.id}.flatten - arr_result = excellent_ids << default_ids - arr_result = arr_result.flatten.first(5) - return arr_result - # 过滤条件:精品课程、本身不在搜索范围 - #e_courses = Course.where("is_excellent =? and id in (?)",1, arr_result).where("id !=?", current_course.id) + and (c.is_excellent =1 or c.excellent_option =1) and c.is_public = 1 and c.id != #{current_course.id} order by cs.updated_at desc;" + default_ids = Course.find_by_sql(sql).flatten.map { |c| c.id } + excellent_ids << default_ids.flatten + arr_result = excellent_ids.flatten.uniq.first(5) + excellent_courses = Course.find(arr_result) + return excellent_courses end # 判断精品课程是否可见,非课程成员无法查看私有课程 @@ -258,7 +238,7 @@ module CoursesHelper # 学生人数计算 # add by nwb def studentCount course - course ? course.student.count.to_s : 0#course.student.count + course ? course.student.count.to_i : 0#course.student.count end #课程成员数计算 @@ -293,12 +273,17 @@ module CoursesHelper def searchTeacherAndAssistant project #searchPeopleByRoles(project, TeacherRoles) members = [] - project.members.each do |m| + project.members.includes(:user).each do |m| members << m if m && m.user && m.user.allowed_to?(:as_teacher,project) end members end + def TeacherAndAssistantCount course + students_count = course.student.count + number = course.members.count - students_count + end + def search_student_in_group(project, course_group_id) #searchPeopleByRoles(project, StudentRoles) members = [] @@ -766,7 +751,7 @@ module CoursesHelper #加入课程、退出课程按钮 def join_in_course_header(course, user, options=[]) if user.logged? - joined = course.members.map{|member| member.user_id}.include? user.id + joined = course.members.includes(:user).map{|member| member.user_id}.include? user.id text = joined ? l(:label_course_exit_student) : l(:label_course_join_student) url = joined ? join_path(:object_id => course.id) : try_join_path(:object_id => course.id) method = joined ? 'delete' : 'post' diff --git a/app/views/boards/_course_show_detail.html.erb b/app/views/boards/_course_show_detail.html.erb index bc7b9667e..d465571c5 100644 --- a/app/views/boards/_course_show_detail.html.erb +++ b/app/views/boards/_course_show_detail.html.erb @@ -2,20 +2,7 @@ <%= import_ke(enable_at: false, prettify: false) %> <%= javascript_include_tag "create_kindeditor" %> <% end %> - - -<% if topics%> +<% if topics %> <% topics.each do |topic| %> <% if topic %> - <%= render :partial => 'users/course_message', :locals => {:activity => topic, :user_activity_id => topic.id,:is_course=>1,:is_board=>1} %> + <%= render :partial => 'users/course_message', :locals => {:activity => topic, :user_activity_id => topic.id, :is_course => 1, :is_board=>1} %> <% end %> <% end %> <% if topics.count == 10 %> - <%= link_to "点击展开更多",boards_topic_path(@board, :course_id => @board.course.id ,:page => page),:id => "show_more_course_topic",:remote => "true",:class => "loadMore mt10 f_grey"%> <% end %> <% end%> - diff --git a/app/views/boards/show.html.erb b/app/views/boards/show.html.erb index 9dd5c78ca..6cc755b61 100644 --- a/app/views/boards/show.html.erb +++ b/app/views/boards/show.html.erb @@ -192,6 +192,4 @@ function nh_init_board(params){ }); } } - - diff --git a/app/views/courses/_course_activity.html.erb b/app/views/courses/_course_activity.html.erb index bdbcabff0..763748ad7 100644 --- a/app/views/courses/_course_activity.html.erb +++ b/app/views/courses/_course_activity.html.erb @@ -50,7 +50,7 @@ -<% course_activities.each do |activity| if course_activities %> +<% course_activities.includes(:course_act).each do |activity| if course_activities %> - <% if activity && activity.course_act%> + <% if activity && activity.course_act %> <% act = activity.course_act %> <% case activity.course_act_type.to_s %> <% when 'HomeworkCommon' %> diff --git a/app/views/courses/_recommendation.html.erb b/app/views/courses/_recommendation.html.erb index a0c659493..63803a5b9 100644 --- a/app/views/courses/_recommendation.html.erb +++ b/app/views/courses/_recommendation.html.erb @@ -1,22 +1,21 @@ -<% unless excellent_course_recommend(course).length == 0 %> +<% exc_course = excellent_course_recommend(course) %> +<% unless exc_course.length == 0 %>
<%=link_to e_course.name, course_path(e_course.id), :class => "hidden fl w170" %>
- <% 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" %>) + <% if course_file_num > 0 %> + <%= l(:project_module_attachments) %>(<%= link_to course_file_num, 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" %>) <% end %>
- -<%=x["result"]%>+
<%=x["result"]%>正确输出: -
<%= x["output"] %>+
<%= x["output"] %>+ <% if x["status"].to_i == 2 %> + 耗时: +
<%=x["time_used"]%>毫秒+ <% end %>
<%=x["result"]%>+
<%=x["result"]%>正确输出: -
<%=x["output"]%>+
<%=x["output"]%>+ <% if x["status"].to_i == 2 %> + 耗时: +
<%=x["time_used"]%>毫秒+ <% end %>
]*>/ig,"\n"),d=d.replace(/<[^>]+>/g,""),d=d.replace(/ {2}/g," "), b.newlineTag=="p"?/\n/.test(d)&&(d=d.replace(/^/,"
").replace(/$/,"
")):d=d.replace(/\n/g,"
$&")),b.insertHtml(d,!0))}var d=b.edit.doc,f,j,i,l="__kindeditor_paste__",m=!1;a(d.body).bind("paste",function(p){if(b.pasteType===0)p.stop();else if(!m){m=!0;a("div."+l,d).remove();f=b.cmd.selection();j=f.range.createBookmark();i=a('