A code autograder for student homework submissions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
1.9 KiB

  1. module KGrader
  2. class Submission
  3. attr_reader :course, :semester, :assignment, :student
  4. def initialize(filesystem, course, semester, assignment, student)
  5. @fs = filesystem
  6. @course = course
  7. @semester = semester
  8. @assignment = assignment
  9. @student = student
  10. @root = @fs.submission @course.name, @semester, @assignment.name, student
  11. @status = nil
  12. end
  13. def status
  14. @status ||= @fs.load(statusfile).to_sym
  15. end
  16. def status=(new_status)
  17. File.write statusfile, new_status
  18. @status = new_status
  19. end
  20. def exists?
  21. File.exists? statusfile
  22. end
  23. def create
  24. FileUtils.mkdir_p @root
  25. self.status = :init
  26. nil
  27. end
  28. def fetch(due)
  29. if status == :init
  30. @course.backend.clone repo, @semester, @assignment.id, @student
  31. rewind due
  32. self.status = :ungraded
  33. else
  34. oldrev = revision if status == :graded
  35. self.status = :fetching
  36. @course.backend.update repo
  37. rewind due
  38. self.status = revision == oldrev ? :graded : :ungraded
  39. end
  40. nil
  41. end
  42. def grade
  43. # TODO:
  44. # self.status = :ungraded
  45. # [grade the stuff]
  46. # [save report to gradefile]
  47. # FileUtils.touch pendingfile
  48. # self.status = :graded
  49. # return grade summary string
  50. sleep rand / 2
  51. '100%'
  52. end
  53. def commit
  54. # TODO:
  55. # if status == :graded && File.exists? pendingfile
  56. # [copy gradefile to repo and commit]
  57. # FileUtils.rm pendingfile
  58. # end
  59. sleep rand / 2
  60. nil
  61. end
  62. private
  63. def repo
  64. File.join @root, 'repo'
  65. end
  66. def statusfile
  67. File.join @root, 'status.txt'
  68. end
  69. def gradefile
  70. File.join @root, 'grade.txt'
  71. end
  72. def pendingfile
  73. File.join @root, 'pending'
  74. end
  75. def revision
  76. @course.backend.revision repo
  77. end
  78. def rewind(date)
  79. # TODO
  80. end
  81. end
  82. end