|
@@ -48,14 +48,13 @@ module KGrader |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def grade |
|
|
def grade |
|
|
self.status = :ungraded |
|
|
|
|
|
|
|
|
grade_prep |
|
|
stage |
|
|
stage |
|
|
build |
|
|
build |
|
|
test |
|
|
test |
|
|
save |
|
|
save |
|
|
# self.status = :graded # UNCOMMENT |
|
|
|
|
|
# @fs.jail.reset # UNCOMMENT |
|
|
|
|
|
# TODO: return grade summary string |
|
|
|
|
|
|
|
|
grade_post |
|
|
|
|
|
@summary |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def commit |
|
|
def commit |
|
@@ -85,6 +84,14 @@ module KGrader |
|
|
File.join @root, 'pending' |
|
|
File.join @root, 'pending' |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def buildlog |
|
|
|
|
|
File.join @root, 'build.log' |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def testlog |
|
|
|
|
|
File.join @root, 'test.log' |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
def revision |
|
|
def revision |
|
|
@course.backend.revision repo |
|
|
@course.backend.revision repo |
|
|
end |
|
|
end |
|
@@ -101,10 +108,23 @@ module KGrader |
|
|
rev |
|
|
rev |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def stage |
|
|
|
|
|
|
|
|
def grade_prep |
|
|
|
|
|
@failure = false |
|
|
|
|
|
@comments = [] |
|
|
|
|
|
@summary = nil |
|
|
|
|
|
@tests = [] |
|
|
|
|
|
|
|
|
|
|
|
self.status = :ungraded |
|
|
|
|
|
FileUtils.rm_f [buildlog, testlog] |
|
|
@fs.jail.reset |
|
|
@fs.jail.reset |
|
|
@fs.jail.init |
|
|
@fs.jail.init |
|
|
|
|
|
|
|
|
|
|
|
@assignment.tests.each do |test| |
|
|
|
|
|
@tests.push({ :name => test[:name], :max => test[:max], :score => 0 }) |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def stage |
|
|
@assignment.manifest[:provided].each do |entry| |
|
|
@assignment.manifest[:provided].each do |entry| |
|
|
@fs.jail.stage entry[:path], entry[:name] |
|
|
@fs.jail.stage entry[:path], entry[:name] |
|
|
end |
|
|
end |
|
@@ -115,19 +135,63 @@ module KGrader |
|
|
|
|
|
|
|
|
def build |
|
|
def build |
|
|
@assignment.build_steps.each do |command| |
|
|
@assignment.build_steps.each do |command| |
|
|
@fs.jail.exec command |
|
|
|
|
|
|
|
|
return build_failure unless @fs.jail.exec command, buildlog |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def test |
|
|
def test |
|
|
@assignment.tests.each do |script| |
|
|
|
|
|
# TODO: execute script in jail |
|
|
|
|
|
|
|
|
return if @failure |
|
|
|
|
|
@assignment.tests.each do |test| |
|
|
|
|
|
# TODO: execute script in jail and update @test/@comments; out testlog |
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def save |
|
|
def save |
|
|
# TODO: save gradefile |
|
|
|
|
|
|
|
|
File.write gradefile, generate_report |
|
|
FileUtils.touch pendingfile |
|
|
FileUtils.touch pendingfile |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def grade_post |
|
|
|
|
|
# self.status = :graded # TODO: uncomment |
|
|
|
|
|
# @fs.jail.reset # TODO: uncomment |
|
|
|
|
|
@summary = generate_summary unless @summary |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def build_failure |
|
|
|
|
|
@failure = true |
|
|
|
|
|
@comments.push "failed to compile" |
|
|
|
|
|
@summary = "#{format_points 0, max_score}: failed to compile" |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def generate_report |
|
|
|
|
|
# TODO |
|
|
|
|
|
@tests |
|
|
|
|
|
@assignment.extra_comments |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def generate_summary |
|
|
|
|
|
tests = @tests.each do |test| |
|
|
|
|
|
"#{test[:score].to_s.rjust get_span(test[:max])}/#{test[:max]}" |
|
|
|
|
|
end.join ', ' |
|
|
|
|
|
"#{format_points score, max_score}: #{tests}" |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def score |
|
|
|
|
|
@tests.reduce(0) { |sum, t| sum + t[:score] } |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def max_score |
|
|
|
|
|
@tests.reduce(0) { |sum, t| sum + t[:max] } |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def format_points(score, max) |
|
|
|
|
|
percent = (score.to_f * 100 / max).round.to_s.rjust 3 |
|
|
|
|
|
span = get_span max |
|
|
|
|
|
"#{percent}% (#{score.to_s.rjust span}/#{max.to_s.rjust span})" |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def get_span(max) |
|
|
|
|
|
(Math.log10(max) + 1).to_i |
|
|
|
|
|
end |
|
|
end |
|
|
end |
|
|
end |
|
|
end |