class SRS::CLI::Reschedule
Public Instance Methods
getScheduler(schedulername)
click to toggle source
# File lib/srs/cli/reschedule.rb, line 67 def getScheduler(schedulername) begin require "./schedulers/#{schedulername}" rescue LoadError begin require "srs/schedulers/#{schedulername}" rescue LoadError puts "Couldn't find scheduler #{schedulername}." return nil end end SRS::Schedulers.const_get(schedulername.to_sym).new end
help()
click to toggle source
# File lib/srs/cli/reschedule.rb, line 82 def help() puts <<-EOF srs reschedule <id> <score> Rescedules the exercise being set by schedule id according to the score supplied. Makes use of the scheduler defined for that schedule. The score passed in will typically be that returned from do-exercise. EOF end
run!(arguments)
click to toggle source
# File lib/srs/cli/reschedule.rb, line 6 def run!(arguments) if not SRS::Workspace.initialised? then puts "Current directory is not an SRS Workspace" return 3 end schedule_id = arguments.shift score = arguments.shift.to_f is_new = false; schedulefile = "schedule/#{schedule_id}" if not File.exists?(schedulefile) then schedulefile = "schedule/pending/#{schedule_id}" is_new = true if not File.exists?(schedulefile) then puts "No content with that ID exists" return 4 end end headers = {} File.open(schedulefile, "r") do |file| while( line = file.gets() ) do if line.strip.empty? then break end key, *val = line.split(':').map{|e| e.strip} headers[key] = val.join(':') end end if not headers.has_key?("Scheduler") then puts "Schedule #{schedule_id} has no scheduler!\n" return 6 end exercise = headers.delete("Exercise") schedulername = headers.delete("Scheduler") scheduler = getScheduler(schedulername) headersOut = is_new ? scheduler.first_rep(score) : scheduler.rep(score, headers) FileUtils.rm_rf( schedulefile ) fileOut = "schedule/#{schedule_id}" File.open(fileOut, "w") do |file| file.puts "Exercise: #{exercise}" file.puts "Scheduler: #{schedulername}" headersOut.each do |key, value| file.puts "#{key}: #{value.to_s}" end end puts "Exercise rescheduled for #{headersOut["Due"]}" puts "Exercise failed; marked for repetition" if headersOut["Repeat"] return 0 end