Description:
add 2nd level sort problem by name (not full name)
show problem name before full_name in main/list
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r409:4e03b3c502cc - - 2 files changed: 2 inserted, 2 deleted
@@ -1,113 +1,113 | |||||
|
1 | class Problem < ActiveRecord::Base |
|
1 | class Problem < ActiveRecord::Base |
|
2 |
|
2 | ||
|
3 | belongs_to :description |
|
3 | belongs_to :description |
|
4 | has_and_belongs_to_many :contests, :uniq => true |
|
4 | has_and_belongs_to_many :contests, :uniq => true |
|
5 | has_many :test_pairs, :dependent => :delete_all |
|
5 | has_many :test_pairs, :dependent => :delete_all |
|
6 |
|
6 | ||
|
7 | validates_presence_of :name |
|
7 | validates_presence_of :name |
|
8 | validates_format_of :name, :with => /^\w+$/ |
|
8 | validates_format_of :name, :with => /^\w+$/ |
|
9 | validates_presence_of :full_name |
|
9 | validates_presence_of :full_name |
|
10 |
|
10 | ||
|
11 | scope :available, :conditions => {:available => true} |
|
11 | scope :available, :conditions => {:available => true} |
|
12 |
|
12 | ||
|
13 | DEFAULT_TIME_LIMIT = 1 |
|
13 | DEFAULT_TIME_LIMIT = 1 |
|
14 | DEFAULT_MEMORY_LIMIT = 32 |
|
14 | DEFAULT_MEMORY_LIMIT = 32 |
|
15 |
|
15 | ||
|
16 | def self.find_available_problems |
|
16 | def self.find_available_problems |
|
17 | - Problem.available.all(:order => "date_added DESC") |
|
17 | + Problem.available.all(:order => "date_added DESC, name ASC") |
|
18 | end |
|
18 | end |
|
19 |
|
19 | ||
|
20 | def self.create_from_import_form_params(params, old_problem=nil) |
|
20 | def self.create_from_import_form_params(params, old_problem=nil) |
|
21 | org_problem = old_problem || Problem.new |
|
21 | org_problem = old_problem || Problem.new |
|
22 | import_params, problem = Problem.extract_params_and_check(params, |
|
22 | import_params, problem = Problem.extract_params_and_check(params, |
|
23 | org_problem) |
|
23 | org_problem) |
|
24 |
|
24 | ||
|
25 | if !problem.errors.empty? |
|
25 | if !problem.errors.empty? |
|
26 | return problem, 'Error importing' |
|
26 | return problem, 'Error importing' |
|
27 | end |
|
27 | end |
|
28 |
|
28 | ||
|
29 | problem.full_score = 100 |
|
29 | problem.full_score = 100 |
|
30 | problem.date_added = Time.new |
|
30 | problem.date_added = Time.new |
|
31 | problem.test_allowed = true |
|
31 | problem.test_allowed = true |
|
32 | problem.output_only = false |
|
32 | problem.output_only = false |
|
33 | problem.available = false |
|
33 | problem.available = false |
|
34 |
|
34 | ||
|
35 | if not problem.save |
|
35 | if not problem.save |
|
36 | return problem, 'Error importing' |
|
36 | return problem, 'Error importing' |
|
37 | end |
|
37 | end |
|
38 |
|
38 | ||
|
39 | import_to_db = params.has_key? :import_to_db |
|
39 | import_to_db = params.has_key? :import_to_db |
|
40 |
|
40 | ||
|
41 | importer = TestdataImporter.new(problem) |
|
41 | importer = TestdataImporter.new(problem) |
|
42 |
|
42 | ||
|
43 | if not importer.import_from_file(import_params[:file], |
|
43 | if not importer.import_from_file(import_params[:file], |
|
44 | import_params[:time_limit], |
|
44 | import_params[:time_limit], |
|
45 | import_params[:memory_limit], |
|
45 | import_params[:memory_limit], |
|
46 | import_params[:checker_name], |
|
46 | import_params[:checker_name], |
|
47 | import_to_db) |
|
47 | import_to_db) |
|
48 | problem.errors.add_to_base('Import error.') |
|
48 | problem.errors.add_to_base('Import error.') |
|
49 | end |
|
49 | end |
|
50 |
|
50 | ||
|
51 | return problem, importer.log_msg |
|
51 | return problem, importer.log_msg |
|
52 | end |
|
52 | end |
|
53 |
|
53 | ||
|
54 | def self.download_file_basedir |
|
54 | def self.download_file_basedir |
|
55 | return "#{Rails.root}/data/tasks" |
|
55 | return "#{Rails.root}/data/tasks" |
|
56 | end |
|
56 | end |
|
57 |
|
57 | ||
|
58 | protected |
|
58 | protected |
|
59 |
|
59 | ||
|
60 | def self.to_i_or_default(st, default) |
|
60 | def self.to_i_or_default(st, default) |
|
61 | if st!='' |
|
61 | if st!='' |
|
62 | result = st.to_i |
|
62 | result = st.to_i |
|
63 | end |
|
63 | end |
|
64 | result ||= default |
|
64 | result ||= default |
|
65 | end |
|
65 | end |
|
66 |
|
66 | ||
|
67 | def self.to_f_or_default(st, default) |
|
67 | def self.to_f_or_default(st, default) |
|
68 | if st!='' |
|
68 | if st!='' |
|
69 | result = st.to_f |
|
69 | result = st.to_f |
|
70 | end |
|
70 | end |
|
71 | result ||= default |
|
71 | result ||= default |
|
72 | end |
|
72 | end |
|
73 |
|
73 | ||
|
74 | def self.extract_params_and_check(params, problem) |
|
74 | def self.extract_params_and_check(params, problem) |
|
75 | time_limit = Problem.to_f_or_default(params[:time_limit], |
|
75 | time_limit = Problem.to_f_or_default(params[:time_limit], |
|
76 | DEFAULT_TIME_LIMIT) |
|
76 | DEFAULT_TIME_LIMIT) |
|
77 | memory_limit = Problem.to_i_or_default(params[:memory_limit], |
|
77 | memory_limit = Problem.to_i_or_default(params[:memory_limit], |
|
78 | DEFAULT_MEMORY_LIMIT) |
|
78 | DEFAULT_MEMORY_LIMIT) |
|
79 |
|
79 | ||
|
80 | if time_limit<=0 or time_limit >60 |
|
80 | if time_limit<=0 or time_limit >60 |
|
81 | problem.errors.add_to_base('Time limit out of range.') |
|
81 | problem.errors.add_to_base('Time limit out of range.') |
|
82 | end |
|
82 | end |
|
83 |
|
83 | ||
|
84 | if memory_limit==0 and params[:memory_limit]!='0' |
|
84 | if memory_limit==0 and params[:memory_limit]!='0' |
|
85 | problem.errors.add_to_base('Memory limit format errors.') |
|
85 | problem.errors.add_to_base('Memory limit format errors.') |
|
86 | elsif memory_limit<=0 or memory_limit >512 |
|
86 | elsif memory_limit<=0 or memory_limit >512 |
|
87 | problem.errors.add_to_base('Memory limit out of range.') |
|
87 | problem.errors.add_to_base('Memory limit out of range.') |
|
88 | end |
|
88 | end |
|
89 |
|
89 | ||
|
90 | if params[:file]==nil or params[:file]=='' |
|
90 | if params[:file]==nil or params[:file]=='' |
|
91 | problem.errors.add_to_base('No testdata file.') |
|
91 | problem.errors.add_to_base('No testdata file.') |
|
92 | end |
|
92 | end |
|
93 |
|
93 | ||
|
94 | checker_name = 'text' |
|
94 | checker_name = 'text' |
|
95 | if ['text','float'].include? params[:checker] |
|
95 | if ['text','float'].include? params[:checker] |
|
96 | checker_name = params[:checker] |
|
96 | checker_name = params[:checker] |
|
97 | end |
|
97 | end |
|
98 |
|
98 | ||
|
99 | file = params[:file] |
|
99 | file = params[:file] |
|
100 |
|
100 | ||
|
101 | if !problem.errors.empty? |
|
101 | if !problem.errors.empty? |
|
102 | return nil, problem |
|
102 | return nil, problem |
|
103 | end |
|
103 | end |
|
104 |
|
104 | ||
|
105 | problem.name = params[:name] |
|
105 | problem.name = params[:name] |
|
106 | if params[:full_name]!='' |
|
106 | if params[:full_name]!='' |
|
107 | problem.full_name = params[:full_name] |
|
107 | problem.full_name = params[:full_name] |
|
108 | else |
|
108 | else |
|
109 | problem.full_name = params[:name] |
|
109 | problem.full_name = params[:name] |
|
110 | end |
|
110 | end |
|
111 |
|
111 | ||
|
112 | return [{ |
|
112 | return [{ |
|
113 | :time_limit => time_limit, |
|
113 | :time_limit => time_limit, |
@@ -1,18 +1,18 | |||||
|
1 | <tr class="info-<%= (problem_counter%2==0) ? "even" : "odd" %>"> |
|
1 | <tr class="info-<%= (problem_counter%2==0) ? "even" : "odd" %>"> |
|
2 | <td> |
|
2 | <td> |
|
3 | <%= "#{problem_counter+1}" %> |
|
3 | <%= "#{problem_counter+1}" %> |
|
4 | </td> |
|
4 | </td> |
|
5 | <td> |
|
5 | <td> |
|
6 |
- <%= "#{problem.full_name} |
|
6 | + <%= "(#{problem.name}) #{problem.full_name}" %> |
|
7 | <%= link_to_description_if_any "[#{t 'main.problem_desc'}]", problem %> |
|
7 | <%= link_to_description_if_any "[#{t 'main.problem_desc'}]", problem %> |
|
8 | </td> |
|
8 | </td> |
|
9 | <td align="center"> |
|
9 | <td align="center"> |
|
10 | <%= @prob_submissions[problem.id][:count] %> |
|
10 | <%= @prob_submissions[problem.id][:count] %> |
|
11 | </td> |
|
11 | </td> |
|
12 | <td> |
|
12 | <td> |
|
13 | <%= render :partial => 'submission_short', |
|
13 | <%= render :partial => 'submission_short', |
|
14 | :locals => { |
|
14 | :locals => { |
|
15 | :submission => @prob_submissions[problem.id][:submission], |
|
15 | :submission => @prob_submissions[problem.id][:submission], |
|
16 | :problem_name => problem.name }%> |
|
16 | :problem_name => problem.name }%> |
|
17 | </td> |
|
17 | </td> |
|
18 | </tr> |
|
18 | </tr> |
You need to be logged in to leave comments.
Login now