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

@@ -216,25 +216,25
216 216 first: { avail: false, value: DateTime.new(3000,1,1) }
217 217 }
218 218 end
219 219
220 220 if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value]
221 221 @by_lang[lang.pretty_name][:runtime] = { avail: true, user_id: sub.user_id, value: sub.max_runtime, sub_id: sub.id }
222 222 end
223 223
224 224 if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value]
225 225 @by_lang[lang.pretty_name][:memory] = { avail: true, user_id: sub.user_id, value: sub.peak_memory, sub_id: sub.id }
226 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 229 !sub.user.admin?
230 230 @by_lang[lang.pretty_name][:first] = { avail: true, user_id: sub.user_id, value: sub.submitted_at, sub_id: sub.id }
231 231 end
232 232
233 233 if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length
234 234 @by_lang[lang.pretty_name][:length] = { avail: true, user_id: sub.user_id, value: sub.effective_code_length, sub_id: sub.id }
235 235 end
236 236 end
237 237
238 238 #process user_id
239 239 @by_lang.each do |lang,prop|
240 240 prop.each do |k,v|
@@ -102,25 +102,26
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 stat
113 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 117 range = 120
117 118 @histogram = { data: Array.new(range,0), summary: {} }
118 119 @summary = {count: 0, solve: 0, attempt: 0}
119 120 problem = Hash.new(0)
120 121
121 122 @submission.find_each do |sub|
122 123 #histogram
123 124 d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
124 125 @histogram[:data][d.to_i] += 1 if d < range
125 126
126 127 @summary[:count] += 1
@@ -1,16 +1,16
1 1 class AddLanguageExt < ActiveRecord::Migration
2 2 def self.up
3 3 add_column :languages, :ext, :string, :limit => 10
4 4
5 5 Language.reset_column_information
6 - langs = Language.find(:all)
6 + langs = Language.all
7 7 langs.each do |l|
8 8 l.ext = l.name
9 9 l.save
10 10 end
11 11 end
12 12
13 13 def self.down
14 14 remove_column :languages, :ext
15 15 end
16 16 end
@@ -1,17 +1,17
1 1 class AddStatusToTasks < ActiveRecord::Migration
2 2 def self.up
3 3 add_column :tasks, :status, :integer
4 4 add_column :tasks, :updated_at, :datetime
5 5
6 6 Task.reset_column_information
7 - Task.find(:all).each do |task|
7 + Task.all.each do |task|
8 8 task.status_complete
9 9 task.save
10 10 end
11 11 end
12 12
13 13 def self.down
14 14 remove_column :tasks, :updated_at
15 15 remove_column :tasks, :status
16 16 end
17 17 end
@@ -1,25 +1,24
1 1 class AddNumberToSubmissions < ActiveRecord::Migration
2 2 def self.up
3 3 add_column :submissions, :number, :integer
4 4
5 5 # add number field for all records
6 6 Submission.reset_column_information
7 7
8 8 last_user_id = nil
9 9 last_problem_id = nil
10 10 current_number = 0
11 11
12 - Submission.find(:all,
13 - :order => 'user_id, problem_id, submitted_at').each do |submission|
12 + Submission.order('user_id, problem_id, submitted_at').each do |submission|
14 13 if submission.user_id==last_user_id and submission.problem_id==last_problem_id
15 14 current_number += 1
16 15 else
17 16 current_number = 1
18 17 end
19 18 submission.number = current_number
20 19 submission.save
21 20
22 21 last_user_id = submission.user_id
23 22 last_problem_id = submission.problem_id
24 23 end
25 24
@@ -1,22 +1,22
1 1 class AddSiteToUserAndAddDefaultSite < ActiveRecord::Migration
2 2 def self.up
3 3 default_site = Site.new({:name => 'default',
4 4 :started => false})
5 5 default_site.save!
6 6
7 7 add_column :users, :site_id, :integer
8 8 User.reset_column_information
9 9
10 - User.find(:all).each do |user|
10 + User.all.each do |user|
11 11
12 12 class << user
13 13 def valid?
14 14 true
15 15 end
16 16 end
17 17
18 18 user.site_id = default_site.id
19 19 user.save
20 20 end
21 21 end
22 22
@@ -1,33 +1,33
1 1 class RefactorProblemBodyToDescription < ActiveRecord::Migration
2 2 def self.up
3 3 add_column :problems, :description_id, :integer
4 4 Problem.reset_column_information
5 5
6 - Problem.find(:all).each do |problem|
6 + Problem.all.each do |problem|
7 7 if problem.body!=nil
8 8 description = Description.new
9 9 description.body = problem.body
10 10 description.markdowned = false
11 11 description.save
12 12 problem.description_id = description.id
13 13 problem.save
14 14 end
15 15 end
16 16
17 17 remove_column :problems, :body
18 18 end
19 19
20 20 def self.down
21 21 add_column :problems, :body, :text
22 22 Problem.reset_column_information
23 23
24 - Problem.find(:all).each do |problem|
24 + Problem.all.each do |problem|
25 25 if problem.description_id != nil
26 26 problem.body = Description.find(problem.description_id).body
27 27 problem.save
28 28 end
29 29 end
30 30
31 31 remove_column :problems, :description_id
32 32 end
33 33 end
@@ -1,15 +1,15
1 1 class AddTestAllowedToProblems < ActiveRecord::Migration
2 2 def self.up
3 3 add_column :problems, :test_allowed, :boolean
4 4 Problem.reset_column_information
5 5
6 - Problem.find(:all).each do |problem|
6 + Problem.all.each do |problem|
7 7 problem.test_allowed = true
8 8 problem.save
9 9 end
10 10 end
11 11
12 12 def self.down
13 13 remove_column :problems, :test_allowed
14 14 end
15 15 end
@@ -1,19 +1,19
1 1 class AddActivatedToUsers < ActiveRecord::Migration
2 2 def self.up
3 3 add_column :users, :activated, :boolean, :default => 0
4 4
5 5 User.reset_column_information
6 6
7 - User.find(:all).each do |user|
7 + User.all.each do |user|
8 8
9 9 # disable validation
10 10 class <<user
11 11 def valid?
12 12 return true
13 13 end
14 14 end
15 15
16 16 user.activated = true
17 17 user.save
18 18 end
19 19 end
@@ -2,22 +2,22
2 2 def self.up
3 3 # language.common_ext is a comma-separated list of common file
4 4 # extensions.
5 5 add_column :languages, :common_ext, :string
6 6
7 7 # updating table information
8 8 Language.reset_column_information
9 9 common_ext = {
10 10 'c' => 'c',
11 11 'cpp' => 'cpp,cc',
12 12 'pas' => 'pas'
13 13 }
14 - Language.find(:all).each do |lang|
14 + Language.all.each do |lang|
15 15 lang.common_ext = common_ext[lang.name]
16 16 lang.save
17 17 end
18 18 end
19 19
20 20 def self.down
21 21 remove_column :languages, :common_ext
22 22 end
23 23 end
You need to be logged in to leave comments. Login now