Description:
problems sorted by update time
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r258:1821e2e3aeb0 - - 4 files changed: 15 inserted, 3 deleted

@@ -0,0 +1,9
1 + class AddTimestampToProblems < ActiveRecord::Migration
2 + def self.up
3 + add_column :problems, :updated_at, :timestamp
4 + end
5 +
6 + def self.down
7 + remove_column :problems, :updated_at
8 + end
9 + end
@@ -1,88 +1,90
1 class Problem < ActiveRecord::Base
1 class Problem < ActiveRecord::Base
2
2
3 belongs_to :description
3 belongs_to :description
4 has_many :test_pairs, :dependent => :delete_all
4 has_many :test_pairs, :dependent => :delete_all
5
5
6 named_scope :level, lambda { |level|
6 named_scope :level, lambda { |level|
7 { :conditions => { :level => level }}
7 { :conditions => { :level => level }}
8 }
8 }
9
9
10 named_scope :unavailable, { :conditions => { :available => false }}
10 named_scope :unavailable, { :conditions => { :available => false }}
11
11
12
12
13 validates_presence_of :name
13 validates_presence_of :name
14 validates_format_of :name, :with => /^\w+$/
14 validates_format_of :name, :with => /^\w+$/
15 validates_presence_of :full_name
15 validates_presence_of :full_name
16
16
17 DEFAULT_TIME_LIMIT = 1
17 DEFAULT_TIME_LIMIT = 1
18 DEFAULT_MEMORY_LIMIT = 32
18 DEFAULT_MEMORY_LIMIT = 32
19
19
20 def test_pair_count
20 def test_pair_count
21 @test_pair_count ||= test_pairs.size
21 @test_pair_count ||= test_pairs.size
22 end
22 end
23
23
24 def uses_random_test_pair?
24 def uses_random_test_pair?
25 test_pair_count != 0
25 test_pair_count != 0
26 end
26 end
27
27
28 def random_test_pair(forbidden_numbers=nil)
28 def random_test_pair(forbidden_numbers=nil)
29 if forbidden_numbers.length < test_pair_count
29 if forbidden_numbers.length < test_pair_count
30 begin
30 begin
31 test_num = 1 + rand(test_pair_count)
31 test_num = 1 + rand(test_pair_count)
32 end while forbidden_numbers!=nil and forbidden_numbers.include? test_num
32 end while forbidden_numbers!=nil and forbidden_numbers.include? test_num
33 else
33 else
34 test_num = 1 + rand(test_pair_count)
34 test_num = 1 + rand(test_pair_count)
35 end
35 end
36 test_pairs.find_by_number test_num
36 test_pairs.find_by_number test_num
37 end
37 end
38
38
39 def self.find_available_problems
39 def self.find_available_problems
40 - find(:all, :conditions => {:available => true}, :order => "date_added DESC")
40 + find(:all,
41 + :conditions => {:available => true},
42 + :order => "updated_at DESC")
41 end
43 end
42
44
43 # TODO: may try to optimize this using cache
45 # TODO: may try to optimize this using cache
44 def self.available_problem_count
46 def self.available_problem_count
45 return Problem.find_available_problems.length
47 return Problem.find_available_problems.length
46 end
48 end
47
49
48 def self.create_from_import_form_params(params, old_problem=nil)
50 def self.create_from_import_form_params(params, old_problem=nil)
49 problem = old_problem || Problem.new
51 problem = old_problem || Problem.new
50 import_params = Problem.extract_params_and_check(params, problem)
52 import_params = Problem.extract_params_and_check(params, problem)
51
53
52 if not problem.valid?
54 if not problem.valid?
53 return problem, 'Error importing'
55 return problem, 'Error importing'
54 end
56 end
55
57
56 problem.full_score = 100
58 problem.full_score = 100
57 problem.date_added = Time.new
59 problem.date_added = Time.new
58 problem.test_allowed = true
60 problem.test_allowed = true
59 problem.output_only = false
61 problem.output_only = false
60 problem.available = false
62 problem.available = false
61
63
62 if not problem.save
64 if not problem.save
63 return problem, 'Error importing'
65 return problem, 'Error importing'
64 end
66 end
65
67
66 import_to_db = params.has_key? :import_to_db
68 import_to_db = params.has_key? :import_to_db
67
69
68 importer = TestdataImporter.new(problem)
70 importer = TestdataImporter.new(problem)
69
71
70 if not importer.import_from_file(import_params[:file],
72 if not importer.import_from_file(import_params[:file],
71 import_params[:time_limit],
73 import_params[:time_limit],
72 import_params[:memory_limit],
74 import_params[:memory_limit],
73 import_to_db)
75 import_to_db)
74 problem.errors.add_to_base('Import error.')
76 problem.errors.add_to_base('Import error.')
75 end
77 end
76
78
77 return problem, importer.log_msg
79 return problem, importer.log_msg
78 end
80 end
79
81
80 protected
82 protected
81
83
82 def self.to_i_or_default(st, default)
84 def self.to_i_or_default(st, default)
83 if st!=''
85 if st!=''
84 st.to_i
86 st.to_i
85 else
87 else
86 default
88 default
87 end
89 end
88 end
90 end
@@ -1,42 +1,42
1 - content_for :head do
1 - content_for :head do
2 = javascript_include_tag :defaults
2 = javascript_include_tag :defaults
3 = javascript_include_tag 'announcement_refresh.js'
3 = javascript_include_tag 'announcement_refresh.js'
4 = javascript_include_tag 'codejom_timeout.js'
4 = javascript_include_tag 'codejom_timeout.js'
5
5
6 = user_title_bar(@user)
6 = user_title_bar(@user)
7
7
8 .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")}
8 .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")}
9 %span{:class => 'title'}
9 %span{:class => 'title'}
10 Announcements
10 Announcements
11 #announcementbox-body
11 #announcementbox-body
12 = render :partial => 'announcement', :collection => @announcements
12 = render :partial => 'announcement', :collection => @announcements
13
13
14 %hr/
14 %hr/
15
15
16 - if (Configuration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true)
16 - if (Configuration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true)
17 %p=t 'main.start_soon'
17 %p=t 'main.start_soon'
18
18
19 - if Configuration.show_tasks_to?(@user)
19 - if Configuration.show_tasks_to?(@user)
20 .problem-list{:id => 'problem-list'}
20 .problem-list{:id => 'problem-list'}
21 = render :partial => 'problem_title', :collection => @problems, :as => :problem
21 = render :partial => 'problem_title', :collection => @problems, :as => :problem
22 .problem-content
22 .problem-content
23 %span{:id => "problem-panel-filler", :style => (@current_problem_id!=nil) ? "display:none" : ""}
23 %span{:id => "problem-panel-filler", :style => (@current_problem_id!=nil) ? "display:none" : ""}
24 %h2
24 %h2
25 Welcome to Code Jom
25 Welcome to Code Jom
26 %br/
26 %br/
27 Choose problems from the list on the right.
27 Choose problems from the list on the right.
28 = render :partial => 'problem', :collection => @problems
28 = render :partial => 'problem', :collection => @problems
29
29
30 %br{:clear=>'both'}/
30 %br{:clear=>'both'}/
31 %hr/
31 %hr/
32
32
33 %script{:type => 'text/javascript'}
33 %script{:type => 'text/javascript'}
34 = "Announcement.refreshUrl = '#{url_for :controller => 'main', :action => 'announcements'}';"
34 = "Announcement.refreshUrl = '#{url_for :controller => 'main', :action => 'announcements'}';"
35 Announcement.registerRefreshEventTimer();
35 Announcement.registerRefreshEventTimer();
36 = render :partial => 'submission_timeouts'
36 = render :partial => 'submission_timeouts'
37 CodejomTimeout.updateProblemMessages();
37 CodejomTimeout.updateProblemMessages();
38 CodejomTimeout.registerRefreshEvent();
38 CodejomTimeout.registerRefreshEvent();
39
39
40 - = periodically_call_remote(:url => { :action => 'problems' }, :update => 'problem-list')
40 + = periodically_call_remote(:url => { :action => 'problems' }, :update => 'problem-list', :frequency => '3')
41
41
42
42
@@ -1,144 +1,145
1 # This file is auto-generated from the current state of the database. Instead of editing this file,
1 # This file is auto-generated from the current state of the database. Instead of editing this file,
2 # please use the migrations feature of Active Record to incrementally modify your database, and
2 # please use the migrations feature of Active Record to incrementally modify your database, and
3 # then regenerate this schema definition.
3 # then regenerate this schema definition.
4 #
4 #
5 # Note that this schema.rb definition is the authoritative source for your database schema. If you need
5 # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6 # to create the application database on another system, you should be using db:schema:load, not running
6 # to create the application database on another system, you should be using db:schema:load, not running
7 # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
7 # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8 # you'll amass, the slower it'll run and the greater likelihood for issues).
8 # you'll amass, the slower it'll run and the greater likelihood for issues).
9 #
9 #
10 # It's strongly recommended to check this file into your version control system.
10 # It's strongly recommended to check this file into your version control system.
11
11
12 - ActiveRecord::Schema.define(:version => 20100209145331) do
12 + ActiveRecord::Schema.define(:version => 20100210012432) do
13
13
14 create_table "announcements", :force => true do |t|
14 create_table "announcements", :force => true do |t|
15 t.string "author"
15 t.string "author"
16 t.text "body"
16 t.text "body"
17 t.boolean "published"
17 t.boolean "published"
18 t.datetime "created_at"
18 t.datetime "created_at"
19 t.datetime "updated_at"
19 t.datetime "updated_at"
20 t.boolean "frontpage", :default => false
20 t.boolean "frontpage", :default => false
21 t.boolean "contest_only", :default => false
21 t.boolean "contest_only", :default => false
22 t.string "title"
22 t.string "title"
23 end
23 end
24
24
25 create_table "codejom_statuses", :force => true do |t|
25 create_table "codejom_statuses", :force => true do |t|
26 t.integer "user_id"
26 t.integer "user_id"
27 t.boolean "alive"
27 t.boolean "alive"
28 t.integer "num_problems_passed"
28 t.integer "num_problems_passed"
29 t.datetime "created_at"
29 t.datetime "created_at"
30 t.datetime "updated_at"
30 t.datetime "updated_at"
31 end
31 end
32
32
33 create_table "configurations", :force => true do |t|
33 create_table "configurations", :force => true do |t|
34 t.string "key"
34 t.string "key"
35 t.string "value_type"
35 t.string "value_type"
36 t.string "value"
36 t.string "value"
37 t.datetime "created_at"
37 t.datetime "created_at"
38 t.datetime "updated_at"
38 t.datetime "updated_at"
39 t.text "description"
39 t.text "description"
40 end
40 end
41
41
42 create_table "countries", :force => true do |t|
42 create_table "countries", :force => true do |t|
43 t.string "name"
43 t.string "name"
44 t.datetime "created_at"
44 t.datetime "created_at"
45 t.datetime "updated_at"
45 t.datetime "updated_at"
46 end
46 end
47
47
48 create_table "descriptions", :force => true do |t|
48 create_table "descriptions", :force => true do |t|
49 t.text "body"
49 t.text "body"
50 t.boolean "markdowned"
50 t.boolean "markdowned"
51 t.datetime "created_at"
51 t.datetime "created_at"
52 t.datetime "updated_at"
52 t.datetime "updated_at"
53 end
53 end
54
54
55 create_table "grader_processes", :force => true do |t|
55 create_table "grader_processes", :force => true do |t|
56 t.string "host", :limit => 20
56 t.string "host", :limit => 20
57 t.integer "pid"
57 t.integer "pid"
58 t.string "mode"
58 t.string "mode"
59 t.boolean "active"
59 t.boolean "active"
60 t.datetime "created_at"
60 t.datetime "created_at"
61 t.datetime "updated_at"
61 t.datetime "updated_at"
62 t.integer "task_id"
62 t.integer "task_id"
63 t.string "task_type"
63 t.string "task_type"
64 t.boolean "terminated"
64 t.boolean "terminated"
65 end
65 end
66
66
67 add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
67 add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
68
68
69 create_table "languages", :force => true do |t|
69 create_table "languages", :force => true do |t|
70 t.string "name", :limit => 10
70 t.string "name", :limit => 10
71 t.string "pretty_name"
71 t.string "pretty_name"
72 t.string "ext", :limit => 10
72 t.string "ext", :limit => 10
73 t.string "common_ext"
73 t.string "common_ext"
74 end
74 end
75
75
76 create_table "messages", :force => true do |t|
76 create_table "messages", :force => true do |t|
77 t.integer "sender_id"
77 t.integer "sender_id"
78 t.integer "receiver_id"
78 t.integer "receiver_id"
79 t.integer "replying_message_id"
79 t.integer "replying_message_id"
80 t.text "body"
80 t.text "body"
81 t.boolean "replied"
81 t.boolean "replied"
82 t.datetime "created_at"
82 t.datetime "created_at"
83 t.datetime "updated_at"
83 t.datetime "updated_at"
84 end
84 end
85
85
86 create_table "problems", :force => true do |t|
86 create_table "problems", :force => true do |t|
87 t.string "name", :limit => 30
87 t.string "name", :limit => 30
88 t.string "full_name"
88 t.string "full_name"
89 t.integer "full_score"
89 t.integer "full_score"
90 t.date "date_added"
90 t.date "date_added"
91 t.boolean "available"
91 t.boolean "available"
92 t.string "url"
92 t.string "url"
93 t.integer "description_id"
93 t.integer "description_id"
94 t.boolean "test_allowed"
94 t.boolean "test_allowed"
95 t.boolean "output_only"
95 t.boolean "output_only"
96 t.integer "level", :default => 0
96 t.integer "level", :default => 0
97 + t.datetime "updated_at"
97 end
98 end
98
99
99 create_table "rights", :force => true do |t|
100 create_table "rights", :force => true do |t|
100 t.string "name"
101 t.string "name"
101 t.string "controller"
102 t.string "controller"
102 t.string "action"
103 t.string "action"
103 end
104 end
104
105
105 create_table "rights_roles", :id => false, :force => true do |t|
106 create_table "rights_roles", :id => false, :force => true do |t|
106 t.integer "right_id"
107 t.integer "right_id"
107 t.integer "role_id"
108 t.integer "role_id"
108 end
109 end
109
110
110 add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id"
111 add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id"
111
112
112 create_table "roles", :force => true do |t|
113 create_table "roles", :force => true do |t|
113 t.string "name"
114 t.string "name"
114 end
115 end
115
116
116 create_table "roles_users", :id => false, :force => true do |t|
117 create_table "roles_users", :id => false, :force => true do |t|
117 t.integer "role_id"
118 t.integer "role_id"
118 t.integer "user_id"
119 t.integer "user_id"
119 end
120 end
120
121
121 add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id"
122 add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id"
122
123
123 create_table "sessions", :force => true do |t|
124 create_table "sessions", :force => true do |t|
124 t.string "session_id"
125 t.string "session_id"
125 t.text "data"
126 t.text "data"
126 t.datetime "updated_at"
127 t.datetime "updated_at"
127 end
128 end
128
129
129 add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
130 add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
130 add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
131 add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
131
132
132 create_table "sites", :force => true do |t|
133 create_table "sites", :force => true do |t|
133 t.string "name"
134 t.string "name"
134 t.boolean "started"
135 t.boolean "started"
135 t.datetime "start_time"
136 t.datetime "start_time"
136 t.datetime "created_at"
137 t.datetime "created_at"
137 t.datetime "updated_at"
138 t.datetime "updated_at"
138 t.integer "country_id"
139 t.integer "country_id"
139 t.string "password"
140 t.string "password"
140 end
141 end
141
142
142 create_table "submission_statuses", :force => true do |t|
143 create_table "submission_statuses", :force => true do |t|
143 t.integer "user_id"
144 t.integer "user_id"
144 t.integer "problem_id"
145 t.integer "problem_id"
You need to be logged in to leave comments. Login now