Description:
Merge pull request #6 from nattee/master add options for grading all submissions of a specific problem
Commit status:
[Not Reviewed]
References:
merge default
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r200:3db773289a2d - - 2 files changed: 28 inserted, 7 deleted

@@ -46,11 +46,22
46 puts <<USAGE
46 puts <<USAGE
47 Grader.
47 Grader.
48 using: (1) grader
48 using: (1) grader
49 - (2) grader environment [mode]
49 + (2) grader environment [mode] [options]
50 (3) grader stop [all|pids-list]
50 (3) grader stop [all|pids-list]
51 (4) grader --help
51 (4) grader --help
52 (1) call grader with environment = 'exam', mode = 'queue'
52 (1) call grader with environment = 'exam', mode = 'queue'
53 (2) possible modes are: 'queue', 'test_request', 'prob', 'sub', 'contest', and 'autonew'
53 (2) possible modes are: 'queue', 'test_request', 'prob', 'sub', 'contest', and 'autonew'
54 + queue: repeatedly check the task queue and grade any available tasks
55 +
56 + prob: re-grade every user latest submission of the specific problem.
57 + the problem name must be specified by the next argument.
58 +
59 + additional options:
60 +
61 + --all-sub re-grade every submissions instead of just the latest submission of each user.
62 + sub: re-grader the specified submission.
63 + The submission ID to be re-graded must be specified by the next argument.
64 +
54 (3) create stop-file to stop running grader in queue mode
65 (3) create stop-file to stop running grader in queue mode
55 (4) You are here.
66 (4) You are here.
56 USAGE
67 USAGE
@@ -105,6 +116,8
105 if ARGV.length >=1
116 if ARGV.length >=1
106 options[:mode] = ARGV.shift
117 options[:mode] = ARGV.shift
107 end
118 end
119 + else
120 + puts 'no argument specified, using default mode and environment.'
108 end
121 end
109
122
110 options[:dry_run] = (ARGV.delete('--dry') != nil)
123 options[:dry_run] = (ARGV.delete('--dry') != nil)
@@ -119,6 +132,8
119 exit(0)
132 exit(0)
120 end
133 end
121
134
135 + options[:all_sub] = (ARGV.delete('--all-sub') != nil)
136 +
122 return options
137 return options
123 end
138 end
124
139
@@ -295,7 +310,7
295 if prob==nil
310 if prob==nil
296 puts "cannot find problem: #{prob_name}"
311 puts "cannot find problem: #{prob_name}"
297 else
312 else
298 - runner.grade_problem(prob)
313 + runner.grade_problem(prob,options)
299 end
314 end
300 end
315 end
301
316
@@ -378,6 +393,7
378 dry_run = options[:dry_run]
393 dry_run = options[:dry_run]
379
394
380 puts "environment: #{GRADER_ENV}"
395 puts "environment: #{GRADER_ENV}"
396 + puts "grader mode: #{grader_mode}"
381 require File.join(File.dirname(__FILE__),'config/environment')
397 require File.join(File.dirname(__FILE__),'config/environment')
382
398
383 # add grader_mode to config
399 # add grader_mode to config
@@ -25,16 +25,21
25 end
25 end
26
26
27 def grade_problem(problem, options={})
27 def grade_problem(problem, options={})
28 - users = User.find(:all)
28 + User.find_each do |u|
29 - users.each do |u|
30 puts "user: #{u.login}"
29 puts "user: #{u.login}"
31 if options[:user_conditions]!=nil
30 if options[:user_conditions]!=nil
32 con_proc = options[:user_conditions]
31 con_proc = options[:user_conditions]
33 next if not con_proc.call(u)
32 next if not con_proc.call(u)
34 end
33 end
35 - last_sub = Submission.find_last_by_user_and_problem(u.id,problem.id)
34 + if options[:all_sub]
36 - if last_sub!=nil
35 + Submission.where(user_id: u.id,problem_id: problem.id).find_each do |sub|
37 - @engine.grade(last_sub)
36 + @engine.grade(sub)
37 + end
38 + else
39 + last_sub = Submission.find_last_by_user_and_problem(u.id,problem.id)
40 + if last_sub!=nil
41 + @engine.grade(last_sub)
42 + end
38 end
43 end
39 end
44 end
40 end
45 end
You need to be logged in to leave comments. Login now