Browse Source

Roster loading

master
Ben Kurtovic 8 years ago
parent
commit
0db69377db
4 changed files with 26 additions and 13 deletions
  1. +3
    -3
      lib/kgrader/course.rb
  2. +9
    -7
      lib/kgrader/filesystem.rb
  3. +13
    -3
      lib/kgrader/roster.rb
  4. +1
    -0
      lib/kgrader/task.rb

+ 3
- 3
lib/kgrader/course.rb View File

@@ -8,16 +8,16 @@ module KGrader
def initialize(filesystem, name)
@fs = filesystem
@name = name

@config = @fs.load @fs.course_config(@name)
@rosters = {}
end

def roster(semester)
# TODO: cache
Roster.new @fs, self, semester
@rosters[semester] ||= Roster.new @fs, self, semester
end

def task(semester, assignment)
# TODO: cache
Task.new @fs, self, semester, assignment
end



+ 9
- 7
lib/kgrader/filesystem.rb View File

@@ -27,20 +27,22 @@ module KGrader
File.join course(name), '_config.yml'
end

def roster(course_name, semester)
File.join desk, course_name, semester, '_roster.csv'
end

def courses
Dir[File.join spec, '*', ''].map! { |fn| File.basename fn }
end

def assignments(course)
Dir[File.join spec, course, '*', '_config.yml'].map! do |fn|
def assignments(course_name)
Dir[File.join course(course_name), '*', '_config.yml'].map! do |fn|
File.basename File.dirname fn
end
end

def semesters(course)
Dir[File.join desk, course, '*', '_roster.csv'].map! do |fn|
File.basename File.dirname fn
end
def semesters(course_name)
Dir[roster course_name, '*'].map! { |fn| File.basename File.dirname fn }
end

def load(path)
@@ -48,7 +50,7 @@ module KGrader
when '.yml', '.yaml'
YAML.load File.read(path)
when '.csv'
# TODO
File.read(path).split("\n").map! { |line| line.split "," }
end
end
end


+ 13
- 3
lib/kgrader/roster.rb View File

@@ -6,16 +6,26 @@ module KGrader
@fs = filesystem
@course = course
@semester = semester
@students = nil
end

def load(filename)
# TODO
puts "Loading roster for #{@course.name}:#{@semester} from [#{filename}]..."
@students = @fs.load(filename).map! { |item| item.first }
FileUtils.mkdir_p File.dirname(rosterfile)
File.write rosterfile, @students.join("\n")
end

def students
@students ||= @fs.load(rosterfile).map! { |item| item.first }
end

def intersect(other)
# TODO
["ksmith12"]
end

private
def rosterfile
@fs.roster @course.name, @semester
end
end
end

+ 1
- 0
lib/kgrader/task.rb View File

@@ -6,6 +6,7 @@ module KGrader
@course = course
@semester = semester
@assignment = assignment
@roster = @course.roster @semester
end

def grade(options = {})


Loading…
Cancel
Save