老师测试功能

This commit is contained in:
guange 2015-09-02 21:38:13 +08:00
parent 1c8b24822d
commit a69cee4b26
5 changed files with 53 additions and 18 deletions

View File

@ -12,10 +12,37 @@ class StudentWorkController < ApplicationController
### ###
def program_test def program_test
is_test = params[:is_test] == 'true'
resultObj = {status: 0, results: [], error_msg: '', time: Time.now} resultObj = {status: 0, results: [], error_msg: '', time: Time.now}
student_work = find_or_save_student_work unless is_test
unless student_work student_work = find_or_save_student_work
resultObj[:status] = 100
unless student_work
resultObj[:status] = 100
else
if @homework.homework_type == 2 && @homework.homework_detail_programing
result = test_realtime(student_work, params[:src])
logger.debug result
resultObj[:status] = result["status"]
resultObj[:results] = result["results"]
resultObj[:error_msg] = result["error_msg"]
results = result["results"]
if result["status"].to_i == -2 #编译错误
results = [result["error_msg"]]
end
student_work_test = student_work.student_work_tests.build(status: result["status"], results: results,
src: params[:src])
unless student_work.save
resultObj[:status] = 200
else
resultObj[:status] = result["status"].to_i
resultObj[:time] = student_work_test.created_at.to_s(:db)
resultObj[:index] = student_work.student_work_tests.count
end
end
end
else else
if @homework.homework_type == 2 && @homework.homework_detail_programing if @homework.homework_type == 2 && @homework.homework_detail_programing
result = test_realtime(student_work, params[:src]) result = test_realtime(student_work, params[:src])
@ -27,18 +54,15 @@ class StudentWorkController < ApplicationController
if result["status"].to_i == -2 #编译错误 if result["status"].to_i == -2 #编译错误
results = [result["error_msg"]] results = [result["error_msg"]]
end end
student_work_test = student_work.student_work_tests.build(status: result["status"], results: results,
src: params[:src])
unless student_work.save
resultObj[:status] = 200
else
resultObj[:status] = result["status"].to_i
resultObj[:time] = student_work_test.created_at.to_s(:db)
resultObj[:index] = student_work.student_work_tests.count
end
resultObj[:status] = result["status"].to_i
resultObj[:time] = Time.now.strftime('%Y%m%d %T')
resultObj[:index] = 0
end end
end end
render :json => resultObj render :json => resultObj
end end

View File

@ -345,6 +345,7 @@ class UsersController < ApplicationController
def new_user_commit_homework def new_user_commit_homework
@user = User.current @user = User.current
@homework = HomeworkCommon.find(params[:homework_id]) @homework = HomeworkCommon.find(params[:homework_id])
@is_test = params[:is_test] == 'true'
@student_work = @homework.student_works.where(user_id: User.current.id).first @student_work = @homework.student_works.where(user_id: User.current.id).first
if @student_work.nil? if @student_work.nil?
@student_work = StudentWork.new @student_work = StudentWork.new

View File

@ -19,6 +19,11 @@
<div class="homepagePostSubmit"> <div class="homepagePostSubmit">
<%= user_for_homework_common homework_common,is_teacher %> <%= user_for_homework_common homework_common,is_teacher %>
</div> </div>
<% if homework_common.homework_type == 2 && is_teacher%>
<div class="homepagePostSubmit">
<%= link_to "模拟答题", new_user_commit_homework_users_path(homework_id: homework_common.id, is_test: true) %>
</div>
<% end %>
<div class="homepagePostDeadline"> <div class="homepagePostDeadline">
<%= l(:label_end_time)%><%= homework_common.end_time%> <%= l(:label_end_time)%><%= homework_common.end_time%>
</div> </div>

View File

@ -48,9 +48,11 @@
<div class="homepagePostTitle fl"><%= @homework.name %></div><span class="fr c_grey">截止时间:<%= @homework.end_time %></span> <div class="homepagePostTitle fl"><%= @homework.name %></div><span class="fr c_grey">截止时间:<%= @homework.end_time %></span>
<div class="cl"></div> <div class="cl"></div>
<a href="javascript:void(0);" class="c_blue"><%= @homework.user.show_name %></a> <a href="javascript:void(0);" class="c_blue"><%= @homework.user.show_name %></a>
<p class="HomeWorkP"><%= @homework.description %> <br /> <p class="HomeWorkP"><%= @homework.description.html_safe %> <br />
输入 2 1 1 4 4 2 3 6 5 <br /> <% @homework.homework_tests.each do |test| %>
输出 15<br /> 输入 <%=test.input%> <br />
输出 <%=test.output%><br />
<% end %>
</p> </p>
</div> </div>
<p class="c_grey mt15">注:迟交扣<span class="c_red">2</span>分,缺评一个作品扣<span class="c_red">2</span>分</p> <p class="c_grey mt15">注:迟交扣<span class="c_red">2</span>分,缺评一个作品扣<span class="c_red">2</span>分</p>
@ -64,7 +66,7 @@
:homework => @homework.id :homework => @homework.id
}, },
:method => :post) do |f|%> :method => :post) do |f|%>
<input type="hidden" name="is_test" value="<%=@is_test%>">
<div class="mt15"> <div class="mt15">
<span>请使用 <%= @homework.language_name %> 语言编写</span> <span>请使用 <%= @homework.language_name %> 语言编写</span>
</div> </div>
@ -76,7 +78,9 @@
</div> </div>
<div class="mt10"> <div class="mt10">
<a href="javascript:void(0);" class="BlueCirBtn fl" data-homework-id="<%=@homework.id%>" data-student-work-id="<%=@student_work.id%>" id="test-program-btn">测试代码</a> <a href="javascript:void(0);" class="BlueCirBtn fl" data-homework-id="<%=@homework.id%>" data-student-work-id="<%=@student_work.id%>" id="test-program-btn">测试代码</a>
<% unless @is_test %>
<a href="javascript:void(0);" class="BlueCirBtn fr" id="commit-program-work-btn">提交代码</a> <a href="javascript:void(0);" class="BlueCirBtn fr" id="commit-program-work-btn">提交代码</a>
<% end %>
<div class="cl"></div> <div class="cl"></div>
</div> </div>
<% end %> <% end %>

View File

@ -26,6 +26,7 @@ $(function(){
var student_work_id = $('#test-program-btn').attr('data-student-work-id'); var student_work_id = $('#test-program-btn').attr('data-student-work-id');
var src = $('#program-src').val(); var src = $('#program-src').val();
var title = $('#program-title').val(); var title = $('#program-title').val();
var is_test = $('input[name=is_test]').val();
if(!valid_form()){ if(!valid_form()){
return; return;
@ -33,7 +34,7 @@ $(function(){
$.post( $.post(
'/student_work/program_test', '/student_work/program_test',
{homework: homework_id, student_work_id: student_work_id, src: src, title: title}, {homework: homework_id, student_work_id: student_work_id, src: src, title: title, is_test: is_test},
function(data,status){ function(data,status){
tested = true; tested = true;
console.log(data); console.log(data);