From 0db69377db88238ab268d0cba7406bfdfed2024b Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Thu, 24 Mar 2016 01:50:20 -0400 Subject: [PATCH] Roster loading --- lib/kgrader/course.rb | 6 +++--- lib/kgrader/filesystem.rb | 16 +++++++++------- lib/kgrader/roster.rb | 16 +++++++++++++--- lib/kgrader/task.rb | 1 + 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/kgrader/course.rb b/lib/kgrader/course.rb index b6bd37f..b42f1da 100644 --- a/lib/kgrader/course.rb +++ b/lib/kgrader/course.rb @@ -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 diff --git a/lib/kgrader/filesystem.rb b/lib/kgrader/filesystem.rb index 8e29759..746355e 100644 --- a/lib/kgrader/filesystem.rb +++ b/lib/kgrader/filesystem.rb @@ -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 diff --git a/lib/kgrader/roster.rb b/lib/kgrader/roster.rb index 108a5d4..0ca2660 100644 --- a/lib/kgrader/roster.rb +++ b/lib/kgrader/roster.rb @@ -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 diff --git a/lib/kgrader/task.rb b/lib/kgrader/task.rb index 9af9ab7..5a96aa0 100644 --- a/lib/kgrader/task.rb +++ b/lib/kgrader/task.rb @@ -6,6 +6,7 @@ module KGrader @course = course @semester = semester @assignment = assignment + @roster = @course.roster @semester end def grade(options = {})