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