测试代码功能完成
This commit is contained in:
parent
5fb2989427
commit
1462ea09f3
|
@ -3,13 +3,43 @@ class StudentWorkController < ApplicationController
|
||||||
include StudentWorkHelper
|
include StudentWorkHelper
|
||||||
require 'bigdecimal'
|
require 'bigdecimal'
|
||||||
require "base64"
|
require "base64"
|
||||||
before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list]
|
before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test]
|
||||||
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work]
|
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work]
|
||||||
before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work]
|
before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work]
|
||||||
before_filter :author_of_work, :only => [:edit, :update, :destroy]
|
before_filter :author_of_work, :only => [:edit, :update, :destroy]
|
||||||
before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list]
|
before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list]
|
||||||
protect_from_forgery :except => :set_program_score
|
protect_from_forgery :except => :set_program_score
|
||||||
|
|
||||||
|
###
|
||||||
|
def program_test
|
||||||
|
resultObj = {status: 0, results: [], error_msg: ''}
|
||||||
|
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.student_work_tests.build(status: result["status"], results: results)
|
||||||
|
unless student_work.save
|
||||||
|
resultObj[:status] = 200
|
||||||
|
else
|
||||||
|
resultObj[:status] = result["status"].to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
render :json => resultObj
|
||||||
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
#设置作业对应的forge_messages表的viewed字段
|
#设置作业对应的forge_messages表的viewed字段
|
||||||
query_student_work = @homework.course_messages
|
query_student_work = @homework.course_messages
|
||||||
|
@ -102,14 +132,9 @@ class StudentWorkController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
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?
|
||||||
@stundet_work = StudentWork.new
|
@student_work = StudentWork.new
|
||||||
respond_to do |format|
|
|
||||||
format.html
|
|
||||||
end
|
|
||||||
else
|
|
||||||
render_403
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -584,4 +609,44 @@ class StudentWorkController < ApplicationController
|
||||||
book.write xls_report
|
book.write xls_report
|
||||||
xls_report.string
|
xls_report.string
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_or_save_student_work
|
||||||
|
student_work = @homework.student_works.where(user_id: User.current.id).first
|
||||||
|
if student_work.nil?
|
||||||
|
@homework.student_works.build(
|
||||||
|
name: params[:title],
|
||||||
|
description: params[:src],
|
||||||
|
user_id: User.current.id
|
||||||
|
)
|
||||||
|
unless @homework.save
|
||||||
|
else
|
||||||
|
student_work = @homework.student_works.where(user_id: User.current.id).first
|
||||||
|
end
|
||||||
|
end
|
||||||
|
student_work
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def test_realtime(student_work, src)
|
||||||
|
url = "http://192.168.41.130:3000/api/realtime_test.json"
|
||||||
|
|
||||||
|
factor = []
|
||||||
|
@homework.homework_tests.each do |test|
|
||||||
|
factor << {input: test.input, output: test.output}
|
||||||
|
end
|
||||||
|
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
|
||||||
end
|
end
|
|
@ -56,4 +56,6 @@ class HomeworkCommon < ActiveRecord::Base
|
||||||
Mailer.run.homework_added(self)
|
Mailer.run.homework_added(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
delegate :language_name, :to => :homework_detail_programing
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,4 +2,8 @@ class HomeworkDetailPrograming < ActiveRecord::Base
|
||||||
attr_accessible :language, :standard_code, :homework_common_id
|
attr_accessible :language, :standard_code, :homework_common_id
|
||||||
|
|
||||||
belongs_to :homework_common
|
belongs_to :homework_common
|
||||||
|
|
||||||
|
def language_name
|
||||||
|
%W(c c++).at(self.language.to_i - 1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,5 +2,4 @@ class HomeworkTest < ActiveRecord::Base
|
||||||
attr_accessible :input, :output, :homework_common_id,:result,:error_msg
|
attr_accessible :input, :output, :homework_common_id,:result,:error_msg
|
||||||
|
|
||||||
belongs_to :homework_common
|
belongs_to :homework_common
|
||||||
has_many :student_work_test
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ class StudentWork < ActiveRecord::Base
|
||||||
has_many :student_works_evaluation_distributions, :dependent => :destroy
|
has_many :student_works_evaluation_distributions, :dependent => :destroy
|
||||||
has_many :student_works_scores, :dependent => :destroy
|
has_many :student_works_scores, :dependent => :destroy
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
has_many :student_work_test
|
has_many :student_work_tests, order: 'id desc'
|
||||||
|
|
||||||
before_destroy :delete_praise
|
before_destroy :delete_praise
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
class StudentWorkTest < ActiveRecord::Base
|
class StudentWorkTest < ActiveRecord::Base
|
||||||
attr_accessible :student_work_id, :homework_test_id, :result, :error_msg
|
attr_accessible :student_work_id, :results, :status
|
||||||
|
|
||||||
belongs_to :homework_test
|
|
||||||
belongs_to :student_work
|
belongs_to :student_work
|
||||||
|
|
||||||
|
serialize :results, Array
|
||||||
|
|
||||||
def status_to_s
|
def status_to_s
|
||||||
case self.result.to_i
|
case self.status.to_i
|
||||||
when -1
|
when -1
|
||||||
'编译出错'
|
'编译出错'
|
||||||
when -2
|
when -2
|
||||||
|
@ -33,10 +33,11 @@ class StudentWorkTest < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_score
|
def test_score
|
||||||
if self.result.to_i == 0
|
if self.status.to_i == 0
|
||||||
format("%.1f",100.0 / self.student_work.homework_common.homework_tests.count)
|
format("%.1f",100.0 / self.student_work.homework_common.homework_tests.count)
|
||||||
else
|
else
|
||||||
0
|
0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
<% content_for :header_tags do %>
|
||||||
|
<%= javascript_include_tag 'homework' %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if @homework.homework_type == 1 %>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
<%if @homework.homework_type == 1 && @homework.homework_detail_manual.comment_status != 1%>
|
<%if @homework.homework_type == 1 && @homework.homework_detail_manual.comment_status != 1%>
|
||||||
$(function(){
|
$(function(){
|
||||||
|
@ -81,3 +86,76 @@
|
||||||
</div>
|
</div>
|
||||||
</div><!--新建作业结束-->
|
</div><!--新建作业结束-->
|
||||||
<div class="cl"></div>
|
<div class="cl"></div>
|
||||||
|
|
||||||
|
<% else %>
|
||||||
|
|
||||||
|
<div class="homepageRight">
|
||||||
|
<div class="HomeWork">
|
||||||
|
<div class="RightBanner">
|
||||||
|
<div class="NewsBannerName">提交作品</div>
|
||||||
|
</div>
|
||||||
|
<div class="HomeWorkBox">
|
||||||
|
<div class="">
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
<p class="c_grey mt15">注:迟交扣<span class="c_red">2</span>分,缺评一个作品扣<span class="c_red">2</span>分</p>
|
||||||
|
</div><!----HomeWorkBox end-->
|
||||||
|
<div class="HomeWorkCon">
|
||||||
|
<div class="mt15">
|
||||||
|
<span>请使用 <%= @homework.language_name %> 语言</span>
|
||||||
|
</div>
|
||||||
|
<div class="mt10">
|
||||||
|
<textarea id="program-title" class="InputBox W700" placeholder="请概括你的代码的功能"></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="mt10">
|
||||||
|
<textarea id="program-src" class="InputBox W700 H150" placeholder="请贴入你的代码"></textarea>
|
||||||
|
</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>
|
||||||
|
<a href="javascript:void(0);" class="BlueCirBtn fr">提交代码</a>
|
||||||
|
<div class="cl"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div><!----HomeWorkCon end-->
|
||||||
|
</div><!----HomeWork end-->
|
||||||
|
<div class="ProResult mt10">
|
||||||
|
<% @student_work.student_work_tests.each_with_index do |test, index| %>
|
||||||
|
<div class="ProResultTop">
|
||||||
|
<p class="c_blue fl">第<%= @student_work.student_work_tests.count - index%>次测试</p><span class="fr c_grey"><%= format_time(test.created_at) %></span>
|
||||||
|
<div class="cl"></div>
|
||||||
|
</div>
|
||||||
|
<% if test.status.to_i == -2 %>
|
||||||
|
<div class="ProResultCon "><%= test.results.first %></div>
|
||||||
|
<% else %>
|
||||||
|
<div class="ProResultTable " >
|
||||||
|
<ul class="ProResultUl " >
|
||||||
|
<% test.results.each_with_index do |x, i| %>
|
||||||
|
<li ><span class="w60 T_C">测试<%=i+1%></span>
|
||||||
|
<% if x["status"].to_i != 0 %>
|
||||||
|
<span class="w150 c_red">测试错误!</span>
|
||||||
|
<span class="w60">您的输出:</span>
|
||||||
|
<span class="W200"><%=x["result"]%></span>
|
||||||
|
<span class="w60">正确输出:</span>
|
||||||
|
<span class="W200"><%=x["output"]%></span>
|
||||||
|
<div class="cl"></div>
|
||||||
|
</li>
|
||||||
|
<% else %>
|
||||||
|
<span class="w150 c_green">测试正确!</span>
|
||||||
|
<div class="cl"></div>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</div><!----ProResult end-->
|
||||||
|
</div><!----homepageRight end-->
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
|
|
@ -120,6 +120,7 @@ RedmineApp::Application.routes.draw do
|
||||||
get 'absence_penalty_list'
|
get 'absence_penalty_list'
|
||||||
get 'evaluation_list'
|
get 'evaluation_list'
|
||||||
post 'set_program_score'
|
post 'set_program_score'
|
||||||
|
post 'program_test'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
class ChangeStudentWorkTests < ActiveRecord::Migration
|
||||||
|
|
||||||
|
def change
|
||||||
|
change_table :student_work_tests do |t|
|
||||||
|
t.remove :error_msg
|
||||||
|
t.remove :result
|
||||||
|
t.remove :homework_test_id
|
||||||
|
t.integer :status, default: 9
|
||||||
|
t.text :results
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20150826061843) do
|
ActiveRecord::Schema.define(:version => 20150828011415) do
|
||||||
|
|
||||||
create_table "activities", :force => true do |t|
|
create_table "activities", :force => true do |t|
|
||||||
t.integer "act_id", :null => false
|
t.integer "act_id", :null => false
|
||||||
|
@ -1297,10 +1297,10 @@ ActiveRecord::Schema.define(:version => 20150826061843) do
|
||||||
create_table "student_work_tests", :force => true do |t|
|
create_table "student_work_tests", :force => true do |t|
|
||||||
t.integer "student_work_id"
|
t.integer "student_work_id"
|
||||||
t.integer "homework_test_id"
|
t.integer "homework_test_id"
|
||||||
t.integer "result"
|
t.integer "status"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at", :null => false
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at", :null => false
|
||||||
t.text "error_msg"
|
t.text "results"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "student_works", :force => true do |t|
|
create_table "student_works", :force => true do |t|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
$(function(){
|
||||||
|
|
||||||
|
$('#test-program-btn').on('click', function(){
|
||||||
|
var homework_id = $(this).attr('data-homework-id');
|
||||||
|
var student_work_id = $(this).attr('data-student-work-id');
|
||||||
|
var src = $('#program-src').val();
|
||||||
|
var title = $('program-title').val();
|
||||||
|
|
||||||
|
if (!src) {
|
||||||
|
alert('请输入正确的代码');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$.post(
|
||||||
|
'/student_work/program_test',
|
||||||
|
{homework: homework_id, student_work_id: student_work_id, src: src, title: title},
|
||||||
|
function(data,status){
|
||||||
|
if(data.status==-2){
|
||||||
|
alert('编译失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
|
@ -532,3 +532,49 @@ a.resourcesBlack:hover {font-size:12px; color:#000000;}
|
||||||
background-color: #64bdd9;
|
background-color: #64bdd9;
|
||||||
outline:none;
|
outline:none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*20150820课程作业 LB*/
|
||||||
|
.HomeWork {width:708px; background-color:#ffffff; padding:20px; border:1px solid #dddddd;}
|
||||||
|
.RightBanner {width:708px; height:34px; border-bottom:1px solid #e9e9e9;}
|
||||||
|
select.InputBox,input.InputBox,textarea.InputBox{ border:1px solid #d9d9d9; color:#888888; height:28px; line-height:28px; padding-left:5px; font-size:14px;}
|
||||||
|
a.BlueCirBtn{ display:block;width:75px; height:28px; background-color:#ffffff; line-height:28px; vertical-align:middle; text-align:center; border:1px solid #15bccf; color:#15bccf; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px;}
|
||||||
|
a:hover.BlueCirBtn{ background:#15bccf; color:#fff;}
|
||||||
|
.W440{ width:440px;}
|
||||||
|
.W120{ width:110px;}
|
||||||
|
.W700{ width:700px;}
|
||||||
|
a.AnnexBtn{ background: url(../images/homepage_icon.png) 0px -343px no-repeat; width:70px; height:20px; display:block; padding-left:20px; color:#888888;}
|
||||||
|
a:hover.AnnexBtn{background: url(../images/homepage_icon.png) -90px -343px no-repeat; color:#15bccf;}
|
||||||
|
a.FilesBtn{ background: url(../images/homepage_icon.png) 0px -373px no-repeat; width:70px; height:20px; display:block; padding-left:20px; color:#888888;}
|
||||||
|
a:hover.FilesBtn{background: url(../images/homepage_icon.png) -89px -372px no-repeat; color:#15bccf;}
|
||||||
|
a.BlueCirBtnMini{ display:block;width:40px; height:22px; background-color:#ffffff; line-height:24px; vertical-align:middle; text-align:center; border:1px solid #15bccf; color:#15bccf; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px;}
|
||||||
|
a:hover.BlueCirBtnMini{ background:#15bccf; color:#fff;}
|
||||||
|
a.DropBtn{background: url(../images/homepage_icon.png) -125px -339px no-repeat; width:85px; height:20px; display:block; color:#888888; font-size:14px;}
|
||||||
|
a:hover.DropBtn{background: url(../images/homepage_icon.png) -125px -370px no-repeat;}
|
||||||
|
.DropLine{border-top:1px solid #d9d9d9; float:left; width:623px; height:10px; margin-top:10px;}
|
||||||
|
/*20150820编程作业 LB*/
|
||||||
|
.W320{ width:320px;}
|
||||||
|
.icon_add{ background:url(../images/courses/icons.png) 0px -310px no-repeat; width:16px; height:27px; display:block;float:left; margin-right:5px;}
|
||||||
|
a:hover.icon_add{background:url(../images/courses/icons.png) -20px -310px no-repeat;}
|
||||||
|
.icon_remove{background:url(../images/courses/icons.png) 0px -338px no-repeat; width:16px; height:27px; display:block;float:left;}
|
||||||
|
a:hover.icon_remove{background:url(../images/courses/icons.png) -20px -338px no-repeat;}
|
||||||
|
/*20150820提交作业 LB*/
|
||||||
|
.HomeWorkBox{ background:#f6f6f6; padding:10px; margin:10px 0;}
|
||||||
|
.c_grey{ color:#888888;}
|
||||||
|
.HomeWorkP{ width:690px; font-size:14px;}
|
||||||
|
.H150{ height:150px;}
|
||||||
|
.ProResult{width:748px; background-color:#fff; border:1px solid #dddddd;border-bottom:none; }
|
||||||
|
.ProResultTop{ height:38px; line-height:38px; border-bottom:1px solid #dddddd; background:#f2f2f2; padding:0 10px;}
|
||||||
|
.ProResultCon{ padding:10px; color:#888888; line-height:24px; border-bottom:1px solid #dddddd; }
|
||||||
|
.W50{ width:50px;}
|
||||||
|
.W200{ width:200px;}
|
||||||
|
.ProResultTable{ color:#888888;}
|
||||||
|
.T_C{ text-align:center;}
|
||||||
|
.SearchIcon{background:url(../images/homepage_icon.png) 676px -393px no-repeat; }
|
||||||
|
.SearchIcon:hover{background:url(../images/homepage_icon.png) 676px -419px no-repeat; }
|
||||||
|
a.link_file{ background:url(../images/courses/pic_file.png) 0 2px no-repeat; padding-left:20px; }
|
||||||
|
a:hover.link_file{ background:url(../images/courses/pic_file.png) 0 -25px no-repeat; color:#3ca5c6;}
|
||||||
|
a.FilesName{ max-width:540px;overflow:hidden; white-space:nowrap; text-overflow:ellipsis; display:block;}
|
||||||
|
a.FilesName02{ max-width:665px;overflow:hidden; white-space:nowrap; text-overflow:ellipsis; display:block;}
|
||||||
|
.ProResultUl span { display:block; float:left;}
|
||||||
|
.ProResultUl li{ line-height:35px; border-bottom:1px solid #dddddd; }
|
||||||
|
.DateBorder{border:1px solid #d9d9d9; border-left:none; padding:7px 6px 6px 6px;}
|
||||||
|
|
Loading…
Reference in New Issue