Description:
added codejom_status model for computing level with basic user update
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r219:95cc49d72ca8 - - 9 files changed: 79 inserted, 1 deleted
@@ -0,0 +1,15 | |||
|
1 | + class CreateCodejomStatuses < ActiveRecord::Migration | |
|
2 | + def self.up | |
|
3 | + create_table :codejom_statuses do |t| | |
|
4 | + t.integer :user_id | |
|
5 | + t.boolean :alive | |
|
6 | + t.integer :num_problems_passed | |
|
7 | + | |
|
8 | + t.timestamps | |
|
9 | + end | |
|
10 | + end | |
|
11 | + | |
|
12 | + def self.down | |
|
13 | + drop_table :codejom_statuses | |
|
14 | + end | |
|
15 | + end |
@@ -0,0 +1,11 | |||
|
1 | + # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | |
|
2 | + | |
|
3 | + one: | |
|
4 | + user_id: 1 | |
|
5 | + alive: false | |
|
6 | + num_problems_passed: 1 | |
|
7 | + | |
|
8 | + two: | |
|
9 | + user_id: 1 | |
|
10 | + alive: false | |
|
11 | + num_problems_passed: 1 |
@@ -0,0 +1,8 | |||
|
1 | + require 'test_helper' | |
|
2 | + | |
|
3 | + class CodejomStatusTest < ActiveSupport::TestCase | |
|
4 | + # Replace this with your real tests. | |
|
5 | + test "the truth" do | |
|
6 | + assert true | |
|
7 | + end | |
|
8 | + end |
@@ -237,12 +237,13 | |||
|
237 | 237 | status.submission_count += 1 |
|
238 | 238 | status.passed = passed |
|
239 | 239 | status.save |
|
240 | 240 | |
|
241 | 241 | if passed |
|
242 | 242 | flash[:notice] = 'Correct solution.' |
|
243 | + user.update_codejom_status | |
|
243 | 244 | else |
|
244 | 245 | flash[:notice] = 'Incorrect solution.' |
|
245 | 246 | end |
|
246 | 247 | redirect_to :action => 'list' |
|
247 | 248 | end |
|
248 | 249 |
@@ -26,12 +26,17 | |||
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | def self.find_available_problems |
|
29 | 29 | find(:all, :conditions => {:available => true}, :order => "date_added DESC") |
|
30 | 30 | end |
|
31 | 31 | |
|
32 | + # TODO: may try to optimize this using cache | |
|
33 | + def self.available_problem_count | |
|
34 | + return Problem.find_available_problems.length | |
|
35 | + end | |
|
36 | + | |
|
32 | 37 | def self.create_from_import_form_params(params, old_problem=nil) |
|
33 | 38 | problem = old_problem || Problem.new |
|
34 | 39 | import_params = Problem.extract_params_and_check(params, problem) |
|
35 | 40 | |
|
36 | 41 | if not problem.valid? |
|
37 | 42 | return problem, 'Error importing' |
@@ -21,12 +21,15 | |||
|
21 | 21 | |
|
22 | 22 | has_one :contest_stat, :class_name => "UserContestStat" |
|
23 | 23 | |
|
24 | 24 | belongs_to :site |
|
25 | 25 | belongs_to :country |
|
26 | 26 | |
|
27 | + # For Code Jom | |
|
28 | + has_one :codejom_status | |
|
29 | + | |
|
27 | 30 | named_scope :activated_users, :conditions => {:activated => true} |
|
28 | 31 | |
|
29 | 32 | validates_presence_of :login |
|
30 | 33 | validates_uniqueness_of :login |
|
31 | 34 | validates_format_of :login, :with => /^[\_A-Za-z0-9]+$/ |
|
32 | 35 | validates_length_of :login, :within => 3..30 |
@@ -218,12 +221,30 | |||
|
218 | 221 | return site.started |
|
219 | 222 | else |
|
220 | 223 | return true |
|
221 | 224 | end |
|
222 | 225 | end |
|
223 | 226 | |
|
227 | + # For Code Jom | |
|
228 | + def update_codejom_status | |
|
229 | + status = codejom_status || CodejomStatus.new(:user => self) | |
|
230 | + problem_count = Problem.available_problem_count | |
|
231 | + status.num_problems_passed = (self.submission_statuses.find_all {|s| s.passed}).length | |
|
232 | + status.alive = (problem_count - (status.num_problems_passed)) <= CODEJOM_MAX_ALIVE_LEVEL | |
|
233 | + status.save | |
|
234 | + end | |
|
235 | + | |
|
236 | + def codejom_level | |
|
237 | + problem_count = Problem.available_problem_count | |
|
238 | + if codejom_status!=nil | |
|
239 | + return problem_count - codejom_status.num_problems_passed | |
|
240 | + else | |
|
241 | + return problem_count | |
|
242 | + end | |
|
243 | + end | |
|
244 | + | |
|
224 | 245 | protected |
|
225 | 246 | def encrypt_new_password |
|
226 | 247 | return if password.blank? |
|
227 | 248 | self.salt = (10+rand(90)).to_s |
|
228 | 249 | self.hashed_password = User.encrypt(self.password,self.salt) |
|
229 | 250 | end |
@@ -100,6 +100,10 | |||
|
100 | 100 | # Uncomment so that Apache X-Sendfile is used when delivering files |
|
101 | 101 | # (e.g., in /tasks/view). |
|
102 | 102 | # USE_APACHE_XSENDFILE = true |
|
103 | 103 | |
|
104 | 104 | # Uncomment so that configuration is read only once when the server is loaded |
|
105 | 105 | # Configuration.enable_caching |
|
106 | + | |
|
107 | + # OPTIONS FOR CODE JOM | |
|
108 | + # -------------------- | |
|
109 | + CODEJOM_MAX_ALIVE_LEVEL = 10 |
@@ -6,25 +6,33 | |||
|
6 | 6 | # to create the application database on another system, you should be using db:schema:load, not running |
|
7 | 7 | # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
8 | 8 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
9 | 9 | # |
|
10 | 10 | # It's strongly recommended to check this file into your version control system. |
|
11 | 11 | |
|
12 |
- ActiveRecord::Schema.define(:version => 20100124 |
|
|
12 | + ActiveRecord::Schema.define(:version => 20100124191250) do | |
|
13 | 13 | |
|
14 | 14 | create_table "announcements", :force => true do |t| |
|
15 | 15 | t.string "author" |
|
16 | 16 | t.text "body" |
|
17 | 17 | t.boolean "published" |
|
18 | 18 | t.datetime "created_at" |
|
19 | 19 | t.datetime "updated_at" |
|
20 | 20 | t.boolean "frontpage", :default => false |
|
21 | 21 | t.boolean "contest_only", :default => false |
|
22 | 22 | t.string "title" |
|
23 | 23 | end |
|
24 | 24 | |
|
25 | + create_table "codejom_statuses", :force => true do |t| | |
|
26 | + t.integer "user_id" | |
|
27 | + t.boolean "alive" | |
|
28 | + t.integer "num_problems_passed" | |
|
29 | + t.datetime "created_at" | |
|
30 | + t.datetime "updated_at" | |
|
31 | + end | |
|
32 | + | |
|
25 | 33 | create_table "configurations", :force => true do |t| |
|
26 | 34 | t.string "key" |
|
27 | 35 | t.string "value_type" |
|
28 | 36 | t.string "value" |
|
29 | 37 | t.datetime "created_at" |
|
30 | 38 | t.datetime "updated_at" |
You need to be logged in to leave comments.
Login now