Description:
* multiple ip login fix * fix when points is nil in stat page and user page
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r531:b75c92a947ff - - 6 files changed: 16 inserted, 16 deleted

@@ -1,29 +1,29
1 1 class ConfigurationsController < ApplicationController
2 2
3 3 before_filter :authenticate
4 4 before_filter { |controller| controller.authorization_by_roles(['admin'])}
5 5
6 6
7 7 def index
8 8 @configurations = GraderConfiguration.find(:all,
9 9 :order => '`key`')
10 10 end
11 11
12 12 def reload
13 13 GraderConfiguration.reload
14 14 redirect_to :action => 'index'
15 15 end
16 16
17 17 def update
18 18 @config = GraderConfiguration.find(params[:id])
19 - User.clear_last_login if @config.key = 'multiple_ip_login' and @config.value == 'true' and params[:grader_configuration][:value] == 'false'
19 + User.clear_last_login if @config.key == GraderConfiguration::MULTIPLE_IP_LOGIN_KEY and @config.value == 'true' and params[:grader_configuration][:value] == 'false'
20 20 respond_to do |format|
21 21 if @config.update_attributes(params[:grader_configuration])
22 22 format.json { head :ok }
23 23 else
24 24 format.json { respond_with_bip(@config) }
25 25 end
26 26 end
27 27 end
28 28
29 29 end
@@ -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.try(:points) >= @problem.full_score) ? 1 : 0].max
166 + user[sub.user_id] = [user[sub.user_id], ((sub.try(:points) || 0) >= @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])
@@ -80,97 +80,97
80 80 else
81 81 @result = :email_used
82 82 end
83 83 else
84 84 @result = :failed
85 85 end
86 86 render :action => 'confirm', :layout => 'empty'
87 87 end
88 88
89 89 def forget
90 90 render :action => 'forget', :layout => 'empty'
91 91 end
92 92
93 93 def retrieve_password
94 94 email = params[:email]
95 95 user = User.find_by_email(email)
96 96 if user
97 97 last_updated_time = user.updated_at || user.created_at || (Time.now.gmtime - 1.hour)
98 98 if last_updated_time > Time.now.gmtime - 5.minutes
99 99 flash[:notice] = 'The account has recently created or new password has recently been requested. Please wait for 5 minutes'
100 100 else
101 101 user.password = user.password_confirmation = User.random_password
102 102 user.save
103 103 send_new_password_email(user)
104 104 flash[:notice] = 'New password has been mailed to you.'
105 105 end
106 106 else
107 107 flash[:notice] = I18n.t 'registration.password_retrieval.no_email'
108 108 end
109 109 redirect_to :action => 'forget'
110 110 end
111 111
112 112 def profile
113 113 @user = User.find(params[:id])
114 114 @submission = Submission.includes(:problem).where(user_id: params[:id])
115 115
116 116 range = 120
117 117 @histogram = { data: Array.new(range,0), summary: {} }
118 118 @summary = {count: 0, solve: 0, attempt: 0}
119 119 problem = Hash.new(0)
120 120
121 121 @submission.find_each do |sub|
122 122 #histogram
123 123 d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
124 124 @histogram[:data][d.to_i] += 1 if d < range
125 125
126 126 @summary[:count] += 1
127 127 next unless sub.problem
128 - problem[sub.problem] = [problem[sub.problem], (sub.points >= sub.problem.full_score) ? 1 : 0].max
128 + problem[sub.problem] = [problem[sub.problem], ( (sub.try(:points) || 0) >= sub.problem.full_score) ? 1 : 0].max
129 129 end
130 130
131 131 @histogram[:summary][:max] = [@histogram[:data].max,1].max
132 132 @summary[:attempt] = problem.count
133 133 problem.each_value { |v| @summary[:solve] += 1 if v == 1 }
134 134 end
135 135
136 136 protected
137 137
138 138 def verify_online_registration
139 139 if !GraderConfiguration['system.online_registration']
140 140 redirect_to :controller => 'main', :action => 'login'
141 141 end
142 142 end
143 143
144 144 def send_confirmation_email(user)
145 145 contest_name = GraderConfiguration['contest.name']
146 146 activation_url = url_for(:action => 'confirm',
147 147 :login => user.login,
148 148 :activation => user.activation_key)
149 149 home_url = url_for(:controller => 'main', :action => 'index')
150 150 mail_subject = "[#{contest_name}] Confirmation"
151 151 mail_body = t('registration.email_body', {
152 152 :full_name => user.full_name,
153 153 :contest_name => contest_name,
154 154 :login => user.login,
155 155 :password => user.password,
156 156 :activation_url => activation_url,
157 157 :admin_email => GraderConfiguration['system.admin_email']
158 158 })
159 159
160 160 logger.info mail_body
161 161
162 162 send_mail(user.email, mail_subject, mail_body)
163 163 end
164 164
165 165 def send_new_password_email(user)
166 166 contest_name = GraderConfiguration['contest.name']
167 167 mail_subject = "[#{contest_name}] Password recovery"
168 168 mail_body = t('registration.password_retrieval.email_body', {
169 169 :full_name => user.full_name,
170 170 :contest_name => contest_name,
171 171 :login => user.login,
172 172 :password => user.password,
173 173 :admin_email => GraderConfiguration['system.admin_email']
174 174 })
175 175
176 176 logger.info mail_body
@@ -1,59 +1,60
1 1 require 'yaml'
2 2
3 3 #
4 4 # This class also contains various login of the system.
5 5 #
6 6 class GraderConfiguration < ActiveRecord::Base
7 7
8 8 SYSTEM_MODE_CONF_KEY = 'system.mode'
9 9 TEST_REQUEST_EARLY_TIMEOUT_KEY = 'contest.test_request.early_timeout'
10 10 MULTICONTESTS_KEY = 'system.multicontests'
11 11 CONTEST_TIME_LIMIT_KEY = 'contest.time_limit'
12 + MULTIPLE_IP_LOGIN_KEY = 'right.multiple_ip_login'
12 13
13 14 cattr_accessor :config_cache
14 15 cattr_accessor :task_grading_info_cache
15 16 cattr_accessor :contest_time_str
16 17 cattr_accessor :contest_time
17 18
18 19 GraderConfiguration.config_cache = nil
19 20 GraderConfiguration.task_grading_info_cache = nil
20 21
21 22 def self.config_cached?
22 23 (defined? CONFIGURATION_CACHE_ENABLED) and (CONFIGURATION_CACHE_ENABLED)
23 24 end
24 25
25 26 def self.get(key)
26 27 if GraderConfiguration.config_cached?
27 28 if GraderConfiguration.config_cache == nil
28 29 self.read_config
29 30 end
30 31 return GraderConfiguration.config_cache[key]
31 32 else
32 33 return GraderConfiguration.read_one_key(key)
33 34 end
34 35 end
35 36
36 37 def self.[](key)
37 38 self.get(key)
38 39 end
39 40
40 41 def self.reload
41 42 self.read_config
42 43 end
43 44
44 45 def self.clear
45 46 GraderConfiguration.config_cache = nil
46 47 end
47 48
48 49 #
49 50 # View decision
50 51 #
51 52 def self.show_submitbox_to?(user)
52 53 mode = get(SYSTEM_MODE_CONF_KEY)
53 54 return false if mode=='analysis'
54 55 if (mode=='contest')
55 56 return false if (user.site!=nil) and
56 57 ((user.site.started!=true) or (user.site.finished?))
57 58 end
58 59 return true
59 60 end
@@ -13,54 +13,54
13 13
14 14 %h1= @user.full_name
15 15
16 16 <b>Login:</b> #{@user.login} <br/>
17 17 <b>Full name:</b> #{@user.full_name} <br />
18 18
19 19
20 20 %h2 Problem Stat
21 21 %table.info
22 22 %thead
23 23 %tr.info-head
24 24 %th Stat
25 25 %th Value
26 26 %tbody
27 27 %tr{class: cycle('info-even','info-odd')}
28 28 %td.info_param Submissions
29 29 %td= @summary[:count]
30 30 %tr{class: cycle('info-even','info-odd')}
31 31 %td.info_param Solved/Attempted Problem
32 32 %td #{@summary[:solve]}/#{@summary[:attempt]} (#{(@summary[:solve]*100.0/@summary[:attempt]).round(1)}%)
33 33
34 34 %h2 Submission History
35 35
36 36 =render partial: 'application/bar_graph', locals: {histogram: @histogram, param: {bar_width: 7}}
37 37
38 38
39 39 %table.tablesorter-cafe#submission_table
40 40 %thead
41 41 %tr
42 42 %th ID
43 43 %th Problem code
44 44 %th Problem full name
45 45 %th Language
46 46 %th Submitted at
47 47 %th Result
48 48 %th Score
49 49 - if session[:admin]
50 50 %th IP
51 51 %tbody
52 52 - @submission.each do |s|
53 53 - next unless s.problem
54 54 %tr
55 55 %td= link_to "#{s.id}", controller: "graders", action: "submission", id: s.id
56 56 %td= link_to s.problem.name, controller: "problems", action: "stat", id: s.problem
57 57 %td= s.problem.full_name
58 58 %td= s.language.pretty_name
59 59 %td #{s.submitted_at.strftime('%Y-%m-%d %H:%M')} (#{time_ago_in_words(s.submitted_at)} ago)
60 60 %td.fix-width= s.grader_comment
61 - %td= (s.points*100)/s.problem.full_score
61 + %td= ( s.try(:points) ? (s.points*100/s.problem.full_score) : '' )
62 62 - if session[:admin]
63 63 %td= s.ip_address
64 64
65 65
66 66
@@ -1,257 +1,256
1 1 # encoding: UTF-8
2 2 # This file is auto-generated from the current state of the database. Instead
3 3 # of editing this file, please use the migrations feature of Active Record to
4 4 # incrementally modify your database, and then regenerate this schema definition.
5 5 #
6 6 # Note that this schema.rb definition is the authoritative source for your
7 7 # database schema. If you need to create the application database on another
8 8 # system, you should be using db:schema:load, not running all the migrations
9 9 # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10 10 # you'll amass, the slower it'll run and the greater likelihood for issues).
11 11 #
12 12 # It's strongly recommended to check this file into your version control system.
13 13
14 14 ActiveRecord::Schema.define(:version => 20150827133841) do
15 15
16 16 create_table "announcements", :force => true do |t|
17 17 t.string "author"
18 - t.text "body", :limit => 16777215
18 + t.text "body"
19 19 t.boolean "published"
20 20 t.datetime "created_at", :null => false
21 21 t.datetime "updated_at", :null => false
22 22 t.boolean "frontpage", :default => false
23 23 t.boolean "contest_only", :default => false
24 24 t.string "title"
25 25 t.string "notes"
26 26 end
27 27
28 28 create_table "contests", :force => true do |t|
29 29 t.string "title"
30 30 t.boolean "enabled"
31 31 t.datetime "created_at", :null => false
32 32 t.datetime "updated_at", :null => false
33 33 t.string "name"
34 34 end
35 35
36 36 create_table "contests_problems", :id => false, :force => true do |t|
37 37 t.integer "contest_id"
38 38 t.integer "problem_id"
39 39 end
40 40
41 41 create_table "contests_users", :id => false, :force => true do |t|
42 42 t.integer "contest_id"
43 43 t.integer "user_id"
44 44 end
45 45
46 46 create_table "countries", :force => true do |t|
47 47 t.string "name"
48 48 t.datetime "created_at", :null => false
49 49 t.datetime "updated_at", :null => false
50 50 end
51 51
52 52 create_table "descriptions", :force => true do |t|
53 - t.text "body", :limit => 16777215
53 + t.text "body"
54 54 t.boolean "markdowned"
55 55 t.datetime "created_at", :null => false
56 56 t.datetime "updated_at", :null => false
57 57 end
58 58
59 59 create_table "grader_configurations", :force => true do |t|
60 60 t.string "key"
61 61 t.string "value_type"
62 62 t.string "value"
63 63 t.datetime "created_at", :null => false
64 64 t.datetime "updated_at", :null => false
65 - t.text "description", :limit => 16777215
65 + t.text "description"
66 66 end
67 67
68 68 create_table "grader_processes", :force => true do |t|
69 69 t.string "host", :limit => 20
70 70 t.integer "pid"
71 71 t.string "mode"
72 72 t.boolean "active"
73 73 t.datetime "created_at", :null => false
74 74 t.datetime "updated_at", :null => false
75 75 t.integer "task_id"
76 76 t.string "task_type"
77 77 t.boolean "terminated"
78 78 end
79 79
80 80 add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
81 81
82 82 create_table "languages", :force => true do |t|
83 83 t.string "name", :limit => 10
84 84 t.string "pretty_name"
85 85 t.string "ext", :limit => 10
86 86 t.string "common_ext"
87 87 end
88 88
89 89 create_table "logins", :force => true do |t|
90 90 t.integer "user_id"
91 91 t.string "ip_address"
92 92 t.datetime "created_at", :null => false
93 93 t.datetime "updated_at", :null => false
94 94 end
95 95
96 96 create_table "messages", :force => true do |t|
97 97 t.integer "sender_id"
98 98 t.integer "receiver_id"
99 99 t.integer "replying_message_id"
100 - t.text "body", :limit => 16777215
100 + t.text "body"
101 101 t.boolean "replied"
102 102 t.datetime "created_at", :null => false
103 103 t.datetime "updated_at", :null => false
104 104 end
105 105
106 106 create_table "problems", :force => true do |t|
107 107 t.string "name", :limit => 30
108 108 t.string "full_name"
109 109 t.integer "full_score"
110 110 t.date "date_added"
111 111 t.boolean "available"
112 112 t.string "url"
113 113 t.integer "description_id"
114 114 t.boolean "test_allowed"
115 115 t.boolean "output_only"
116 116 t.string "description_filename"
117 117 end
118 118
119 119 create_table "rights", :force => true do |t|
120 120 t.string "name"
121 121 t.string "controller"
122 122 t.string "action"
123 123 end
124 124
125 125 create_table "rights_roles", :id => false, :force => true do |t|
126 126 t.integer "right_id"
127 127 t.integer "role_id"
128 128 end
129 129
130 130 add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id"
131 131
132 132 create_table "roles", :force => true do |t|
133 133 t.string "name"
134 134 end
135 135
136 136 create_table "roles_users", :id => false, :force => true do |t|
137 137 t.integer "role_id"
138 138 t.integer "user_id"
139 139 end
140 140
141 141 add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id"
142 142
143 143 create_table "sessions", :force => true do |t|
144 144 t.string "session_id"
145 - t.text "data", :limit => 16777215
145 + t.text "data"
146 146 t.datetime "updated_at"
147 147 end
148 148
149 149 add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
150 150 add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
151 151
152 152 create_table "sites", :force => true do |t|
153 153 t.string "name"
154 154 t.boolean "started"
155 155 t.datetime "start_time"
156 156 t.datetime "created_at", :null => false
157 157 t.datetime "updated_at", :null => false
158 158 t.integer "country_id"
159 159 t.string "password"
160 160 end
161 161
162 162 create_table "submission_view_logs", :force => true do |t|
163 163 t.integer "user_id"
164 164 t.integer "submission_id"
165 165 t.datetime "created_at", :null => false
166 166 t.datetime "updated_at", :null => false
167 167 end
168 168
169 169 create_table "submissions", :force => true do |t|
170 170 t.integer "user_id"
171 171 t.integer "problem_id"
172 172 t.integer "language_id"
173 - t.text "source", :limit => 16777215
173 + t.text "source"
174 174 t.binary "binary"
175 175 t.datetime "submitted_at"
176 176 t.datetime "compiled_at"
177 - t.text "compiler_message", :limit => 16777215
177 + t.text "compiler_message"
178 178 t.datetime "graded_at"
179 179 t.integer "points"
180 - t.text "grader_comment", :limit => 16777215
180 + t.text "grader_comment"
181 181 t.integer "number"
182 182 t.string "source_filename"
183 183 t.float "max_runtime"
184 184 t.integer "peak_memory"
185 185 t.integer "effective_code_length"
186 186 t.string "ip_address"
187 187 end
188 188
189 189 add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true
190 190 add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id"
191 191
192 192 create_table "tasks", :force => true do |t|
193 193 t.integer "submission_id"
194 194 t.datetime "created_at"
195 195 t.integer "status"
196 196 t.datetime "updated_at"
197 197 end
198 198
199 199 create_table "test_pairs", :force => true do |t|
200 200 t.integer "problem_id"
201 - t.text "input", :limit => 2147483647
202 - t.text "solution", :limit => 2147483647
201 + t.text "input", :limit => 16777215
202 + t.text "solution", :limit => 16777215
203 203 t.datetime "created_at", :null => false
204 204 t.datetime "updated_at", :null => false
205 205 end
206 206
207 207 create_table "test_requests", :force => true do |t|
208 208 t.integer "user_id"
209 209 t.integer "problem_id"
210 210 t.integer "submission_id"
211 211 t.string "input_file_name"
212 212 t.string "output_file_name"
213 213 t.string "running_stat"
214 214 t.integer "status"
215 215 t.datetime "updated_at", :null => false
216 216 t.datetime "submitted_at"
217 217 t.datetime "compiled_at"
218 - t.text "compiler_message", :limit => 16777215
218 + t.text "compiler_message"
219 219 t.datetime "graded_at"
220 220 t.string "grader_comment"
221 221 t.datetime "created_at", :null => false
222 222 t.float "running_time"
223 223 t.string "exit_status"
224 224 t.integer "memory_usage"
225 225 end
226 226
227 227 add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id"
228 228
229 229 create_table "user_contest_stats", :force => true do |t|
230 230 t.integer "user_id"
231 231 t.datetime "started_at"
232 232 t.datetime "created_at", :null => false
233 233 t.datetime "updated_at", :null => false
234 234 t.boolean "forced_logout"
235 235 end
236 236
237 237 create_table "users", :force => true do |t|
238 238 t.string "login", :limit => 50
239 239 t.string "full_name"
240 240 t.string "hashed_password"
241 241 t.string "salt", :limit => 5
242 242 t.string "alias"
243 243 t.string "email"
244 244 t.integer "site_id"
245 245 t.integer "country_id"
246 246 t.boolean "activated", :default => false
247 247 t.datetime "created_at"
248 248 t.datetime "updated_at"
249 - t.string "section"
250 249 t.boolean "enabled", :default => true
251 250 t.string "remark"
252 251 t.string "last_ip"
253 252 end
254 253
255 254 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
256 255
257 256 end
You need to be logged in to leave comments. Login now