Description:
Merge pull request #19 from nattee/master upstream merge from nattee/cafe-grader-web
Commit status:
[Not Reviewed]
References:
merge default
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r717:6d7ccf388baa - - 10 files changed: 12 inserted, 12 deleted

@@ -204,49 +204,49
204 user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max
204 user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max
205
205
206 lang = Language.find_by_id(sub.language_id)
206 lang = Language.find_by_id(sub.language_id)
207 next unless lang
207 next unless lang
208 next unless sub.points >= @problem.full_score
208 next unless sub.points >= @problem.full_score
209
209
210 #initialize
210 #initialize
211 unless @by_lang.has_key?(lang.pretty_name)
211 unless @by_lang.has_key?(lang.pretty_name)
212 @by_lang[lang.pretty_name] = {
212 @by_lang[lang.pretty_name] = {
213 runtime: { avail: false, value: 2**30-1 },
213 runtime: { avail: false, value: 2**30-1 },
214 memory: { avail: false, value: 2**30-1 },
214 memory: { avail: false, value: 2**30-1 },
215 length: { avail: false, value: 2**30-1 },
215 length: { avail: false, value: 2**30-1 },
216 first: { avail: false, value: DateTime.new(3000,1,1) }
216 first: { avail: false, value: DateTime.new(3000,1,1) }
217 }
217 }
218 end
218 end
219
219
220 if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value]
220 if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value]
221 @by_lang[lang.pretty_name][:runtime] = { avail: true, user_id: sub.user_id, value: sub.max_runtime, sub_id: sub.id }
221 @by_lang[lang.pretty_name][:runtime] = { avail: true, user_id: sub.user_id, value: sub.max_runtime, sub_id: sub.id }
222 end
222 end
223
223
224 if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value]
224 if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value]
225 @by_lang[lang.pretty_name][:memory] = { avail: true, user_id: sub.user_id, value: sub.peak_memory, sub_id: sub.id }
225 @by_lang[lang.pretty_name][:memory] = { avail: true, user_id: sub.user_id, value: sub.peak_memory, sub_id: sub.id }
226 end
226 end
227
227
228 - if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and
228 + if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and sub.user and
229 !sub.user.admin?
229 !sub.user.admin?
230 @by_lang[lang.pretty_name][:first] = { avail: true, user_id: sub.user_id, value: sub.submitted_at, sub_id: sub.id }
230 @by_lang[lang.pretty_name][:first] = { avail: true, user_id: sub.user_id, value: sub.submitted_at, sub_id: sub.id }
231 end
231 end
232
232
233 if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length
233 if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length
234 @by_lang[lang.pretty_name][:length] = { avail: true, user_id: sub.user_id, value: sub.effective_code_length, sub_id: sub.id }
234 @by_lang[lang.pretty_name][:length] = { avail: true, user_id: sub.user_id, value: sub.effective_code_length, sub_id: sub.id }
235 end
235 end
236 end
236 end
237
237
238 #process user_id
238 #process user_id
239 @by_lang.each do |lang,prop|
239 @by_lang.each do |lang,prop|
240 prop.each do |k,v|
240 prop.each do |k,v|
241 v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)"
241 v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)"
242 end
242 end
243 end
243 end
244
244
245 #sum into best
245 #sum into best
246 if @by_lang and @by_lang.first
246 if @by_lang and @by_lang.first
247 @best = @by_lang.first[1].clone
247 @best = @by_lang.first[1].clone
248 @by_lang.each do |lang,prop|
248 @by_lang.each do |lang,prop|
249 if @best[:runtime][:value] >= prop[:runtime][:value]
249 if @best[:runtime][:value] >= prop[:runtime][:value]
250 @best[:runtime] = prop[:runtime]
250 @best[:runtime] = prop[:runtime]
251 @best[:runtime][:lang] = lang
251 @best[:runtime][:lang] = lang
252 end
252 end
@@ -90,49 +90,50
90 render :action => 'forget', :layout => 'empty'
90 render :action => 'forget', :layout => 'empty'
91 end
91 end
92
92
93 def retrieve_password
93 def retrieve_password
94 email = params[:email]
94 email = params[:email]
95 user = User.find_by_email(email)
95 user = User.find_by_email(email)
96 if user
96 if user
97 last_updated_time = user.updated_at || user.created_at || (Time.now.gmtime - 1.hour)
97 last_updated_time = user.updated_at || user.created_at || (Time.now.gmtime - 1.hour)
98 if last_updated_time > Time.now.gmtime - 5.minutes
98 if last_updated_time > Time.now.gmtime - 5.minutes
99 flash[:notice] = 'The account has recently created or new password has recently been requested. Please wait for 5 minutes'
99 flash[:notice] = 'The account has recently created or new password has recently been requested. Please wait for 5 minutes'
100 else
100 else
101 user.password = user.password_confirmation = User.random_password
101 user.password = user.password_confirmation = User.random_password
102 user.save
102 user.save
103 send_new_password_email(user)
103 send_new_password_email(user)
104 flash[:notice] = 'New password has been mailed to you.'
104 flash[:notice] = 'New password has been mailed to you.'
105 end
105 end
106 else
106 else
107 flash[:notice] = I18n.t 'registration.password_retrieval.no_email'
107 flash[:notice] = I18n.t 'registration.password_retrieval.no_email'
108 end
108 end
109 redirect_to :action => 'forget'
109 redirect_to :action => 'forget'
110 end
110 end
111
111
112 def stat
112 def stat
113 @user = User.find(params[:id])
113 @user = User.find(params[:id])
114 - @submission = Submission.includes(:problem).where(user_id: params[:id])
114 + @submission = Submission.joins(:problem).where(user_id: params[:id])
115 + @submission = @submission.where('problems.available = true') unless current_user.admin?
115
116
116 range = 120
117 range = 120
117 @histogram = { data: Array.new(range,0), summary: {} }
118 @histogram = { data: Array.new(range,0), summary: {} }
118 @summary = {count: 0, solve: 0, attempt: 0}
119 @summary = {count: 0, solve: 0, attempt: 0}
119 problem = Hash.new(0)
120 problem = Hash.new(0)
120
121
121 @submission.find_each do |sub|
122 @submission.find_each do |sub|
122 #histogram
123 #histogram
123 d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
124 d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
124 @histogram[:data][d.to_i] += 1 if d < range
125 @histogram[:data][d.to_i] += 1 if d < range
125
126
126 @summary[:count] += 1
127 @summary[:count] += 1
127 next unless sub.problem
128 next unless sub.problem
128 problem[sub.problem] = [problem[sub.problem], ( (sub.try(:points) || 0) >= sub.problem.full_score) ? 1 : 0].max
129 problem[sub.problem] = [problem[sub.problem], ( (sub.try(:points) || 0) >= sub.problem.full_score) ? 1 : 0].max
129 end
130 end
130
131
131 @histogram[:summary][:max] = [@histogram[:data].max,1].max
132 @histogram[:summary][:max] = [@histogram[:data].max,1].max
132 @summary[:attempt] = problem.count
133 @summary[:attempt] = problem.count
133 problem.each_value { |v| @summary[:solve] += 1 if v == 1 }
134 problem.each_value { |v| @summary[:solve] += 1 if v == 1 }
134 end
135 end
135
136
136 def toggle_activate
137 def toggle_activate
137 @user = User.find(params[:id])
138 @user = User.find(params[:id])
138 @user.update_attributes( activated: !@user.activated? )
139 @user.update_attributes( activated: !@user.activated? )
@@ -1,16 +1,16
1 class AddLanguageExt < ActiveRecord::Migration
1 class AddLanguageExt < ActiveRecord::Migration
2 def self.up
2 def self.up
3 add_column :languages, :ext, :string, :limit => 10
3 add_column :languages, :ext, :string, :limit => 10
4
4
5 Language.reset_column_information
5 Language.reset_column_information
6 - langs = Language.find(:all)
6 + langs = Language.all
7 langs.each do |l|
7 langs.each do |l|
8 l.ext = l.name
8 l.ext = l.name
9 l.save
9 l.save
10 end
10 end
11 end
11 end
12
12
13 def self.down
13 def self.down
14 remove_column :languages, :ext
14 remove_column :languages, :ext
15 end
15 end
16 end
16 end
@@ -1,17 +1,17
1 class AddStatusToTasks < ActiveRecord::Migration
1 class AddStatusToTasks < ActiveRecord::Migration
2 def self.up
2 def self.up
3 add_column :tasks, :status, :integer
3 add_column :tasks, :status, :integer
4 add_column :tasks, :updated_at, :datetime
4 add_column :tasks, :updated_at, :datetime
5
5
6 Task.reset_column_information
6 Task.reset_column_information
7 - Task.find(:all).each do |task|
7 + Task.all.each do |task|
8 task.status_complete
8 task.status_complete
9 task.save
9 task.save
10 end
10 end
11 end
11 end
12
12
13 def self.down
13 def self.down
14 remove_column :tasks, :updated_at
14 remove_column :tasks, :updated_at
15 remove_column :tasks, :status
15 remove_column :tasks, :status
16 end
16 end
17 end
17 end
@@ -1,33 +1,32
1 class AddNumberToSubmissions < ActiveRecord::Migration
1 class AddNumberToSubmissions < ActiveRecord::Migration
2 def self.up
2 def self.up
3 add_column :submissions, :number, :integer
3 add_column :submissions, :number, :integer
4
4
5 # add number field for all records
5 # add number field for all records
6 Submission.reset_column_information
6 Submission.reset_column_information
7
7
8 last_user_id = nil
8 last_user_id = nil
9 last_problem_id = nil
9 last_problem_id = nil
10 current_number = 0
10 current_number = 0
11
11
12 - Submission.find(:all,
12 + Submission.order('user_id, problem_id, submitted_at').each do |submission|
13 - :order => 'user_id, problem_id, submitted_at').each do |submission|
14 if submission.user_id==last_user_id and submission.problem_id==last_problem_id
13 if submission.user_id==last_user_id and submission.problem_id==last_problem_id
15 current_number += 1
14 current_number += 1
16 else
15 else
17 current_number = 1
16 current_number = 1
18 end
17 end
19 submission.number = current_number
18 submission.number = current_number
20 submission.save
19 submission.save
21
20
22 last_user_id = submission.user_id
21 last_user_id = submission.user_id
23 last_problem_id = submission.problem_id
22 last_problem_id = submission.problem_id
24 end
23 end
25
24
26 add_index :submissions, [:user_id, :problem_id, :number], :unique => true
25 add_index :submissions, [:user_id, :problem_id, :number], :unique => true
27 end
26 end
28
27
29 def self.down
28 def self.down
30 remove_index :submissions, :column => [:user_id, :problem_id, :number]
29 remove_index :submissions, :column => [:user_id, :problem_id, :number]
31 remove_column :submissions, :number
30 remove_column :submissions, :number
32 end
31 end
33 end
32 end
@@ -1,29 +1,29
1 class AddSiteToUserAndAddDefaultSite < ActiveRecord::Migration
1 class AddSiteToUserAndAddDefaultSite < ActiveRecord::Migration
2 def self.up
2 def self.up
3 default_site = Site.new({:name => 'default',
3 default_site = Site.new({:name => 'default',
4 :started => false})
4 :started => false})
5 default_site.save!
5 default_site.save!
6
6
7 add_column :users, :site_id, :integer
7 add_column :users, :site_id, :integer
8 User.reset_column_information
8 User.reset_column_information
9
9
10 - User.find(:all).each do |user|
10 + User.all.each do |user|
11
11
12 class << user
12 class << user
13 def valid?
13 def valid?
14 true
14 true
15 end
15 end
16 end
16 end
17
17
18 user.site_id = default_site.id
18 user.site_id = default_site.id
19 user.save
19 user.save
20 end
20 end
21 end
21 end
22
22
23 def self.down
23 def self.down
24 remove_column :users, :site_id
24 remove_column :users, :site_id
25
25
26 default_site = Site.find_by_name('default')
26 default_site = Site.find_by_name('default')
27 default_site.destroy if default_site
27 default_site.destroy if default_site
28 end
28 end
29 end
29 end
@@ -1,33 +1,33
1 class RefactorProblemBodyToDescription < ActiveRecord::Migration
1 class RefactorProblemBodyToDescription < ActiveRecord::Migration
2 def self.up
2 def self.up
3 add_column :problems, :description_id, :integer
3 add_column :problems, :description_id, :integer
4 Problem.reset_column_information
4 Problem.reset_column_information
5
5
6 - Problem.find(:all).each do |problem|
6 + Problem.all.each do |problem|
7 if problem.body!=nil
7 if problem.body!=nil
8 description = Description.new
8 description = Description.new
9 description.body = problem.body
9 description.body = problem.body
10 description.markdowned = false
10 description.markdowned = false
11 description.save
11 description.save
12 problem.description_id = description.id
12 problem.description_id = description.id
13 problem.save
13 problem.save
14 end
14 end
15 end
15 end
16
16
17 remove_column :problems, :body
17 remove_column :problems, :body
18 end
18 end
19
19
20 def self.down
20 def self.down
21 add_column :problems, :body, :text
21 add_column :problems, :body, :text
22 Problem.reset_column_information
22 Problem.reset_column_information
23
23
24 - Problem.find(:all).each do |problem|
24 + Problem.all.each do |problem|
25 if problem.description_id != nil
25 if problem.description_id != nil
26 problem.body = Description.find(problem.description_id).body
26 problem.body = Description.find(problem.description_id).body
27 problem.save
27 problem.save
28 end
28 end
29 end
29 end
30
30
31 remove_column :problems, :description_id
31 remove_column :problems, :description_id
32 end
32 end
33 end
33 end
@@ -1,15 +1,15
1 class AddTestAllowedToProblems < ActiveRecord::Migration
1 class AddTestAllowedToProblems < ActiveRecord::Migration
2 def self.up
2 def self.up
3 add_column :problems, :test_allowed, :boolean
3 add_column :problems, :test_allowed, :boolean
4 Problem.reset_column_information
4 Problem.reset_column_information
5
5
6 - Problem.find(:all).each do |problem|
6 + Problem.all.each do |problem|
7 problem.test_allowed = true
7 problem.test_allowed = true
8 problem.save
8 problem.save
9 end
9 end
10 end
10 end
11
11
12 def self.down
12 def self.down
13 remove_column :problems, :test_allowed
13 remove_column :problems, :test_allowed
14 end
14 end
15 end
15 end
@@ -1,25 +1,25
1 class AddActivatedToUsers < ActiveRecord::Migration
1 class AddActivatedToUsers < ActiveRecord::Migration
2 def self.up
2 def self.up
3 add_column :users, :activated, :boolean, :default => 0
3 add_column :users, :activated, :boolean, :default => 0
4
4
5 User.reset_column_information
5 User.reset_column_information
6
6
7 - User.find(:all).each do |user|
7 + User.all.each do |user|
8
8
9 # disable validation
9 # disable validation
10 class <<user
10 class <<user
11 def valid?
11 def valid?
12 return true
12 return true
13 end
13 end
14 end
14 end
15
15
16 user.activated = true
16 user.activated = true
17 user.save
17 user.save
18 end
18 end
19 end
19 end
20
20
21
21
22 def self.down
22 def self.down
23 remove_column :users, :activated
23 remove_column :users, :activated
24 end
24 end
25 end
25 end
@@ -1,23 +1,23
1 class AddCommonExtToLanguages < ActiveRecord::Migration
1 class AddCommonExtToLanguages < ActiveRecord::Migration
2 def self.up
2 def self.up
3 # language.common_ext is a comma-separated list of common file
3 # language.common_ext is a comma-separated list of common file
4 # extensions.
4 # extensions.
5 add_column :languages, :common_ext, :string
5 add_column :languages, :common_ext, :string
6
6
7 # updating table information
7 # updating table information
8 Language.reset_column_information
8 Language.reset_column_information
9 common_ext = {
9 common_ext = {
10 'c' => 'c',
10 'c' => 'c',
11 'cpp' => 'cpp,cc',
11 'cpp' => 'cpp,cc',
12 'pas' => 'pas'
12 'pas' => 'pas'
13 }
13 }
14 - Language.find(:all).each do |lang|
14 + Language.all.each do |lang|
15 lang.common_ext = common_ext[lang.name]
15 lang.common_ext = common_ext[lang.name]
16 lang.save
16 lang.save
17 end
17 end
18 end
18 end
19
19
20 def self.down
20 def self.down
21 remove_column :languages, :common_ext
21 remove_column :languages, :common_ext
22 end
22 end
23 end
23 end
You need to be logged in to leave comments. Login now