Description:
problems sorted by update time
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
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,132 +1,134 | |||
|
1 | 1 | class Problem < ActiveRecord::Base |
|
2 | 2 | |
|
3 | 3 | belongs_to :description |
|
4 | 4 | has_many :test_pairs, :dependent => :delete_all |
|
5 | 5 | |
|
6 | 6 | named_scope :level, lambda { |level| |
|
7 | 7 | { :conditions => { :level => level }} |
|
8 | 8 | } |
|
9 | 9 | |
|
10 | 10 | named_scope :unavailable, { :conditions => { :available => false }} |
|
11 | 11 | |
|
12 | 12 | |
|
13 | 13 | validates_presence_of :name |
|
14 | 14 | validates_format_of :name, :with => /^\w+$/ |
|
15 | 15 | validates_presence_of :full_name |
|
16 | 16 | |
|
17 | 17 | DEFAULT_TIME_LIMIT = 1 |
|
18 | 18 | DEFAULT_MEMORY_LIMIT = 32 |
|
19 | 19 | |
|
20 | 20 | def test_pair_count |
|
21 | 21 | @test_pair_count ||= test_pairs.size |
|
22 | 22 | end |
|
23 | 23 | |
|
24 | 24 | def uses_random_test_pair? |
|
25 | 25 | test_pair_count != 0 |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | def random_test_pair(forbidden_numbers=nil) |
|
29 | 29 | if forbidden_numbers.length < test_pair_count |
|
30 | 30 | begin |
|
31 | 31 | test_num = 1 + rand(test_pair_count) |
|
32 | 32 | end while forbidden_numbers!=nil and forbidden_numbers.include? test_num |
|
33 | 33 | else |
|
34 | 34 | test_num = 1 + rand(test_pair_count) |
|
35 | 35 | end |
|
36 | 36 | test_pairs.find_by_number test_num |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 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 | 43 | end |
|
42 | 44 | |
|
43 | 45 | # TODO: may try to optimize this using cache |
|
44 | 46 | def self.available_problem_count |
|
45 | 47 | return Problem.find_available_problems.length |
|
46 | 48 | end |
|
47 | 49 | |
|
48 | 50 | def self.create_from_import_form_params(params, old_problem=nil) |
|
49 | 51 | problem = old_problem || Problem.new |
|
50 | 52 | import_params = Problem.extract_params_and_check(params, problem) |
|
51 | 53 | |
|
52 | 54 | if not problem.valid? |
|
53 | 55 | return problem, 'Error importing' |
|
54 | 56 | end |
|
55 | 57 | |
|
56 | 58 | problem.full_score = 100 |
|
57 | 59 | problem.date_added = Time.new |
|
58 | 60 | problem.test_allowed = true |
|
59 | 61 | problem.output_only = false |
|
60 | 62 | problem.available = false |
|
61 | 63 | |
|
62 | 64 | if not problem.save |
|
63 | 65 | return problem, 'Error importing' |
|
64 | 66 | end |
|
65 | 67 | |
|
66 | 68 | import_to_db = params.has_key? :import_to_db |
|
67 | 69 | |
|
68 | 70 | importer = TestdataImporter.new(problem) |
|
69 | 71 | |
|
70 | 72 | if not importer.import_from_file(import_params[:file], |
|
71 | 73 | import_params[:time_limit], |
|
72 | 74 | import_params[:memory_limit], |
|
73 | 75 | import_to_db) |
|
74 | 76 | problem.errors.add_to_base('Import error.') |
|
75 | 77 | end |
|
76 | 78 | |
|
77 | 79 | return problem, importer.log_msg |
|
78 | 80 | end |
|
79 | 81 | |
|
80 | 82 | protected |
|
81 | 83 | |
|
82 | 84 | def self.to_i_or_default(st, default) |
|
83 | 85 | if st!='' |
|
84 | 86 | st.to_i |
|
85 | 87 | else |
|
86 | 88 | default |
|
87 | 89 | end |
|
88 | 90 | end |
|
89 | 91 | |
|
90 | 92 | def self.extract_params_and_check(params, problem) |
|
91 | 93 | time_limit = Problem.to_i_or_default(params[:time_limit], |
|
92 | 94 | DEFAULT_TIME_LIMIT) |
|
93 | 95 | memory_limit = Problem.to_i_or_default(params[:memory_limit], |
|
94 | 96 | DEFAULT_MEMORY_LIMIT) |
|
95 | 97 | |
|
96 | 98 | if time_limit==0 and time_limit_s!='0' |
|
97 | 99 | problem.errors.add_to_base('Time limit format errors.') |
|
98 | 100 | elsif time_limit<=0 or time_limit >60 |
|
99 | 101 | problem.errors.add_to_base('Time limit out of range.') |
|
100 | 102 | end |
|
101 | 103 | |
|
102 | 104 | if memory_limit==0 and memory_limit_s!='0' |
|
103 | 105 | problem.errors.add_to_base('Memory limit format errors.') |
|
104 | 106 | elsif memory_limit<=0 or memory_limit >512 |
|
105 | 107 | problem.errors.add_to_base('Memory limit out of range.') |
|
106 | 108 | end |
|
107 | 109 | |
|
108 | 110 | if params[:file]==nil or params[:file]=='' |
|
109 | 111 | problem.errors.add_to_base('No testdata file.') |
|
110 | 112 | end |
|
111 | 113 | |
|
112 | 114 | file = params[:file] |
|
113 | 115 | |
|
114 | 116 | if problem.errors.length!=0 |
|
115 | 117 | return problem |
|
116 | 118 | end |
|
117 | 119 | |
|
118 | 120 | problem.name = params[:name] |
|
119 | 121 | if params[:full_name]!='' |
|
120 | 122 | problem.full_name = params[:full_name] |
|
121 | 123 | else |
|
122 | 124 | problem.full_name = params[:name] |
|
123 | 125 | end |
|
124 | 126 | |
|
125 | 127 | return { |
|
126 | 128 | :time_limit => time_limit, |
|
127 | 129 | :memory_limit => memory_limit, |
|
128 | 130 | :file => file |
|
129 | 131 | } |
|
130 | 132 | end |
|
131 | 133 | |
|
132 | 134 | end |
@@ -1,42 +1,42 | |||
|
1 | 1 | - content_for :head do |
|
2 | 2 | = javascript_include_tag :defaults |
|
3 | 3 | = javascript_include_tag 'announcement_refresh.js' |
|
4 | 4 | = javascript_include_tag 'codejom_timeout.js' |
|
5 | 5 | |
|
6 | 6 | = user_title_bar(@user) |
|
7 | 7 | |
|
8 | 8 | .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")} |
|
9 | 9 | %span{:class => 'title'} |
|
10 | 10 | Announcements |
|
11 | 11 | #announcementbox-body |
|
12 | 12 | = render :partial => 'announcement', :collection => @announcements |
|
13 | 13 | |
|
14 | 14 | %hr/ |
|
15 | 15 | |
|
16 | 16 | - if (Configuration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true) |
|
17 | 17 | %p=t 'main.start_soon' |
|
18 | 18 | |
|
19 | 19 | - if Configuration.show_tasks_to?(@user) |
|
20 | 20 | .problem-list{:id => 'problem-list'} |
|
21 | 21 | = render :partial => 'problem_title', :collection => @problems, :as => :problem |
|
22 | 22 | .problem-content |
|
23 | 23 | %span{:id => "problem-panel-filler", :style => (@current_problem_id!=nil) ? "display:none" : ""} |
|
24 | 24 | %h2 |
|
25 | 25 | Welcome to Code Jom |
|
26 | 26 | %br/ |
|
27 | 27 | Choose problems from the list on the right. |
|
28 | 28 | = render :partial => 'problem', :collection => @problems |
|
29 | 29 | |
|
30 | 30 | %br{:clear=>'both'}/ |
|
31 | 31 | %hr/ |
|
32 | 32 | |
|
33 | 33 | %script{:type => 'text/javascript'} |
|
34 | 34 | = "Announcement.refreshUrl = '#{url_for :controller => 'main', :action => 'announcements'}';" |
|
35 | 35 | Announcement.registerRefreshEventTimer(); |
|
36 | 36 | = render :partial => 'submission_timeouts' |
|
37 | 37 | CodejomTimeout.updateProblemMessages(); |
|
38 | 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,192 +1,193 | |||
|
1 | 1 | # This file is auto-generated from the current state of the database. Instead of editing this file, |
|
2 | 2 | # please use the migrations feature of Active Record to incrementally modify your database, and |
|
3 | 3 | # then regenerate this schema definition. |
|
4 | 4 | # |
|
5 | 5 | # Note that this schema.rb definition is the authoritative source for your database schema. If you need |
|
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 => 201002 |
|
|
12 | + ActiveRecord::Schema.define(:version => 20100210012432) 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 | 25 | create_table "codejom_statuses", :force => true do |t| |
|
26 | 26 | t.integer "user_id" |
|
27 | 27 | t.boolean "alive" |
|
28 | 28 | t.integer "num_problems_passed" |
|
29 | 29 | t.datetime "created_at" |
|
30 | 30 | t.datetime "updated_at" |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | create_table "configurations", :force => true do |t| |
|
34 | 34 | t.string "key" |
|
35 | 35 | t.string "value_type" |
|
36 | 36 | t.string "value" |
|
37 | 37 | t.datetime "created_at" |
|
38 | 38 | t.datetime "updated_at" |
|
39 | 39 | t.text "description" |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | create_table "countries", :force => true do |t| |
|
43 | 43 | t.string "name" |
|
44 | 44 | t.datetime "created_at" |
|
45 | 45 | t.datetime "updated_at" |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | create_table "descriptions", :force => true do |t| |
|
49 | 49 | t.text "body" |
|
50 | 50 | t.boolean "markdowned" |
|
51 | 51 | t.datetime "created_at" |
|
52 | 52 | t.datetime "updated_at" |
|
53 | 53 | end |
|
54 | 54 | |
|
55 | 55 | create_table "grader_processes", :force => true do |t| |
|
56 | 56 | t.string "host", :limit => 20 |
|
57 | 57 | t.integer "pid" |
|
58 | 58 | t.string "mode" |
|
59 | 59 | t.boolean "active" |
|
60 | 60 | t.datetime "created_at" |
|
61 | 61 | t.datetime "updated_at" |
|
62 | 62 | t.integer "task_id" |
|
63 | 63 | t.string "task_type" |
|
64 | 64 | t.boolean "terminated" |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid" |
|
68 | 68 | |
|
69 | 69 | create_table "languages", :force => true do |t| |
|
70 | 70 | t.string "name", :limit => 10 |
|
71 | 71 | t.string "pretty_name" |
|
72 | 72 | t.string "ext", :limit => 10 |
|
73 | 73 | t.string "common_ext" |
|
74 | 74 | end |
|
75 | 75 | |
|
76 | 76 | create_table "messages", :force => true do |t| |
|
77 | 77 | t.integer "sender_id" |
|
78 | 78 | t.integer "receiver_id" |
|
79 | 79 | t.integer "replying_message_id" |
|
80 | 80 | t.text "body" |
|
81 | 81 | t.boolean "replied" |
|
82 | 82 | t.datetime "created_at" |
|
83 | 83 | t.datetime "updated_at" |
|
84 | 84 | end |
|
85 | 85 | |
|
86 | 86 | create_table "problems", :force => true do |t| |
|
87 | 87 | t.string "name", :limit => 30 |
|
88 | 88 | t.string "full_name" |
|
89 | 89 | t.integer "full_score" |
|
90 | 90 | t.date "date_added" |
|
91 | 91 | t.boolean "available" |
|
92 | 92 | t.string "url" |
|
93 | 93 | t.integer "description_id" |
|
94 | 94 | t.boolean "test_allowed" |
|
95 | 95 | t.boolean "output_only" |
|
96 | 96 | t.integer "level", :default => 0 |
|
97 | + t.datetime "updated_at" | |
|
97 | 98 | end |
|
98 | 99 | |
|
99 | 100 | create_table "rights", :force => true do |t| |
|
100 | 101 | t.string "name" |
|
101 | 102 | t.string "controller" |
|
102 | 103 | t.string "action" |
|
103 | 104 | end |
|
104 | 105 | |
|
105 | 106 | create_table "rights_roles", :id => false, :force => true do |t| |
|
106 | 107 | t.integer "right_id" |
|
107 | 108 | t.integer "role_id" |
|
108 | 109 | end |
|
109 | 110 | |
|
110 | 111 | add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id" |
|
111 | 112 | |
|
112 | 113 | create_table "roles", :force => true do |t| |
|
113 | 114 | t.string "name" |
|
114 | 115 | end |
|
115 | 116 | |
|
116 | 117 | create_table "roles_users", :id => false, :force => true do |t| |
|
117 | 118 | t.integer "role_id" |
|
118 | 119 | t.integer "user_id" |
|
119 | 120 | end |
|
120 | 121 | |
|
121 | 122 | add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id" |
|
122 | 123 | |
|
123 | 124 | create_table "sessions", :force => true do |t| |
|
124 | 125 | t.string "session_id" |
|
125 | 126 | t.text "data" |
|
126 | 127 | t.datetime "updated_at" |
|
127 | 128 | end |
|
128 | 129 | |
|
129 | 130 | add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id" |
|
130 | 131 | add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at" |
|
131 | 132 | |
|
132 | 133 | create_table "sites", :force => true do |t| |
|
133 | 134 | t.string "name" |
|
134 | 135 | t.boolean "started" |
|
135 | 136 | t.datetime "start_time" |
|
136 | 137 | t.datetime "created_at" |
|
137 | 138 | t.datetime "updated_at" |
|
138 | 139 | t.integer "country_id" |
|
139 | 140 | t.string "password" |
|
140 | 141 | end |
|
141 | 142 | |
|
142 | 143 | create_table "submission_statuses", :force => true do |t| |
|
143 | 144 | t.integer "user_id" |
|
144 | 145 | t.integer "problem_id" |
|
145 | 146 | t.boolean "passed" |
|
146 | 147 | t.integer "submission_count" |
|
147 | 148 | t.datetime "created_at" |
|
148 | 149 | t.datetime "updated_at" |
|
149 | 150 | end |
|
150 | 151 | |
|
151 | 152 | create_table "submissions", :force => true do |t| |
|
152 | 153 | t.integer "user_id" |
|
153 | 154 | t.integer "problem_id" |
|
154 | 155 | t.integer "language_id" |
|
155 | 156 | t.text "source" |
|
156 | 157 | t.binary "binary" |
|
157 | 158 | t.datetime "submitted_at" |
|
158 | 159 | t.datetime "compiled_at" |
|
159 | 160 | t.text "compiler_message" |
|
160 | 161 | t.datetime "graded_at" |
|
161 | 162 | t.integer "points" |
|
162 | 163 | t.text "grader_comment" |
|
163 | 164 | t.integer "number" |
|
164 | 165 | t.string "source_filename" |
|
165 | 166 | end |
|
166 | 167 | |
|
167 | 168 | add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true |
|
168 | 169 | add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id" |
|
169 | 170 | |
|
170 | 171 | create_table "tasks", :force => true do |t| |
|
171 | 172 | t.integer "submission_id" |
|
172 | 173 | t.datetime "created_at" |
|
173 | 174 | t.integer "status" |
|
174 | 175 | t.datetime "updated_at" |
|
175 | 176 | end |
|
176 | 177 | |
|
177 | 178 | create_table "test_pair_assignments", :force => true do |t| |
|
178 | 179 | t.integer "user_id" |
|
179 | 180 | t.integer "problem_id" |
|
180 | 181 | t.integer "test_pair_id" |
|
181 | 182 | t.integer "test_pair_number" |
|
182 | 183 | t.integer "request_number" |
|
183 | 184 | t.datetime "created_at" |
|
184 | 185 | t.datetime "updated_at" |
|
185 | 186 | t.boolean "submitted" |
|
186 | 187 | end |
|
187 | 188 | |
|
188 | 189 | create_table "test_pairs", :force => true do |t| |
|
189 | 190 | t.integer "problem_id" |
|
190 | 191 | t.text "input", :limit => 16777215 |
|
191 | 192 | t.text "solution", :limit => 16777215 |
|
192 | 193 | t.datetime "created_at" |
You need to be logged in to leave comments.
Login now