代码测试结果不全分数100分的BUG修复

This commit is contained in:
yuanke 2016-10-19 10:27:40 +08:00
parent c0e6085e74
commit b907b626a9
3 changed files with 23 additions and 10 deletions

View File

@ -37,7 +37,7 @@ class StudentWork < ActiveRecord::Base
unless last_test
self.system_score = 0
else
self.system_score = last_test.test_score
self.system_score = last_test.test_score self.homework_common.homework_tests.size
end
end
set_final_score self.homework_common,self

View File

@ -32,13 +32,14 @@ class StudentWorkTest < ActiveRecord::Base
end
end
def test_score
if self.status.to_i == 0
#必须和测试集个数一样才能得100分
def test_score(testcount)
if self.status.to_i == 0 && testcount == self.results.count
100
elsif self.results.empty?
0
else
get_success_count * 100 / self.results.count
get_success_count * 100 / testcount
end
end

View File

@ -26,6 +26,7 @@ $(function(){
var test_program = function(cb){
$('#test-program-btn').hide();
$('#commit-program-work-btn').hide();
var homework_id = $('#test-program-btn').attr('data-homework-id');
var student_work_id = $('#test-program-btn').attr('data-student-work-id');
var src = $('#program-src').val();
@ -34,6 +35,7 @@ $(function(){
if(!valid_form()){
$('#test-program-btn').show();
$('#commit-program-work-btn').show();
return;
}
//先测试一次并返回测试集个数及结果再判断是否需要继续进行测试
@ -52,12 +54,14 @@ $(function(){
pop_up_box(htmlvalue,580,30,50);
$('#test-program-btn').show();
$('#commit-program-work-btn').show();
return;
}
else if (data.status==-3){
var htmlvalue = "</br><div style='width:550px;text-align:center'>由于目前大量用户正在测试,系统繁忙,请稍后再试。我们将尽快提升平台的处理能力,谢谢您的支持!</div></br><div style='width:67px; margin:0 auto; text-align:center'><a href='javascript:void(0);' class='Blue-btn' onclick='hideModal()'>确定</a></div>";
pop_up_box(htmlvalue,580,30,50);
$('#test-program-btn').show();
$('#commit-program-work-btn').show();
return;
}
var tSeq = data.tseq;
@ -74,17 +78,19 @@ $(function(){
$('.ProResult').prepend(html);
if (data.status==0 && is_test != 'true') {
if (typeof cb == 'function') {cb(data);$('#test-program-btn').show(); return;}
var htmlvalue = "</br><div style='width:550px;text-align:center'>答题正确,是否立刻提交?</div></br><div style='width:164px; margin:0 auto; text-align:center'><a href='javascript:void(0);' class='Blue-btn fl' onclick='submit_code()'>确定</a><a href='javascript:void(0);' class='Blue-btn fl' onclick='hideModal()'>取消</a></div><script>function submit_code(){$('.HomeWorkCon form').submit();hideModal();}</script>";
if (typeof cb == 'function') {cb(data);return;}
var htmlvalue = "</br><div style='width:550px;text-align:center'>答题正确,是否立刻提交?</div></br><div style='width:164px; margin:0 auto; text-align:center'><a href='javascript:void(0);' class='Blue-btn fl' onclick='submit_code()'>确定</a><a href='javascript:void(0);' class='Blue-btn fl' onclick='hideModal()'>取消</a></div><script>function submit_code(){$('#commit-program-work-btn').hide();$('#test-program-btn').hide();$('.HomeWorkCon form').submit();hideModal();}</script>";
pop_up_box(htmlvalue,580,30,50);
$('#test-program-btn').show();
$('#commit-program-work-btn').show();
return;
}
//2 超时 -2 编译错误 测试结束
if (data.status == 2 || data.status == -2 || tSeq >= tCount ){
if (typeof cb == 'function') {cb(data);$('#test-program-btn').show(); return;}
if (typeof cb == 'function') {cb(data);$('#test-program-btn').show();$('#commit-program-work-btn').show(); return;}
$('#test-program-btn').show();
$('#commit-program-work-btn').show();
return;
}
@ -95,10 +101,11 @@ $(function(){
var htmlvalue = "</br><div style='width:550px;text-align:center'>您的答案超时了, 请检查代码是否存在死循环的错误!</div></br><div style='width:67px; margin:0 auto; text-align:center'><a href='javascript:void(0);' class='Blue-btn' onclick='hideModal()'>确定</a></div>";
pop_up_box(htmlvalue,580,30,50);
} else {
var htmlvalue = "</br><div style='width:550px;text-align:center'>对不起,服务器繁忙请稍后再试!</div></br><div style='width:67px; margin:0 auto; text-align:center'><a href='javascript:void(0);' class='Blue-btn' onclick='hideModal()'>确定</a></div>";
var htmlvalue = "</br><div style='width:550px;text-align:center'>由于目前大量用户正在测试,系统繁忙,请稍后再试。我们将尽快提升平台的处理能力,谢谢您的支持!</div></br><div style='width:67px; margin:0 auto; text-align:center'><a href='javascript:void(0);' class='Blue-btn' onclick='hideModal()'>确定</a></div>";
pop_up_box(htmlvalue,580,30,50);
}
$('#test-program-btn').show();
$('#commit-program-work-btn').show();
return;
});
};
@ -113,6 +120,7 @@ $(function(){
if(!valid_form()){
return;
}
$('#commit-program-work-btn').hide();
if($('.ProResult .ProResultTop').length<=0){
var htmlvalue = "</br><div style='width:550px;text-align:center'>测试后才能提交,是否立刻测试?</div></br><div style='width:164px; margin:0 auto; text-align:center'><a href='javascript:void(0);' id='code-test-button' class='Blue-btn fl'>确定</a><a href='javascript:void(0);' class='Blue-btn fl' onclick='hideModal()'>取消</a></div>";
pop_up_box(htmlvalue,580,30,50);
@ -125,16 +133,20 @@ $(function(){
if (!tested) {
test_program(function(data){
if (data.status!=0) {
var htmlvalue = "</br><div style='width:550px;text-align:center'>测试不通过,是否强制提交?</div></br><div style='width:164px; margin:0 auto; text-align:center'><a href='javascript:void(0);' class='Blue-btn fl' onclick='submit_code()'>确定</a><a href='javascript:void(0);' class='Blue-btn fl' onclick='hideModal()'>取消</a></div><script>function submit_code(){$('.HomeWorkCon form').submit();hideModal();}</script>";
var htmlvalue = "</br><div style='width:550px;text-align:center'>测试不通过,是否强制提交?</div></br><div style='width:164px; margin:0 auto; text-align:center'><a href='javascript:void(0);' class='Blue-btn fl' onclick='submit_code()'>确定</a><a href='javascript:void(0);' class='Blue-btn fl' onclick='hideModal()'>取消</a></div><script>function submit_code(){$('#commit-program-work-btn').hide();$('.HomeWorkCon form').submit();hideModal();}</script>";
pop_up_box(htmlvalue,580,30,50);
$('#commit-program-work-btn').show();
return;
};
$('#commit-program-work-btn').hide();
$('#test-program-btn').hide();
$(".HomeWorkCon form").submit();
});
return;
}
$('#commit-program-work-btn').hide();
$('#test-program-btn').hide();
$(".HomeWorkCon form").submit();
});