Description:
import problem replaced old one, fixed small problems problem validates name to have no space, test interface can deal with broken dependecies on problems. git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@436 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r205:9bf8e38c2911 - - 5 files changed: 15 inserted, 3 deleted

@@ -111,79 +111,87
111 111 def turn_all_off
112 112 Problem.find(:all,
113 113 :conditions => "available = 1").each do |problem|
114 114 problem.available = false
115 115 problem.save
116 116 end
117 117 redirect_to :action => 'list'
118 118 end
119 119
120 120 def turn_all_on
121 121 Problem.find(:all,
122 122 :conditions => "available = 0").each do |problem|
123 123 problem.available = true
124 124 problem.save
125 125 end
126 126 redirect_to :action => 'list'
127 127 end
128 128
129 129 def stat
130 130 @problem = Problem.find(params[:id])
131 131 if !@problem.available
132 132 redirect_to :controller => 'main', :action => 'list'
133 133 else
134 134 @submissions = Submission.find_all_last_by_problem(params[:id])
135 135 end
136 136 end
137 137
138 138 def manage
139 139 @problems = Problem.find(:all, :order => 'date_added DESC')
140 140 end
141 141
142 142 def do_manage
143 143 if params.has_key? 'change_date_added'
144 144 change_date_added
145 145 end
146 146 redirect_to :action => 'manage'
147 147 end
148 148
149 149 def import
150 150 end
151 151
152 152 def do_import
153 153 @problem, import_log = Problem.new_from_import_form_params(params)
154 154
155 155 if @problem.errors.length != 0
156 156 render :action => 'import' and return
157 157 end
158 158
159 + old_problem = Problem.find_by_name(@problem.name)
160 + if old_problem!=nil
161 + old_problem.full_name = @problem.full_name
162 + @problem = old_problem
163 +
164 + flash[:notice] = "The test data has been replaced for problem #{@problem.name}"
165 + end
166 +
159 167 @problem.save
160 168 @log = import_log
161 169 end
162 170
163 171 ##################################
164 172 protected
165 173
166 174 def change_date_added
167 175 problems = get_problems_from_params
168 176 year = params[:date_added][:year].to_i
169 177 month = params[:date_added][:month].to_i
170 178 day = params[:date_added][:day].to_i
171 179 date = Date.new(year,month,day)
172 180 problems.each do |p|
173 181 p.date_added = date
174 182 p.save
175 183 end
176 184 end
177 185
178 186 def get_problems_from_params
179 187 problems = []
180 188 params.keys.each do |k|
181 189 if k.index('prob-')==0
182 190 name, id = k.split('-')
183 191 problems << Problem.find(id)
184 192 end
185 193 end
186 194 problems
187 195 end
188 196
189 197 end
@@ -56,65 +56,65
56 56 test_request = nil
57 57 end
58 58 if test_request==nil or test_request.user_id != user.id
59 59 flash[:notice] = 'Invalid output'
60 60 redirect_to :action => 'index'
61 61 return
62 62 end
63 63 if test_request.output_file_name!=nil
64 64 data = File.open(test_request.output_file_name).read(2048)
65 65 if data==nil
66 66 data=""
67 67 end
68 68 send_data(data,
69 69 {:filename => 'output.txt',
70 70 :type => 'text/plain'})
71 71 return
72 72 end
73 73 redirect_to :action => 'index'
74 74 end
75 75
76 76 def result
77 77 @user = User.find(session[:user_id])
78 78 begin
79 79 @test_request = TestRequest.find(params[:id])
80 80 rescue
81 81 @test_request = nil
82 82 end
83 83 if @test_request==nil or @test_request.user_id != @user.id
84 84 flash[:notice] = 'Invalid request'
85 85 redirect_to :action => 'index'
86 86 return
87 87 end
88 88 end
89 89
90 90 protected
91 91
92 92 def prepare_index_information
93 93 @user = User.find(session[:user_id])
94 94 @submissions = Submission.find_last_for_all_available_problems(@user.id)
95 95 all_problems = @submissions.collect { |submission| submission.problem }
96 96 @problems = []
97 97 all_problems.each do |problem|
98 98 if problem.test_allowed
99 99 @problems << problem
100 100 end
101 101 end
102 102 @test_requests = []
103 103 @user.test_requests.each do |ts|
104 - if ts.problem.available
104 + if ts.problem and ts.problem.available
105 105 @test_requests << ts
106 106 end
107 107 end
108 108 end
109 109
110 110 def check_viewability
111 111 user = User.find(session[:user_id])
112 112 if !Configuration.show_tasks_to?(user)
113 113 redirect_to :controller => 'main', :action => 'list'
114 114 end
115 115 if (!Configuration.show_submitbox_to?(user)) and (action_name=='submit')
116 116 redirect_to :controller => 'test', :action => 'index'
117 117 end
118 118 end
119 119
120 120 end
@@ -1,55 +1,56
1 1 class Problem < ActiveRecord::Base
2 2
3 3 belongs_to :description
4 4
5 5 validates_presence_of :name
6 + validates_format_of :name, :with => /^\w+$/
6 7 validates_presence_of :full_name
7 -
8 +
8 9 def self.find_available_problems
9 10 find(:all, :conditions => {:available => true}, :order => "date_added DESC")
10 11 end
11 12
12 13 def self.new_from_import_form_params(params)
13 14 problem = Problem.new
14 15
15 16 # form error checking
16 17
17 18 time_limit_s = params[:time_limit]
18 19 memory_limit_s = params[:memory_limit]
19 20
20 21 time_limit_s = '1' if time_limit_s==''
21 22 memory_limit_s = '32' if memory_limit_s==''
22 23
23 24 time_limit = time_limit_s.to_i
24 25 memory_limit = memory_limit_s.to_i
25 26
26 27 if time_limit==0 and time_limit_s!='0'
27 28 problem.errors.add_to_base('Time limit format errors.')
28 29 elsif time_limit<=0 or time_limit >60
29 30 problem.errors.add_to_base('Time limit out of range.')
30 31 end
31 32
32 33 if memory_limit==0 and memory_limit_s!='0'
33 34 problem.errors.add_to_base('Memory limit format errors.')
34 35 elsif memory_limit<=0 or memory_limit >512
35 36 problem.errors.add_to_base('Memory limit out of range.')
36 37 end
37 38
38 39 if params[:file]==nil or params[:file]==''
39 40 problem.errors.add_to_base('No testdata file.')
40 41 end
41 42
42 43 file = params[:file]
43 44
44 45 if problem.errors.length!=0
45 46 return problem
46 47 end
47 48
48 49 problem.name = params[:name]
49 50 if params[:full_name]!=''
50 51 problem.full_name = params[:full_name]
51 52 else
52 53 problem.full_name = params[:name]
53 54 end
54 55
55 56 if not problem.valid?
@@ -1,48 +1,51
1 1 - content_for :head do
2 2 = stylesheet_link_tag 'graders'
3 3 <meta http-equiv ="refresh" content="60"/>
4 4
5 5 %h1 Grader information
6 6
7 + = link_to '[Refresh]', :action => 'list'
8 + %br/
9 +
7 10 .submitbox
8 11 .item
9 12 Grader control:
10 13 .item
11 14 - form_for :clear, nil, :url => {:action => 'start_grading'} do |f|
12 15 = submit_tag 'Start graders in grading env'
13 16 .item
14 17 - form_for :clear, nil, :url => {:action => 'start_exam'} do |f|
15 18 = submit_tag 'Start graders in exam env'
16 19 .item
17 20 - form_for :clear, nil, :url => {:action => 'stop_all'} do |f|
18 21 = submit_tag 'Stop all running graders'
19 22 .item
20 23 - form_for :clear, nil, :url => {:action => 'clear_all'} do |f|
21 24 = submit_tag 'Clear all data'
22 25 %br{:style => 'clear:both'}/
23 26
24 27 - if @last_task
25 28 Last task:
26 29 = link_to "#{@last_task.id}", :action => 'view', :id => @last_task.id, :type => 'Task'
27 30
28 31 %br/
29 32
30 33 - if @last_test_request
31 34 Last test_request:
32 35 = link_to "#{@last_test_request.id}", :action => 'view', :id => @last_test_request.id, :type => 'TestRequest'
33 36
34 37
35 38 %h2 Current graders
36 39
37 40 = render :partial => 'grader_list', :locals => {:grader_list => @grader_processes}
38 41
39 42 %h2 Stalled graders
40 43
41 44 = render :partial => 'grader_list', :locals => {:grader_list => @stalled_processes}
42 45
43 46 %h2 Terminated graders
44 47
45 48 - form_for :clear, nil, :url => {:action => 'clear_terminated'} do |f|
46 49 = submit_tag 'Clear data for terminated graders'
47 50
48 51 = render :partial => 'grader_list', :locals => {:grader_list => @terminated_processes}
@@ -1,76 +1,76
1 1 require 'tmpdir'
2 2
3 3 class TestdataImporter
4 4
5 5 attr :log_msg
6 6
7 7 def import_from_file(problem_name,
8 8 tempfile,
9 9 time_limit,
10 10 memory_limit)
11 11
12 12 dirname = TestdataImporter.extract(problem_name, tempfile)
13 13 return false if not dirname
14 14 @log_msg = GraderScript.call_import_problem(problem_name,
15 15 dirname,
16 16 time_limit,
17 17 memory_limit)
18 18 return true
19 19 end
20 20
21 21 protected
22 22
23 23 def self.long_ext(filename)
24 24 i = filename.index('.')
25 25 len = filename.length
26 26 return filename.slice(i..len)
27 27 end
28 28
29 29 def self.extract(problem_name, tempfile)
30 30 testdata_filename = TestdataImporter.save_testdata_file(problem_name,
31 31 tempfile)
32 32 ext = TestdataImporter.long_ext(tempfile.original_filename)
33 33
34 34 extract_dir = File.join(GraderScript.raw_dir, problem_name)
35 35 begin
36 36 Dir.mkdir extract_dir
37 37 rescue Errno::EEXIST
38 38 end
39 39
40 40 if ext=='.tar.gz' or ext=='.tgz'
41 41 cmd = "tar -zxvf #{testdata_filename} -C #{extract_dir}"
42 42 elsif ext=='.tar'
43 43 cmd = "tar -xvf #{testdata_filename} -C #{extract_dir}"
44 44 elsif ext=='.zip'
45 - cmd = "unzip #{testdata_filename} -d #{extract_dir}"
45 + cmd = "unzip -o #{testdata_filename} -d #{extract_dir}"
46 46 else
47 47 return nil
48 48 end
49 49
50 50 system(cmd)
51 51
52 52 files = Dir["#{extract_dir}/**/1*.in"]
53 53 return nil if files.length==0
54 54
55 55 return File.dirname(files[0])
56 56 end
57 57
58 58 def self.save_testdata_file(problem_name, tempfile)
59 59 ext = TestdataImporter.long_ext(tempfile.original_filename)
60 60 testdata_filename = File.join(Dir.tmpdir,"#{problem_name}#{ext}")
61 61
62 62 return nil if tempfile==""
63 63
64 64 if tempfile.instance_of?(Tempfile)
65 65 tempfile.close
66 66 FileUtils.move(tempfile.path,testdata_filename)
67 67 else
68 68 File.open(testdata_filename, "wb") do |f|
69 69 f.write(tempfile.read)
70 70 end
71 71 end
72 72
73 73 return testdata_filename
74 74 end
75 75
76 76 end
You need to be logged in to leave comments. Login now