Description:
fix bug on calculating best of each lanuage
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r438:1c02c7fc8a89 - - 1 file changed: 1 inserted, 1 deleted
@@ -71,119 +71,119 | |||||
|
71 | a = Problem.find(s.problem_id) |
|
71 | a = Problem.find(s.problem_id) |
|
72 | rescue |
|
72 | rescue |
|
73 | a = nil |
|
73 | a = nil |
|
74 | end |
|
74 | end |
|
75 | @submissions[s.user_id][:sub][s.problem_id] = |
|
75 | @submissions[s.user_id][:sub][s.problem_id] = |
|
76 | { prob_name: (a ? a.full_name : '(NULL)'), |
|
76 | { prob_name: (a ? a.full_name : '(NULL)'), |
|
77 | sub_ids: [s.id] } |
|
77 | sub_ids: [s.id] } |
|
78 | else |
|
78 | else |
|
79 | @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id |
|
79 | @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id |
|
80 | end |
|
80 | end |
|
81 | @submissions[s.user_id][:count] += 1 |
|
81 | @submissions[s.user_id][:count] += 1 |
|
82 | end |
|
82 | end |
|
83 | end |
|
83 | end |
|
84 | end |
|
84 | end |
|
85 |
|
85 | ||
|
86 | def problem_hof |
|
86 | def problem_hof |
|
87 | # gen problem list |
|
87 | # gen problem list |
|
88 | @user = User.find(session[:user_id]) |
|
88 | @user = User.find(session[:user_id]) |
|
89 | @problems = @user.available_problems |
|
89 | @problems = @user.available_problems |
|
90 |
|
90 | ||
|
91 | # get selected problems or the default |
|
91 | # get selected problems or the default |
|
92 | if params[:id] |
|
92 | if params[:id] |
|
93 | begin |
|
93 | begin |
|
94 | @problem = Problem.available.find(params[:id]) |
|
94 | @problem = Problem.available.find(params[:id]) |
|
95 | rescue |
|
95 | rescue |
|
96 | redirect_to action: :problem_hof |
|
96 | redirect_to action: :problem_hof |
|
97 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
97 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
98 | return |
|
98 | return |
|
99 | end |
|
99 | end |
|
100 | end |
|
100 | end |
|
101 |
|
101 | ||
|
102 | if @problem |
|
102 | if @problem |
|
103 | #aggregrate by language |
|
103 | #aggregrate by language |
|
104 | @by_lang = {} |
|
104 | @by_lang = {} |
|
105 | Submission.where(problem_id: @problem.id).find_each do |sub| |
|
105 | Submission.where(problem_id: @problem.id).find_each do |sub| |
|
106 | lang = Language.find_by_id(sub.language_id) |
|
106 | lang = Language.find_by_id(sub.language_id) |
|
107 | next unless lang |
|
107 | next unless lang |
|
108 | next unless sub.points >= @problem.full_score |
|
108 | next unless sub.points >= @problem.full_score |
|
109 |
|
109 | ||
|
110 | #initialize |
|
110 | #initialize |
|
111 | unless @by_lang.has_key?(lang.pretty_name) |
|
111 | unless @by_lang.has_key?(lang.pretty_name) |
|
112 | @by_lang[lang.pretty_name] = { |
|
112 | @by_lang[lang.pretty_name] = { |
|
113 | runtime: { avail: false, value: 2**30-1 }, |
|
113 | runtime: { avail: false, value: 2**30-1 }, |
|
114 | memory: { avail: false, value: 2**30-1 }, |
|
114 | memory: { avail: false, value: 2**30-1 }, |
|
115 | length: { avail: false, value: 2**30-1 }, |
|
115 | length: { avail: false, value: 2**30-1 }, |
|
116 | first: { avail: false, value: DateTime.new(3000,1,1) } |
|
116 | first: { avail: false, value: DateTime.new(3000,1,1) } |
|
117 | } |
|
117 | } |
|
118 | end |
|
118 | end |
|
119 |
|
119 | ||
|
120 | if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value] |
|
120 | if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value] |
|
121 | @by_lang[lang.pretty_name][:runtime] = { |
|
121 | @by_lang[lang.pretty_name][:runtime] = { |
|
122 | avail: true, |
|
122 | avail: true, |
|
123 | user_id: sub.user_id, |
|
123 | user_id: sub.user_id, |
|
124 | value: sub.max_runtime, |
|
124 | value: sub.max_runtime, |
|
125 | sub_id: sub.id |
|
125 | sub_id: sub.id |
|
126 | } |
|
126 | } |
|
127 | end |
|
127 | end |
|
128 |
|
128 | ||
|
129 | if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value] |
|
129 | if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value] |
|
130 | @by_lang[lang.pretty_name][:memory] = { |
|
130 | @by_lang[lang.pretty_name][:memory] = { |
|
131 | avail: true, |
|
131 | avail: true, |
|
132 | user_id: sub.user_id, |
|
132 | user_id: sub.user_id, |
|
133 | value: sub.peak_memory, |
|
133 | value: sub.peak_memory, |
|
134 | sub_id: sub.id |
|
134 | sub_id: sub.id |
|
135 | } |
|
135 | } |
|
136 | end |
|
136 | end |
|
137 |
|
137 | ||
|
138 | if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and |
|
138 | if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and |
|
139 | !sub.user.admin? |
|
139 | !sub.user.admin? |
|
140 | @by_lang[lang.pretty_name][:first] = { |
|
140 | @by_lang[lang.pretty_name][:first] = { |
|
141 | avail: true, |
|
141 | avail: true, |
|
142 | user_id: sub.user_id, |
|
142 | user_id: sub.user_id, |
|
143 | value: sub.submitted_at, |
|
143 | value: sub.submitted_at, |
|
144 | sub_id: sub.id |
|
144 | sub_id: sub.id |
|
145 | } |
|
145 | } |
|
146 | end |
|
146 | end |
|
147 |
|
147 | ||
|
148 | if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length |
|
148 | if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length |
|
149 | @by_lang[lang.pretty_name][:length] = { |
|
149 | @by_lang[lang.pretty_name][:length] = { |
|
150 | avail: true, |
|
150 | avail: true, |
|
151 | user_id: sub.user_id, |
|
151 | user_id: sub.user_id, |
|
152 | value: sub.effective_code_length, |
|
152 | value: sub.effective_code_length, |
|
153 | sub_id: sub.id |
|
153 | sub_id: sub.id |
|
154 | } |
|
154 | } |
|
155 | end |
|
155 | end |
|
156 | end |
|
156 | end |
|
157 |
|
157 | ||
|
158 | #process user_id |
|
158 | #process user_id |
|
159 | @by_lang.each do |lang,prop| |
|
159 | @by_lang.each do |lang,prop| |
|
160 | prop.each do |k,v| |
|
160 | prop.each do |k,v| |
|
161 | v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)" |
|
161 | v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)" |
|
162 | end |
|
162 | end |
|
163 | end |
|
163 | end |
|
164 |
|
164 | ||
|
165 | #sum into best |
|
165 | #sum into best |
|
166 | if @by_lang and @by_lang.first |
|
166 | if @by_lang and @by_lang.first |
|
167 | - @best = @by_lang.first[1] |
|
167 | + @best = @by_lang.first[1].clone |
|
168 | @by_lang.each do |lang,prop| |
|
168 | @by_lang.each do |lang,prop| |
|
169 | if @best[:runtime][:value] >= prop[:runtime][:value] |
|
169 | if @best[:runtime][:value] >= prop[:runtime][:value] |
|
170 | @best[:runtime] = prop[:runtime] |
|
170 | @best[:runtime] = prop[:runtime] |
|
171 | @best[:runtime][:lang] = lang |
|
171 | @best[:runtime][:lang] = lang |
|
172 | end |
|
172 | end |
|
173 | if @best[:memory][:value] >= prop[:memory][:value] |
|
173 | if @best[:memory][:value] >= prop[:memory][:value] |
|
174 | @best[:memory] = prop[:memory] |
|
174 | @best[:memory] = prop[:memory] |
|
175 | @best[:memory][:lang] = lang |
|
175 | @best[:memory][:lang] = lang |
|
176 | end |
|
176 | end |
|
177 | if @best[:length][:value] >= prop[:length][:value] |
|
177 | if @best[:length][:value] >= prop[:length][:value] |
|
178 | @best[:length] = prop[:length] |
|
178 | @best[:length] = prop[:length] |
|
179 | @best[:length][:lang] = lang |
|
179 | @best[:length][:lang] = lang |
|
180 | end |
|
180 | end |
|
181 | if @best[:first][:value] >= prop[:first][:value] |
|
181 | if @best[:first][:value] >= prop[:first][:value] |
|
182 | @best[:first] = prop[:first] |
|
182 | @best[:first] = prop[:first] |
|
183 | @best[:first][:lang] = lang |
|
183 | @best[:first][:lang] = lang |
|
184 | end |
|
184 | end |
|
185 | end |
|
185 | end |
|
186 | end |
|
186 | end |
|
187 | end |
|
187 | end |
|
188 | end |
|
188 | end |
|
189 | end |
|
189 | end |
You need to be logged in to leave comments.
Login now