|
|
@@ -48,14 +48,13 @@ module KGrader |
|
|
|
end |
|
|
|
|
|
|
|
def grade |
|
|
|
self.status = :ungraded |
|
|
|
grade_prep |
|
|
|
stage |
|
|
|
build |
|
|
|
test |
|
|
|
save |
|
|
|
# self.status = :graded # UNCOMMENT |
|
|
|
# @fs.jail.reset # UNCOMMENT |
|
|
|
# TODO: return grade summary string |
|
|
|
grade_post |
|
|
|
@summary |
|
|
|
end |
|
|
|
|
|
|
|
def commit |
|
|
@@ -85,6 +84,14 @@ module KGrader |
|
|
|
File.join @root, 'pending' |
|
|
|
end |
|
|
|
|
|
|
|
def buildlog |
|
|
|
File.join @root, 'build.log' |
|
|
|
end |
|
|
|
|
|
|
|
def testlog |
|
|
|
File.join @root, 'test.log' |
|
|
|
end |
|
|
|
|
|
|
|
def revision |
|
|
|
@course.backend.revision repo |
|
|
|
end |
|
|
@@ -101,10 +108,23 @@ module KGrader |
|
|
|
rev |
|
|
|
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.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| |
|
|
|
@fs.jail.stage entry[:path], entry[:name] |
|
|
|
end |
|
|
@@ -115,19 +135,63 @@ module KGrader |
|
|
|
|
|
|
|
def build |
|
|
|
@assignment.build_steps.each do |command| |
|
|
|
@fs.jail.exec command |
|
|
|
return build_failure unless @fs.jail.exec command, buildlog |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
def save |
|
|
|
# TODO: save gradefile |
|
|
|
File.write gradefile, generate_report |
|
|
|
FileUtils.touch pendingfile |
|
|
|
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 |