Description:
fix logins user_id from string to integer
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r504:83c7ff482214 - - 2 files changed: 31 inserted, 27 deleted

@@ -63,193 +63,196
63 63 @until_time = DateTime.new(3000,1,1)
64 64 end
65 65
66 66 @submissions = {}
67 67
68 68 User.find_each do |user|
69 69 @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } }
70 70 end
71 71
72 72 Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s|
73 73 if @submissions[s.user_id]
74 74 if not @submissions[s.user_id][:sub].has_key?(s.problem_id)
75 75 a = nil
76 76 begin
77 77 a = Problem.find(s.problem_id)
78 78 rescue
79 79 a = nil
80 80 end
81 81 @submissions[s.user_id][:sub][s.problem_id] =
82 82 { prob_name: (a ? a.full_name : '(NULL)'),
83 83 sub_ids: [s.id] }
84 84 else
85 85 @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id
86 86 end
87 87 @submissions[s.user_id][:count] += 1
88 88 end
89 89 end
90 90 end
91 91
92 92 def problem_hof
93 93 # gen problem list
94 94 @user = User.find(session[:user_id])
95 95 @problems = @user.available_problems
96 96
97 97 # get selected problems or the default
98 98 if params[:id]
99 99 begin
100 100 @problem = Problem.available.find(params[:id])
101 101 rescue
102 102 redirect_to action: :problem_hof
103 103 flash[:notice] = 'Error: submissions for that problem are not viewable.'
104 104 return
105 105 end
106 106 end
107 107
108 108 return unless @problem
109 109
110 110 @by_lang = {} #aggregrate by language
111 111
112 112 range =65
113 113 @histogram = { data: Array.new(range,0), summary: {} }
114 114 @summary = {count: 0, solve: 0, attempt: 0}
115 115 user = Hash.new(0)
116 116 Submission.where(problem_id: @problem.id).find_each do |sub|
117 117 #histogram
118 118 d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
119 119 @histogram[:data][d.to_i] += 1 if d < range
120 120
121 121 next unless sub.points
122 122 @summary[:count] += 1
123 123 user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max
124 124
125 125 lang = Language.find_by_id(sub.language_id)
126 126 next unless lang
127 127 next unless sub.points >= @problem.full_score
128 128
129 129 #initialize
130 130 unless @by_lang.has_key?(lang.pretty_name)
131 131 @by_lang[lang.pretty_name] = {
132 132 runtime: { avail: false, value: 2**30-1 },
133 133 memory: { avail: false, value: 2**30-1 },
134 134 length: { avail: false, value: 2**30-1 },
135 135 first: { avail: false, value: DateTime.new(3000,1,1) }
136 136 }
137 137 end
138 138
139 139 if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value]
140 140 @by_lang[lang.pretty_name][:runtime] = { avail: true, user_id: sub.user_id, value: sub.max_runtime, sub_id: sub.id }
141 141 end
142 142
143 143 if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value]
144 144 @by_lang[lang.pretty_name][:memory] = { avail: true, user_id: sub.user_id, value: sub.peak_memory, sub_id: sub.id }
145 145 end
146 146
147 147 if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and
148 148 !sub.user.admin?
149 149 @by_lang[lang.pretty_name][:first] = { avail: true, user_id: sub.user_id, value: sub.submitted_at, sub_id: sub.id }
150 150 end
151 151
152 152 if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length
153 153 @by_lang[lang.pretty_name][:length] = { avail: true, user_id: sub.user_id, value: sub.effective_code_length, sub_id: sub.id }
154 154 end
155 155 end
156 156
157 157 #process user_id
158 158 @by_lang.each do |lang,prop|
159 159 prop.each do |k,v|
160 160 v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)"
161 161 end
162 162 end
163 163
164 164 #sum into best
165 165 if @by_lang and @by_lang.first
166 166 @best = @by_lang.first[1].clone
167 167 @by_lang.each do |lang,prop|
168 168 if @best[:runtime][:value] >= prop[:runtime][:value]
169 169 @best[:runtime] = prop[:runtime]
170 170 @best[:runtime][:lang] = lang
171 171 end
172 172 if @best[:memory][:value] >= prop[:memory][:value]
173 173 @best[:memory] = prop[:memory]
174 174 @best[:memory][:lang] = lang
175 175 end
176 176 if @best[:length][:value] >= prop[:length][:value]
177 177 @best[:length] = prop[:length]
178 178 @best[:length][:lang] = lang
179 179 end
180 180 if @best[:first][:value] >= prop[:first][:value]
181 181 @best[:first] = prop[:first]
182 182 @best[:first][:lang] = lang
183 183 end
184 184 end
185 185 end
186 186
187 187 @histogram[:summary][:max] = [@histogram[:data].max,1].max
188 188 @summary[:attempt] = user.count
189 189 user.each_value { |v| @summary[:solve] += 1 if v == 1 }
190 190 end
191 191
192 192 def stuck #report struggling user,problem
193 193 # init
194 194 user,problem = nil
195 195 solve = true
196 196 tries = 0
197 197 @struggle = Array.new
198 198 record = {}
199 199 Submission.includes(:problem,:user).order(:problem_id,:user_id).find_each do |sub|
200 200 next unless sub.problem and sub.user
201 201 if user != sub.user_id or problem != sub.problem_id
202 202 @struggle << { user: record[:user], problem: record[:problem], tries: tries } unless solve
203 203 record = {user: sub.user, problem: sub.problem}
204 204 user,problem = sub.user_id, sub.problem_id
205 205 solve = false
206 206 tries = 0
207 207 end
208 208 if sub.points >= sub.problem.full_score
209 209 solve = true
210 210 else
211 211 tries += 1
212 212 end
213 213 end
214 214 @struggle.sort!{|a,b| b[:tries] <=> a[:tries] }
215 215 @struggle = @struggle[0..50]
216 216 end
217 217
218 218
219 219 def multiple_login
220 220 #user with multiple IP
221 221 raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:login)
222 222 last,count = 0,0
223 223 first = 0
224 224 @users = []
225 225 raw.each do |r|
226 226 if last != r.user.login
227 227 count = 1
228 228 last = r.user.login
229 229 first = r
230 230 else
231 231 @users << first if count == 1
232 232 @users << r
233 233 count += 1
234 234 end
235 235 end
236 236
237 237 #IP with multiple user
238 238 raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:ip_address)
239 239 last,count = 0,0
240 240 first = 0
241 241 @ip = []
242 242 raw.each do |r|
243 243 if last != r.ip_address
244 244 count = 1
245 245 last = r.ip_address
246 246 first = r
247 247 else
248 248 @ip << first if count == 1
249 249 @ip << r
250 250 count += 1
251 251 end
252 252 end
253 253 end
254 254
255 + def cheat_report
256 + end
257 +
255 258 end
@@ -1,248 +1,249
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 - ActiveRecord::Schema.define(:version => 20150203153534) do
14 + ActiveRecord::Schema.define(:version => 20150503164846) do
15 15
16 16 create_table "announcements", :force => true do |t|
17 17 t.string "author"
18 - t.text "body"
18 + t.text "body", :limit => 16777215
19 19 t.boolean "published"
20 - t.datetime "created_at", :null => false
21 - t.datetime "updated_at", :null => false
22 - t.boolean "frontpage", :default => false
23 - t.boolean "contest_only", :default => false
20 + t.datetime "created_at", :null => false
21 + t.datetime "updated_at", :null => false
22 + t.boolean "frontpage", :default => false
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"
53 + t.text "body", :limit => 16777215
54 54 t.boolean "markdowned"
55 - t.datetime "created_at", :null => false
56 - t.datetime "updated_at", :null => false
55 + t.datetime "created_at", :null => false
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 - t.datetime "created_at", :null => false
64 - t.datetime "updated_at", :null => false
65 - t.text "description"
63 + t.datetime "created_at", :null => false
64 + t.datetime "updated_at", :null => false
65 + t.text "description", :limit => 16777215
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 - t.string "user_id"
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"
100 + t.text "body", :limit => 16777215
101 101 t.boolean "replied"
102 - t.datetime "created_at", :null => false
103 - t.datetime "updated_at", :null => false
102 + t.datetime "created_at", :null => false
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"
145 + t.text "data", :limit => 16777215
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 "submissions", :force => true do |t|
163 163 t.integer "user_id"
164 164 t.integer "problem_id"
165 165 t.integer "language_id"
166 - t.text "source"
166 + t.text "source", :limit => 16777215
167 167 t.binary "binary"
168 168 t.datetime "submitted_at"
169 169 t.datetime "compiled_at"
170 - t.text "compiler_message"
170 + t.text "compiler_message", :limit => 16777215
171 171 t.datetime "graded_at"
172 172 t.integer "points"
173 - t.text "grader_comment"
173 + t.text "grader_comment", :limit => 16777215
174 174 t.integer "number"
175 175 t.string "source_filename"
176 176 t.float "max_runtime"
177 177 t.integer "peak_memory"
178 178 t.integer "effective_code_length"
179 179 t.string "ip_address"
180 180 end
181 181
182 182 add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true
183 183 add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id"
184 184
185 185 create_table "tasks", :force => true do |t|
186 186 t.integer "submission_id"
187 187 t.datetime "created_at"
188 188 t.integer "status"
189 189 t.datetime "updated_at"
190 190 end
191 191
192 192 create_table "test_pairs", :force => true do |t|
193 193 t.integer "problem_id"
194 - t.text "input", :limit => 16777215
195 - t.text "solution", :limit => 16777215
196 - t.datetime "created_at", :null => false
197 - t.datetime "updated_at", :null => false
194 + t.text "input", :limit => 2147483647
195 + t.text "solution", :limit => 2147483647
196 + t.datetime "created_at", :null => false
197 + t.datetime "updated_at", :null => false
198 198 end
199 199
200 200 create_table "test_requests", :force => true do |t|
201 201 t.integer "user_id"
202 202 t.integer "problem_id"
203 203 t.integer "submission_id"
204 204 t.string "input_file_name"
205 205 t.string "output_file_name"
206 206 t.string "running_stat"
207 207 t.integer "status"
208 - t.datetime "updated_at", :null => false
208 + t.datetime "updated_at", :null => false
209 209 t.datetime "submitted_at"
210 210 t.datetime "compiled_at"
211 - t.text "compiler_message"
211 + t.text "compiler_message", :limit => 16777215
212 212 t.datetime "graded_at"
213 213 t.string "grader_comment"
214 - t.datetime "created_at", :null => false
214 + t.datetime "created_at", :null => false
215 215 t.float "running_time"
216 216 t.string "exit_status"
217 217 t.integer "memory_usage"
218 218 end
219 219
220 220 add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id"
221 221
222 222 create_table "user_contest_stats", :force => true do |t|
223 223 t.integer "user_id"
224 224 t.datetime "started_at"
225 225 t.datetime "created_at", :null => false
226 226 t.datetime "updated_at", :null => false
227 227 t.boolean "forced_logout"
228 228 end
229 229
230 230 create_table "users", :force => true do |t|
231 231 t.string "login", :limit => 50
232 232 t.string "full_name"
233 233 t.string "hashed_password"
234 234 t.string "salt", :limit => 5
235 235 t.string "alias"
236 236 t.string "email"
237 237 t.integer "site_id"
238 238 t.integer "country_id"
239 239 t.boolean "activated", :default => false
240 240 t.datetime "created_at"
241 241 t.datetime "updated_at"
242 + t.string "section"
242 243 t.boolean "enabled", :default => true
243 244 t.string "remark"
244 245 end
245 246
246 247 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
247 248
248 249 end
You need to be logged in to leave comments. Login now