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.

71 lines
1.4 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. end
  27. def fetch(due)
  28. if status == :init
  29. @course.backend.clone repo, @semester, @assignment.id, @student
  30. rewind due
  31. self.status = :ungraded
  32. else
  33. oldrev = revision if status == :graded
  34. self.status = :fetching
  35. @course.backend.update repo
  36. rewind due
  37. self.status = revision == oldrev ? :graded : :ungraded
  38. end
  39. end
  40. def grade
  41. # TODO
  42. # self.status = :graded
  43. end
  44. private
  45. def statusfile
  46. File.join @root, "status.txt"
  47. end
  48. def repo
  49. File.join @root, "repo"
  50. end
  51. def revision
  52. @course.backend.revision repo
  53. end
  54. def rewind(date)
  55. # TODO
  56. end
  57. end
  58. end