Description:
merge
Commit status:
[Not Reviewed]
References:
merge algo
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r466:b99651140f6d - - 3 files changed: 2 inserted, 2 deleted

@@ -25,192 +25,193
25 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
25 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
26 @until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i)
26 @until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i)
27 rescue
27 rescue
28 @until_time = DateTime.new(3000,1,1)
28 @until_time = DateTime.new(3000,1,1)
29 end
29 end
30
30
31 User.all.each do |user|
31 User.all.each do |user|
32 @logins << { id: user.id,
32 @logins << { id: user.id,
33 login: user.login,
33 login: user.login,
34 full_name: user.full_name,
34 full_name: user.full_name,
35 count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
35 count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
36 user.id,@since_time,@until_time)
36 user.id,@since_time,@until_time)
37 .count(:id),
37 .count(:id),
38 min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
38 min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
39 user.id,@since_time,@until_time)
39 user.id,@since_time,@until_time)
40 .minimum(:created_at),
40 .minimum(:created_at),
41 max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
41 max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
42 user.id,@since_time,@until_time)
42 user.id,@since_time,@until_time)
43 .maximum(:created_at),
43 .maximum(:created_at),
44 ip: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
44 ip: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
45 user.id,@since_time,@until_time)
45 user.id,@since_time,@until_time)
46 .select(:ip_address).uniq
46 .select(:ip_address).uniq
47
47
48 }
48 }
49 end
49 end
50 end
50 end
51
51
52 def submission_stat
52 def submission_stat
53
53
54 date_and_time = '%Y-%m-%d %H:%M'
54 date_and_time = '%Y-%m-%d %H:%M'
55 begin
55 begin
56 @since_time = DateTime.strptime(params[:since_datetime],date_and_time)
56 @since_time = DateTime.strptime(params[:since_datetime],date_and_time)
57 rescue
57 rescue
58 @since_time = DateTime.new(1000,1,1)
58 @since_time = DateTime.new(1000,1,1)
59 end
59 end
60 begin
60 begin
61 @until_time = DateTime.strptime(params[:until_datetime],date_and_time)
61 @until_time = DateTime.strptime(params[:until_datetime],date_and_time)
62 rescue
62 rescue
63 @until_time = DateTime.new(3000,1,1)
63 @until_time = DateTime.new(3000,1,1)
64 end
64 end
65
65
66 @submissions = {}
66 @submissions = {}
67
67
68 User.find_each do |user|
68 User.find_each do |user|
69 @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } }
69 @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } }
70 end
70 end
71
71
72 Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s|
72 Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s|
73 if @submissions[s.user_id]
73 if @submissions[s.user_id]
74 if not @submissions[s.user_id][:sub].has_key?(s.problem_id)
74 if not @submissions[s.user_id][:sub].has_key?(s.problem_id)
75 a = nil
75 a = nil
76 begin
76 begin
77 a = Problem.find(s.problem_id)
77 a = Problem.find(s.problem_id)
78 rescue
78 rescue
79 a = nil
79 a = nil
80 end
80 end
81 @submissions[s.user_id][:sub][s.problem_id] =
81 @submissions[s.user_id][:sub][s.problem_id] =
82 { prob_name: (a ? a.full_name : '(NULL)'),
82 { prob_name: (a ? a.full_name : '(NULL)'),
83 sub_ids: [s.id] }
83 sub_ids: [s.id] }
84 else
84 else
85 @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id
85 @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id
86 end
86 end
87 @submissions[s.user_id][:count] += 1
87 @submissions[s.user_id][:count] += 1
88 end
88 end
89 end
89 end
90 end
90 end
91
91
92 def problem_hof
92 def problem_hof
93 # gen problem list
93 # gen problem list
94 @user = User.find(session[:user_id])
94 @user = User.find(session[:user_id])
95 @problems = @user.available_problems
95 @problems = @user.available_problems
96
96
97 # get selected problems or the default
97 # get selected problems or the default
98 if params[:id]
98 if params[:id]
99 begin
99 begin
100 @problem = Problem.available.find(params[:id])
100 @problem = Problem.available.find(params[:id])
101 rescue
101 rescue
102 redirect_to action: :problem_hof
102 redirect_to action: :problem_hof
103 flash[:notice] = 'Error: submissions for that problem are not viewable.'
103 flash[:notice] = 'Error: submissions for that problem are not viewable.'
104 return
104 return
105 end
105 end
106 end
106 end
107
107
108 return unless @problem
108 return unless @problem
109
109
110 @by_lang = {} #aggregrate by language
110 @by_lang = {} #aggregrate by language
111
111
112 range =65
112 range =65
113 @histogram = { data: Array.new(range,0), summary: {} }
113 @histogram = { data: Array.new(range,0), summary: {} }
114 @summary = {count: 0, solve: 0, attempt: 0}
114 @summary = {count: 0, solve: 0, attempt: 0}
115 user = Hash.new(0)
115 user = Hash.new(0)
116 Submission.where(problem_id: @problem.id).find_each do |sub|
116 Submission.where(problem_id: @problem.id).find_each do |sub|
117 #histogram
117 #histogram
118 d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
118 d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
119 @histogram[:data][d.to_i] += 1 if d < range
119 @histogram[:data][d.to_i] += 1 if d < range
120
120
121 + next unless sub.points
121 @summary[:count] += 1
122 @summary[:count] += 1
122 user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max
123 user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max
123
124
124 lang = Language.find_by_id(sub.language_id)
125 lang = Language.find_by_id(sub.language_id)
125 next unless lang
126 next unless lang
126 next unless sub.points >= @problem.full_score
127 next unless sub.points >= @problem.full_score
127
128
128 #initialize
129 #initialize
129 unless @by_lang.has_key?(lang.pretty_name)
130 unless @by_lang.has_key?(lang.pretty_name)
130 @by_lang[lang.pretty_name] = {
131 @by_lang[lang.pretty_name] = {
131 runtime: { avail: false, value: 2**30-1 },
132 runtime: { avail: false, value: 2**30-1 },
132 memory: { avail: false, value: 2**30-1 },
133 memory: { avail: false, value: 2**30-1 },
133 length: { avail: false, value: 2**30-1 },
134 length: { avail: false, value: 2**30-1 },
134 first: { avail: false, value: DateTime.new(3000,1,1) }
135 first: { avail: false, value: DateTime.new(3000,1,1) }
135 }
136 }
136 end
137 end
137
138
138 if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value]
139 if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value]
139 @by_lang[lang.pretty_name][:runtime] = { avail: true, user_id: sub.user_id, value: sub.max_runtime, sub_id: sub.id }
140 @by_lang[lang.pretty_name][:runtime] = { avail: true, user_id: sub.user_id, value: sub.max_runtime, sub_id: sub.id }
140 end
141 end
141
142
142 if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value]
143 if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value]
143 @by_lang[lang.pretty_name][:memory] = { avail: true, user_id: sub.user_id, value: sub.peak_memory, sub_id: sub.id }
144 @by_lang[lang.pretty_name][:memory] = { avail: true, user_id: sub.user_id, value: sub.peak_memory, sub_id: sub.id }
144 end
145 end
145
146
146 if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and
147 if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and
147 !sub.user.admin?
148 !sub.user.admin?
148 @by_lang[lang.pretty_name][:first] = { avail: true, user_id: sub.user_id, value: sub.submitted_at, sub_id: sub.id }
149 @by_lang[lang.pretty_name][:first] = { avail: true, user_id: sub.user_id, value: sub.submitted_at, sub_id: sub.id }
149 end
150 end
150
151
151 if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length
152 if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length
152 @by_lang[lang.pretty_name][:length] = { avail: true, user_id: sub.user_id, value: sub.effective_code_length, sub_id: sub.id }
153 @by_lang[lang.pretty_name][:length] = { avail: true, user_id: sub.user_id, value: sub.effective_code_length, sub_id: sub.id }
153 end
154 end
154 end
155 end
155
156
156 #process user_id
157 #process user_id
157 @by_lang.each do |lang,prop|
158 @by_lang.each do |lang,prop|
158 prop.each do |k,v|
159 prop.each do |k,v|
159 v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)"
160 v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)"
160 end
161 end
161 end
162 end
162
163
163 #sum into best
164 #sum into best
164 if @by_lang and @by_lang.first
165 if @by_lang and @by_lang.first
165 @best = @by_lang.first[1].clone
166 @best = @by_lang.first[1].clone
166 @by_lang.each do |lang,prop|
167 @by_lang.each do |lang,prop|
167 if @best[:runtime][:value] >= prop[:runtime][:value]
168 if @best[:runtime][:value] >= prop[:runtime][:value]
168 @best[:runtime] = prop[:runtime]
169 @best[:runtime] = prop[:runtime]
169 @best[:runtime][:lang] = lang
170 @best[:runtime][:lang] = lang
170 end
171 end
171 if @best[:memory][:value] >= prop[:memory][:value]
172 if @best[:memory][:value] >= prop[:memory][:value]
172 @best[:memory] = prop[:memory]
173 @best[:memory] = prop[:memory]
173 @best[:memory][:lang] = lang
174 @best[:memory][:lang] = lang
174 end
175 end
175 if @best[:length][:value] >= prop[:length][:value]
176 if @best[:length][:value] >= prop[:length][:value]
176 @best[:length] = prop[:length]
177 @best[:length] = prop[:length]
177 @best[:length][:lang] = lang
178 @best[:length][:lang] = lang
178 end
179 end
179 if @best[:first][:value] >= prop[:first][:value]
180 if @best[:first][:value] >= prop[:first][:value]
180 @best[:first] = prop[:first]
181 @best[:first] = prop[:first]
181 @best[:first][:lang] = lang
182 @best[:first][:lang] = lang
182 end
183 end
183 end
184 end
184 end
185 end
185
186
186 @histogram[:summary][:max] = [@histogram[:data].max,1].max
187 @histogram[:summary][:max] = [@histogram[:data].max,1].max
187 @summary[:attempt] = user.count
188 @summary[:attempt] = user.count
188 user.each_value { |v| @summary[:solve] += 1 if v == 1 }
189 user.each_value { |v| @summary[:solve] += 1 if v == 1 }
189 end
190 end
190
191
191 def stuck #report struggling user,problem
192 def stuck #report struggling user,problem
192 # init
193 # init
193 user,problem = nil
194 user,problem = nil
194 solve = true
195 solve = true
195 tries = 0
196 tries = 0
196 @struggle = Array.new
197 @struggle = Array.new
197 record = {}
198 record = {}
198 Submission.includes(:problem,:user).order(:problem_id,:user_id).find_each do |sub|
199 Submission.includes(:problem,:user).order(:problem_id,:user_id).find_each do |sub|
199 next unless sub.problem and sub.user
200 next unless sub.problem and sub.user
200 if user != sub.user_id or problem != sub.problem_id
201 if user != sub.user_id or problem != sub.problem_id
201 @struggle << { user: record[:user], problem: record[:problem], tries: tries } unless solve
202 @struggle << { user: record[:user], problem: record[:problem], tries: tries } unless solve
202 record = {user: sub.user, problem: sub.problem}
203 record = {user: sub.user, problem: sub.problem}
203 user,problem = sub.user_id, sub.problem_id
204 user,problem = sub.user_id, sub.problem_id
204 solve = false
205 solve = false
205 tries = 0
206 tries = 0
206 end
207 end
207 if sub.points >= sub.problem.full_score
208 if sub.points >= sub.problem.full_score
208 solve = true
209 solve = true
209 else
210 else
210 tries += 1
211 tries += 1
211 end
212 end
212 end
213 end
213 @struggle.sort!{|a,b| b[:tries] <=> a[:tries] }
214 @struggle.sort!{|a,b| b[:tries] <=> a[:tries] }
214 @struggle = @struggle[0..50]
215 @struggle = @struggle[0..50]
215 end
216 end
216
217
@@ -146,102 +146,101
146 t.datetime "updated_at"
146 t.datetime "updated_at"
147 end
147 end
148
148
149 add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
149 add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
150 add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
150 add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
151
151
152 create_table "sites", :force => true do |t|
152 create_table "sites", :force => true do |t|
153 t.string "name"
153 t.string "name"
154 t.boolean "started"
154 t.boolean "started"
155 t.datetime "start_time"
155 t.datetime "start_time"
156 t.datetime "created_at", :null => false
156 t.datetime "created_at", :null => false
157 t.datetime "updated_at", :null => false
157 t.datetime "updated_at", :null => false
158 t.integer "country_id"
158 t.integer "country_id"
159 t.string "password"
159 t.string "password"
160 end
160 end
161
161
162 create_table "submissions", :force => true do |t|
162 create_table "submissions", :force => true do |t|
163 t.integer "user_id"
163 t.integer "user_id"
164 t.integer "problem_id"
164 t.integer "problem_id"
165 t.integer "language_id"
165 t.integer "language_id"
166 t.text "source"
166 t.text "source"
167 t.binary "binary"
167 t.binary "binary"
168 t.datetime "submitted_at"
168 t.datetime "submitted_at"
169 t.datetime "compiled_at"
169 t.datetime "compiled_at"
170 t.text "compiler_message"
170 t.text "compiler_message"
171 t.datetime "graded_at"
171 t.datetime "graded_at"
172 t.integer "points"
172 t.integer "points"
173 t.text "grader_comment"
173 t.text "grader_comment"
174 t.integer "number"
174 t.integer "number"
175 t.string "source_filename"
175 t.string "source_filename"
176 t.float "max_runtime"
176 t.float "max_runtime"
177 t.integer "peak_memory"
177 t.integer "peak_memory"
178 t.integer "effective_code_length"
178 t.integer "effective_code_length"
179 t.string "ip_address"
179 t.string "ip_address"
180 end
180 end
181
181
182 add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true
182 add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true
183 add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id"
183 add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id"
184
184
185 create_table "tasks", :force => true do |t|
185 create_table "tasks", :force => true do |t|
186 t.integer "submission_id"
186 t.integer "submission_id"
187 t.datetime "created_at"
187 t.datetime "created_at"
188 t.integer "status"
188 t.integer "status"
189 t.datetime "updated_at"
189 t.datetime "updated_at"
190 end
190 end
191
191
192 create_table "test_pairs", :force => true do |t|
192 create_table "test_pairs", :force => true do |t|
193 t.integer "problem_id"
193 t.integer "problem_id"
194 t.text "input", :limit => 16777215
194 t.text "input", :limit => 16777215
195 t.text "solution", :limit => 16777215
195 t.text "solution", :limit => 16777215
196 t.datetime "created_at", :null => false
196 t.datetime "created_at", :null => false
197 t.datetime "updated_at", :null => false
197 t.datetime "updated_at", :null => false
198 end
198 end
199
199
200 create_table "test_requests", :force => true do |t|
200 create_table "test_requests", :force => true do |t|
201 t.integer "user_id"
201 t.integer "user_id"
202 t.integer "problem_id"
202 t.integer "problem_id"
203 t.integer "submission_id"
203 t.integer "submission_id"
204 t.string "input_file_name"
204 t.string "input_file_name"
205 t.string "output_file_name"
205 t.string "output_file_name"
206 t.string "running_stat"
206 t.string "running_stat"
207 t.integer "status"
207 t.integer "status"
208 t.datetime "updated_at", :null => false
208 t.datetime "updated_at", :null => false
209 t.datetime "submitted_at"
209 t.datetime "submitted_at"
210 t.datetime "compiled_at"
210 t.datetime "compiled_at"
211 t.text "compiler_message"
211 t.text "compiler_message"
212 t.datetime "graded_at"
212 t.datetime "graded_at"
213 t.string "grader_comment"
213 t.string "grader_comment"
214 t.datetime "created_at", :null => false
214 t.datetime "created_at", :null => false
215 t.float "running_time"
215 t.float "running_time"
216 t.string "exit_status"
216 t.string "exit_status"
217 t.integer "memory_usage"
217 t.integer "memory_usage"
218 end
218 end
219
219
220 add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id"
220 add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id"
221
221
222 create_table "user_contest_stats", :force => true do |t|
222 create_table "user_contest_stats", :force => true do |t|
223 t.integer "user_id"
223 t.integer "user_id"
224 t.datetime "started_at"
224 t.datetime "started_at"
225 t.datetime "created_at", :null => false
225 t.datetime "created_at", :null => false
226 t.datetime "updated_at", :null => false
226 t.datetime "updated_at", :null => false
227 t.boolean "forced_logout"
227 t.boolean "forced_logout"
228 end
228 end
229
229
230 create_table "users", :force => true do |t|
230 create_table "users", :force => true do |t|
231 t.string "login", :limit => 50
231 t.string "login", :limit => 50
232 t.string "full_name"
232 t.string "full_name"
233 t.string "hashed_password"
233 t.string "hashed_password"
234 t.string "salt", :limit => 5
234 t.string "salt", :limit => 5
235 t.string "alias"
235 t.string "alias"
236 t.string "email"
236 t.string "email"
237 t.integer "site_id"
237 t.integer "site_id"
238 t.integer "country_id"
238 t.integer "country_id"
239 t.boolean "activated", :default => false
239 t.boolean "activated", :default => false
240 t.datetime "created_at"
240 t.datetime "created_at"
241 t.datetime "updated_at"
241 t.datetime "updated_at"
242 - t.string "section"
243 end
242 end
244
243
245 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
244 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
246
245
247 end
246 end
@@ -7,193 +7,193
7 :description => 'Only admins can log in to the system when running under single user mode.'
7 :description => 'Only admins can log in to the system when running under single user mode.'
8 },
8 },
9
9
10 {
10 {
11 :key => 'ui.front.title',
11 :key => 'ui.front.title',
12 :value_type => 'string',
12 :value_type => 'string',
13 :default_value => 'Grader'
13 :default_value => 'Grader'
14 },
14 },
15
15
16 {
16 {
17 :key => 'ui.front.welcome_message',
17 :key => 'ui.front.welcome_message',
18 :value_type => 'string',
18 :value_type => 'string',
19 :default_value => 'Welcome!'
19 :default_value => 'Welcome!'
20 },
20 },
21
21
22 {
22 {
23 :key => 'ui.show_score',
23 :key => 'ui.show_score',
24 :value_type => 'boolean',
24 :value_type => 'boolean',
25 :default_value => 'true'
25 :default_value => 'true'
26 },
26 },
27
27
28 {
28 {
29 :key => 'contest.time_limit',
29 :key => 'contest.time_limit',
30 :value_type => 'string',
30 :value_type => 'string',
31 :default_value => 'unlimited',
31 :default_value => 'unlimited',
32 :description => 'Time limit in format hh:mm, or "unlimited" for contests with no time limits. This config is CACHED. Restart the server before the change can take effect.'
32 :description => 'Time limit in format hh:mm, or "unlimited" for contests with no time limits. This config is CACHED. Restart the server before the change can take effect.'
33 },
33 },
34
34
35 {
35 {
36 :key => 'system.mode',
36 :key => 'system.mode',
37 :value_type => 'string',
37 :value_type => 'string',
38 :default_value => 'standard',
38 :default_value => 'standard',
39 :description => 'Current modes are "standard", "contest", "indv-contest", and "analysis".'
39 :description => 'Current modes are "standard", "contest", "indv-contest", and "analysis".'
40 },
40 },
41
41
42 {
42 {
43 :key => 'contest.name',
43 :key => 'contest.name',
44 :value_type => 'string',
44 :value_type => 'string',
45 :default_value => 'Grader',
45 :default_value => 'Grader',
46 :description => 'This name will be shown on the user header bar.'
46 :description => 'This name will be shown on the user header bar.'
47 },
47 },
48
48
49 {
49 {
50 :key => 'contest.multisites',
50 :key => 'contest.multisites',
51 :value_type => 'boolean',
51 :value_type => 'boolean',
52 :default_value => 'false',
52 :default_value => 'false',
53 :description => 'If the server is in contest mode and this option is true, on the log in of the admin a menu for site selections is shown.'
53 :description => 'If the server is in contest mode and this option is true, on the log in of the admin a menu for site selections is shown.'
54 },
54 },
55
55
56 {
56 {
57 :key => 'right.user_hall_of_fame',
57 :key => 'right.user_hall_of_fame',
58 :value_type => 'boolean',
58 :value_type => 'boolean',
59 :default_value => 'false',
59 :default_value => 'false',
60 :description => 'If true, any user can access hall of fame page.'
60 :description => 'If true, any user can access hall of fame page.'
61 },
61 },
62
62
63 {
63 {
64 :key => 'right.user_view_submission',
64 :key => 'right.user_view_submission',
65 :value_type => 'boolean',
65 :value_type => 'boolean',
66 :default_value => 'false',
66 :default_value => 'false',
67 :description => 'If true, any user can view submissions of every one.'
67 :description => 'If true, any user can view submissions of every one.'
68 },
68 },
69
69
70 # If Configuration['system.online_registration'] is true, the
70 # If Configuration['system.online_registration'] is true, the
71 # system allows online registration, and will use these
71 # system allows online registration, and will use these
72 # information for sending confirmation emails.
72 # information for sending confirmation emails.
73 {
73 {
74 :key => 'system.online_registration.smtp',
74 :key => 'system.online_registration.smtp',
75 :value_type => 'string',
75 :value_type => 'string',
76 :default_value => 'smtp.somehost.com'
76 :default_value => 'smtp.somehost.com'
77 },
77 },
78
78
79 {
79 {
80 :key => 'system.online_registration.from',
80 :key => 'system.online_registration.from',
81 :value_type => 'string',
81 :value_type => 'string',
82 :default_value => 'your.email@address'
82 :default_value => 'your.email@address'
83 },
83 },
84
84
85 {
85 {
86 :key => 'system.admin_email',
86 :key => 'system.admin_email',
87 :value_type => 'string',
87 :value_type => 'string',
88 :default_value => 'admin@admin.email'
88 :default_value => 'admin@admin.email'
89 },
89 },
90
90
91 {
91 {
92 :key => 'system.user_setting_enabled',
92 :key => 'system.user_setting_enabled',
93 :value_type => 'boolean',
93 :value_type => 'boolean',
94 :default_value => 'true',
94 :default_value => 'true',
95 :description => 'If this option is true, users can change their settings'
95 :description => 'If this option is true, users can change their settings'
96 },
96 },
97
97
98 {
98 {
99 :key => 'system.user_setting_enabled',
99 :key => 'system.user_setting_enabled',
100 :value_type => 'boolean',
100 :value_type => 'boolean',
101 :default_value => 'true',
101 :default_value => 'true',
102 :description => 'If this option is true, users can change their settings'
102 :description => 'If this option is true, users can change their settings'
103 - }
103 + },
104
104
105 # If Configuration['contest.test_request.early_timeout'] is true
105 # If Configuration['contest.test_request.early_timeout'] is true
106 # the user will not be able to use test request at 30 minutes
106 # the user will not be able to use test request at 30 minutes
107 # before the contest ends.
107 # before the contest ends.
108 {
108 {
109 :key => 'contest.test_request.early_timeout',
109 :key => 'contest.test_request.early_timeout',
110 :value_type => 'boolean',
110 :value_type => 'boolean',
111 :default_value => 'false'
111 :default_value => 'false'
112 },
112 },
113
113
114 {
114 {
115 :key => 'system.multicontests',
115 :key => 'system.multicontests',
116 :value_type => 'boolean',
116 :value_type => 'boolean',
117 :default_value => 'false'
117 :default_value => 'false'
118 },
118 },
119
119
120 {
120 {
121 :key => 'contest.confirm_indv_contest_start',
121 :key => 'contest.confirm_indv_contest_start',
122 :value_type => 'boolean',
122 :value_type => 'boolean',
123 :default_value => 'false'
123 :default_value => 'false'
124 },
124 },
125
125
126 {
126 {
127 :key => 'contest.default_contest_name',
127 :key => 'contest.default_contest_name',
128 :value_type => 'string',
128 :value_type => 'string',
129 :default_value => 'none',
129 :default_value => 'none',
130 :description => "New user will be assigned to this contest automatically, if it exists. Set to 'none' if there is no default contest."
130 :description => "New user will be assigned to this contest automatically, if it exists. Set to 'none' if there is no default contest."
131 }
131 }
132
132
133 ]
133 ]
134
134
135
135
136 def create_configuration_key(key,
136 def create_configuration_key(key,
137 value_type,
137 value_type,
138 default_value,
138 default_value,
139 description='')
139 description='')
140 conf = (GraderConfiguration.find_by_key(key) ||
140 conf = (GraderConfiguration.find_by_key(key) ||
141 GraderConfiguration.new(:key => key,
141 GraderConfiguration.new(:key => key,
142 :value_type => value_type,
142 :value_type => value_type,
143 :value => default_value))
143 :value => default_value))
144 conf.description = description
144 conf.description = description
145 conf.save
145 conf.save
146 end
146 end
147
147
148 def seed_config
148 def seed_config
149 CONFIGURATIONS.each do |conf|
149 CONFIGURATIONS.each do |conf|
150 if conf.has_key? :description
150 if conf.has_key? :description
151 desc = conf[:description]
151 desc = conf[:description]
152 else
152 else
153 desc = ''
153 desc = ''
154 end
154 end
155 create_configuration_key(conf[:key],
155 create_configuration_key(conf[:key],
156 conf[:value_type],
156 conf[:value_type],
157 conf[:default_value],
157 conf[:default_value],
158 desc)
158 desc)
159 end
159 end
160 end
160 end
161
161
162 def seed_roles
162 def seed_roles
163 return if Role.find_by_name('admin')
163 return if Role.find_by_name('admin')
164
164
165 role = Role.create(:name => 'admin')
165 role = Role.create(:name => 'admin')
166 user_admin_right = Right.create(:name => 'user_admin',
166 user_admin_right = Right.create(:name => 'user_admin',
167 :controller => 'user_admin',
167 :controller => 'user_admin',
168 :action => 'all')
168 :action => 'all')
169 problem_admin_right = Right.create(:name=> 'problem_admin',
169 problem_admin_right = Right.create(:name=> 'problem_admin',
170 :controller => 'problems',
170 :controller => 'problems',
171 :action => 'all')
171 :action => 'all')
172
172
173 graders_right = Right.create(:name => 'graders_admin',
173 graders_right = Right.create(:name => 'graders_admin',
174 :controller => 'graders',
174 :controller => 'graders',
175 :action => 'all')
175 :action => 'all')
176
176
177 role.rights << user_admin_right;
177 role.rights << user_admin_right;
178 role.rights << problem_admin_right;
178 role.rights << problem_admin_right;
179 role.rights << graders_right;
179 role.rights << graders_right;
180 role.save
180 role.save
181 end
181 end
182
182
183 def seed_root
183 def seed_root
184 return if User.find_by_login('root')
184 return if User.find_by_login('root')
185
185
186 root = User.new(:login => 'root',
186 root = User.new(:login => 'root',
187 :full_name => 'Administrator',
187 :full_name => 'Administrator',
188 :alias => 'root')
188 :alias => 'root')
189 root.password = 'ioionrails';
189 root.password = 'ioionrails';
190
190
191 class << root
191 class << root
192 public :encrypt_new_password
192 public :encrypt_new_password
193 def valid?(context=nil)
193 def valid?(context=nil)
194 true
194 true
195 end
195 end
196 end
196 end
197
197
198 root.encrypt_new_password
198 root.encrypt_new_password
199
199
You need to be logged in to leave comments. Login now