Description:
fix bug when score is nil
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r492:9941b31fd734 - - 1 file changed: 1 inserted, 1 deleted
@@ -118,97 +118,97 | |||||
|
118 | render :action => 'edit' |
|
118 | render :action => 'edit' |
|
119 | end |
|
119 | end |
|
120 | end |
|
120 | end |
|
121 |
|
121 | ||
|
122 | def destroy |
|
122 | def destroy |
|
123 | Problem.find(params[:id]).destroy |
|
123 | Problem.find(params[:id]).destroy |
|
124 | redirect_to :action => 'list' |
|
124 | redirect_to :action => 'list' |
|
125 | end |
|
125 | end |
|
126 |
|
126 | ||
|
127 | def toggle |
|
127 | def toggle |
|
128 | @problem = Problem.find(params[:id]) |
|
128 | @problem = Problem.find(params[:id]) |
|
129 | @problem.available = !(@problem.available) |
|
129 | @problem.available = !(@problem.available) |
|
130 | @problem.save |
|
130 | @problem.save |
|
131 | end |
|
131 | end |
|
132 |
|
132 | ||
|
133 | def turn_all_off |
|
133 | def turn_all_off |
|
134 | Problem.find(:all, |
|
134 | Problem.find(:all, |
|
135 | :conditions => "available = 1").each do |problem| |
|
135 | :conditions => "available = 1").each do |problem| |
|
136 | problem.available = false |
|
136 | problem.available = false |
|
137 | problem.save |
|
137 | problem.save |
|
138 | end |
|
138 | end |
|
139 | redirect_to :action => 'list' |
|
139 | redirect_to :action => 'list' |
|
140 | end |
|
140 | end |
|
141 |
|
141 | ||
|
142 | def turn_all_on |
|
142 | def turn_all_on |
|
143 | Problem.find(:all, |
|
143 | Problem.find(:all, |
|
144 | :conditions => "available = 0").each do |problem| |
|
144 | :conditions => "available = 0").each do |problem| |
|
145 | problem.available = true |
|
145 | problem.available = true |
|
146 | problem.save |
|
146 | problem.save |
|
147 | end |
|
147 | end |
|
148 | redirect_to :action => 'list' |
|
148 | redirect_to :action => 'list' |
|
149 | end |
|
149 | end |
|
150 |
|
150 | ||
|
151 | def stat |
|
151 | def stat |
|
152 | @problem = Problem.find(params[:id]) |
|
152 | @problem = Problem.find(params[:id]) |
|
153 | unless @problem.available or session[:admin] |
|
153 | unless @problem.available or session[:admin] |
|
154 | redirect_to :controller => 'main', :action => 'list' |
|
154 | redirect_to :controller => 'main', :action => 'list' |
|
155 | return |
|
155 | return |
|
156 | end |
|
156 | end |
|
157 | @submissions = Submission.includes(:user).where(problem_id: params[:id]).order(:user_id,:id) |
|
157 | @submissions = Submission.includes(:user).where(problem_id: params[:id]).order(:user_id,:id) |
|
158 |
|
158 | ||
|
159 | #stat summary |
|
159 | #stat summary |
|
160 | range =65 |
|
160 | range =65 |
|
161 | @histogram = { data: Array.new(range,0), summary: {} } |
|
161 | @histogram = { data: Array.new(range,0), summary: {} } |
|
162 | user = Hash.new(0) |
|
162 | user = Hash.new(0) |
|
163 | @submissions.find_each do |sub| |
|
163 | @submissions.find_each do |sub| |
|
164 | d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 |
|
164 | d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 |
|
165 | @histogram[:data][d.to_i] += 1 if d < range |
|
165 | @histogram[:data][d.to_i] += 1 if d < range |
|
166 | - user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max |
|
166 | + user[sub.user_id] = [user[sub.user_id], ( sub.try(:points) >= @problem.full_score) ? 1 : 0].max |
|
167 | end |
|
167 | end |
|
168 | @histogram[:summary][:max] = [@histogram[:data].max,1].max |
|
168 | @histogram[:summary][:max] = [@histogram[:data].max,1].max |
|
169 |
|
169 | ||
|
170 | @summary = { attempt: user.count, solve: 0 } |
|
170 | @summary = { attempt: user.count, solve: 0 } |
|
171 | user.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
171 | user.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
172 | end |
|
172 | end |
|
173 |
|
173 | ||
|
174 | def manage |
|
174 | def manage |
|
175 | @problems = Problem.find(:all, :order => 'date_added DESC') |
|
175 | @problems = Problem.find(:all, :order => 'date_added DESC') |
|
176 | end |
|
176 | end |
|
177 |
|
177 | ||
|
178 | def do_manage |
|
178 | def do_manage |
|
179 | if params.has_key? 'change_date_added' |
|
179 | if params.has_key? 'change_date_added' |
|
180 | change_date_added |
|
180 | change_date_added |
|
181 | elsif params.has_key? 'add_to_contest' |
|
181 | elsif params.has_key? 'add_to_contest' |
|
182 | add_to_contest |
|
182 | add_to_contest |
|
183 | elsif params.has_key? 'enable_problem' |
|
183 | elsif params.has_key? 'enable_problem' |
|
184 | set_available(true) |
|
184 | set_available(true) |
|
185 | elsif params.has_key? 'disable_problem' |
|
185 | elsif params.has_key? 'disable_problem' |
|
186 | set_available(false) |
|
186 | set_available(false) |
|
187 | end |
|
187 | end |
|
188 | redirect_to :action => 'manage' |
|
188 | redirect_to :action => 'manage' |
|
189 | end |
|
189 | end |
|
190 |
|
190 | ||
|
191 | def import |
|
191 | def import |
|
192 | @allow_test_pair_import = allow_test_pair_import? |
|
192 | @allow_test_pair_import = allow_test_pair_import? |
|
193 | end |
|
193 | end |
|
194 |
|
194 | ||
|
195 | def do_import |
|
195 | def do_import |
|
196 | old_problem = Problem.find_by_name(params[:name]) |
|
196 | old_problem = Problem.find_by_name(params[:name]) |
|
197 | if !allow_test_pair_import? and params.has_key? :import_to_db |
|
197 | if !allow_test_pair_import? and params.has_key? :import_to_db |
|
198 | params.delete :import_to_db |
|
198 | params.delete :import_to_db |
|
199 | end |
|
199 | end |
|
200 | @problem, import_log = Problem.create_from_import_form_params(params, |
|
200 | @problem, import_log = Problem.create_from_import_form_params(params, |
|
201 | old_problem) |
|
201 | old_problem) |
|
202 |
|
202 | ||
|
203 | if !@problem.errors.empty? |
|
203 | if !@problem.errors.empty? |
|
204 | render :action => 'import' and return |
|
204 | render :action => 'import' and return |
|
205 | end |
|
205 | end |
|
206 |
|
206 | ||
|
207 | if old_problem!=nil |
|
207 | if old_problem!=nil |
|
208 | flash[:notice] = "The test data has been replaced for problem #{@problem.name}" |
|
208 | flash[:notice] = "The test data has been replaced for problem #{@problem.name}" |
|
209 | end |
|
209 | end |
|
210 | @log = import_log |
|
210 | @log = import_log |
|
211 | end |
|
211 | end |
|
212 |
|
212 | ||
|
213 | def remove_contest |
|
213 | def remove_contest |
|
214 | problem = Problem.find(params[:id]) |
|
214 | problem = Problem.find(params[:id]) |
You need to be logged in to leave comments.
Login now