2015-07-16 17:33:15 +08:00
|
|
|
# encoding: utf-8
|
2015-07-15 15:21:26 +08:00
|
|
|
class StudentWorkTest < ActiveRecord::Base
|
2016-04-20 09:51:51 +08:00
|
|
|
attr_accessible :student_work_id, :results, :status, :src, :uwait_time
|
2015-07-15 15:21:26 +08:00
|
|
|
belongs_to :student_work
|
2015-07-16 17:33:15 +08:00
|
|
|
|
2015-08-28 12:04:49 +08:00
|
|
|
serialize :results, Array
|
|
|
|
|
2015-07-16 17:33:15 +08:00
|
|
|
def status_to_s
|
2015-08-28 12:04:49 +08:00
|
|
|
case self.status.to_i
|
2015-07-16 17:33:15 +08:00
|
|
|
when -1
|
|
|
|
'编译出错'
|
|
|
|
when -2
|
|
|
|
'答题错误'
|
|
|
|
when -3
|
|
|
|
'答案错误'
|
|
|
|
when 1
|
|
|
|
'运行出错'
|
|
|
|
when 2
|
|
|
|
'超时'
|
|
|
|
when 3
|
|
|
|
'内存超出'
|
|
|
|
when 4
|
|
|
|
'输出超出'
|
|
|
|
when 5
|
|
|
|
'禁用函数'
|
|
|
|
when 6
|
|
|
|
'其他错误'
|
|
|
|
when 0
|
|
|
|
'成功'
|
|
|
|
else
|
|
|
|
'未知错误'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_score
|
2015-08-28 12:04:49 +08:00
|
|
|
if self.status.to_i == 0
|
2015-09-09 00:43:54 +08:00
|
|
|
100
|
|
|
|
elsif self.results.empty?
|
2015-07-16 17:33:15 +08:00
|
|
|
0
|
2015-09-09 00:43:54 +08:00
|
|
|
else
|
|
|
|
get_success_count * 100 / self.results.count
|
2015-07-16 17:33:15 +08:00
|
|
|
end
|
|
|
|
end
|
2015-08-28 12:04:49 +08:00
|
|
|
|
2015-09-09 00:43:54 +08:00
|
|
|
private
|
|
|
|
def get_success_count
|
|
|
|
self.results.inject(0) do |sum, result|
|
2015-09-22 16:52:21 +08:00
|
|
|
sum += (result["status"] && result["status"].to_i == 0 ? 1 : 0)
|
2015-09-09 00:43:54 +08:00
|
|
|
end || 0
|
|
|
|
end
|
|
|
|
|
2015-07-15 15:21:26 +08:00
|
|
|
end
|