老师测试功能
This commit is contained in:
parent
1c8b24822d
commit
a69cee4b26
|
@ -12,10 +12,37 @@ class StudentWorkController < ApplicationController
|
|||
|
||||
###
|
||||
def program_test
|
||||
is_test = params[:is_test] == 'true'
|
||||
resultObj = {status: 0, results: [], error_msg: '', time: Time.now}
|
||||
student_work = find_or_save_student_work
|
||||
unless student_work
|
||||
resultObj[:status] = 100
|
||||
unless is_test
|
||||
student_work = find_or_save_student_work
|
||||
|
||||
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
|
||||
if @homework.homework_type == 2 && @homework.homework_detail_programing
|
||||
result = test_realtime(student_work, params[:src])
|
||||
|
@ -27,18 +54,15 @@ class StudentWorkController < ApplicationController
|
|||
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
|
||||
|
||||
resultObj[:status] = result["status"].to_i
|
||||
resultObj[:time] = Time.now.strftime('%Y%m%d %T')
|
||||
resultObj[:index] = 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
render :json => resultObj
|
||||
end
|
||||
|
||||
|
|
|
@ -345,6 +345,7 @@ class UsersController < ApplicationController
|
|||
def new_user_commit_homework
|
||||
@user = User.current
|
||||
@homework = HomeworkCommon.find(params[:homework_id])
|
||||
@is_test = params[:is_test] == 'true'
|
||||
@student_work = @homework.student_works.where(user_id: User.current.id).first
|
||||
if @student_work.nil?
|
||||
@student_work = StudentWork.new
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
<div class="homepagePostSubmit">
|
||||
<%= user_for_homework_common homework_common,is_teacher %>
|
||||
</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">
|
||||
<%= l(:label_end_time)%>:<%= homework_common.end_time%>
|
||||
</div>
|
||||
|
|
|
@ -48,9 +48,11 @@
|
|||
<div class="homepagePostTitle fl"><%= @homework.name %></div><span class="fr c_grey">截止时间:<%= @homework.end_time %></span>
|
||||
<div class="cl"></div>
|
||||
<a href="javascript:void(0);" class="c_blue"><%= @homework.user.show_name %></a>
|
||||
<p class="HomeWorkP"><%= @homework.description %> <br />
|
||||
输入 2 1 1 4 4 2 3 6 5 <br />
|
||||
输出 15<br />
|
||||
<p class="HomeWorkP"><%= @homework.description.html_safe %> <br />
|
||||
<% @homework.homework_tests.each do |test| %>
|
||||
输入 <%=test.input%> <br />
|
||||
输出 <%=test.output%><br />
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
||||
<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
|
||||
},
|
||||
:method => :post) do |f|%>
|
||||
|
||||
<input type="hidden" name="is_test" value="<%=@is_test%>">
|
||||
<div class="mt15">
|
||||
<span>请使用 <%= @homework.language_name %> 语言编写</span>
|
||||
</div>
|
||||
|
@ -76,7 +78,9 @@
|
|||
</div>
|
||||
<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>
|
||||
<% unless @is_test %>
|
||||
<a href="javascript:void(0);" class="BlueCirBtn fr" id="commit-program-work-btn">提交代码</a>
|
||||
<% end %>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
@ -26,6 +26,7 @@ $(function(){
|
|||
var student_work_id = $('#test-program-btn').attr('data-student-work-id');
|
||||
var src = $('#program-src').val();
|
||||
var title = $('#program-title').val();
|
||||
var is_test = $('input[name=is_test]').val();
|
||||
|
||||
if(!valid_form()){
|
||||
return;
|
||||
|
@ -33,7 +34,7 @@ $(function(){
|
|||
|
||||
$.post(
|
||||
'/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){
|
||||
tested = true;
|
||||
console.log(data);
|
||||
|
|
Loading…
Reference in New Issue