Description:
update problem stat to show all submissions change view to haml
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r448:f7ee3d7bf71a - - 4 files changed: 36 inserted, 31 deleted

@@ -0,0 +1,34
1 + :css
2 + .fix-width {
3 + font-family: "Consolas, Monaco, Droid Sans Mono,Mono, Monospace,Courier"
4 + }
5 +
6 + %h1 Problem stat: #{@problem.name}
7 + %h2 Overview
8 +
9 + %h2 Submissions
10 + - if @submissions and @submissions.count > 0
11 + %table.info#main_table
12 + %thead
13 + %tr.info-head
14 + %th ID
15 + %th Login
16 + %th Name
17 + %th Submitted_at
18 + %th Points
19 + %th comment
20 + %tbody
21 + - row_odd,curr = true,''
22 + - @submissions.each do |sub|
23 + - next unless sub.user
24 + - row_odd,curr = !row_odd, sub.user if curr != sub.user
25 + %tr{class: row_odd ? "info-odd" : "info-even"}
26 + %td= link_to sub.id, controller: 'graders', action: 'submission', id: sub.id
27 + %td= link_to sub.user.login, controller: :users, action: :profile, id: sub.user.id
28 + %td= sub.user.full_name
29 + %td= time_ago_in_words(sub.submitted_at) + " ago"
30 + %td= sub.points
31 + %td.fix-width= sub.grader_comment
32 + - else
33 + No submission
34 +
@@ -86,97 +86,97
86 86 elsif @description!=nil
87 87 if !@description.update_attributes(params[:description])
88 88 flash[:notice] = 'Error saving description'
89 89 render :action => 'edit' and return
90 90 end
91 91 end
92 92 if @problem.update_attributes(params[:problem])
93 93 flash[:notice] = 'Problem was successfully updated.'
94 94 redirect_to :action => 'show', :id => @problem
95 95 else
96 96 render :action => 'edit'
97 97 end
98 98 end
99 99
100 100 def destroy
101 101 Problem.find(params[:id]).destroy
102 102 redirect_to :action => 'list'
103 103 end
104 104
105 105 def toggle
106 106 @problem = Problem.find(params[:id])
107 107 @problem.available = !(@problem.available)
108 108 @problem.save
109 109 end
110 110
111 111 def turn_all_off
112 112 Problem.find(:all,
113 113 :conditions => "available = 1").each do |problem|
114 114 problem.available = false
115 115 problem.save
116 116 end
117 117 redirect_to :action => 'list'
118 118 end
119 119
120 120 def turn_all_on
121 121 Problem.find(:all,
122 122 :conditions => "available = 0").each do |problem|
123 123 problem.available = true
124 124 problem.save
125 125 end
126 126 redirect_to :action => 'list'
127 127 end
128 128
129 129 def stat
130 130 @problem = Problem.find(params[:id])
131 131 if !@problem.available
132 132 redirect_to :controller => 'main', :action => 'list'
133 133 else
134 - @submissions = Submission.find_all_last_by_problem(params[:id])
134 + @submissions = Submission.includes(:user).where(problem_id: params[:id]).order(:user_id,:id)
135 135 end
136 136 end
137 137
138 138 def manage
139 139 @problems = Problem.find(:all, :order => 'date_added DESC')
140 140 end
141 141
142 142 def do_manage
143 143 if params.has_key? 'change_date_added'
144 144 change_date_added
145 145 else params.has_key? 'add_to_contest'
146 146 add_to_contest
147 147 end
148 148 redirect_to :action => 'manage'
149 149 end
150 150
151 151 def import
152 152 @allow_test_pair_import = allow_test_pair_import?
153 153 end
154 154
155 155 def do_import
156 156 old_problem = Problem.find_by_name(params[:name])
157 157 if !allow_test_pair_import? and params.has_key? :import_to_db
158 158 params.delete :import_to_db
159 159 end
160 160 @problem, import_log = Problem.create_from_import_form_params(params,
161 161 old_problem)
162 162
163 163 if !@problem.errors.empty?
164 164 render :action => 'import' and return
165 165 end
166 166
167 167 if old_problem!=nil
168 168 flash[:notice] = "The test data has been replaced for problem #{@problem.name}"
169 169 end
170 170 @log = import_log
171 171 end
172 172
173 173 def remove_contest
174 174 problem = Problem.find(params[:id])
175 175 contest = Contest.find(params[:contest_id])
176 176 if problem!=nil and contest!=nil
177 177 problem.contests.delete(contest)
178 178 end
179 179 redirect_to :action => 'manage'
180 180 end
181 181
182 182 ##################################
@@ -1,76 +1,76
1 1 class Submission < ActiveRecord::Base
2 2
3 3 belongs_to :language
4 4 belongs_to :problem
5 5 belongs_to :user
6 6
7 7 before_validation :assign_problem
8 8 before_validation :assign_language
9 9
10 10 validates_presence_of :source
11 11 validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long'
12 12 validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short'
13 13 validate :must_have_valid_problem
14 14 validate :must_specify_language
15 15
16 16 before_save :assign_latest_number_if_new_recond
17 17
18 18 def self.find_last_by_user_and_problem(user_id, problem_id)
19 19 last_sub = find(:first,
20 20 :conditions => {:user_id => user_id,
21 21 :problem_id => problem_id},
22 22 :order => 'number DESC')
23 23 return last_sub
24 24 end
25 25
26 26 def self.find_all_last_by_problem(problem_id)
27 27 # need to put in SQL command, maybe there's a better way
28 - Submission.find_by_sql("SELECT * FROM submissions " +
28 + Submission.includes(:user).find_by_sql("SELECT * FROM submissions " +
29 29 "WHERE id = " +
30 30 "(SELECT MAX(id) FROM submissions AS subs " +
31 31 "WHERE subs.user_id = submissions.user_id AND " +
32 32 "problem_id = " + problem_id.to_s + " " +
33 33 "GROUP BY user_id) " +
34 34 "ORDER BY user_id")
35 35 end
36 36
37 37 def self.find_in_range_by_user_and_problem(user_id, problem_id,since_id,until_id)
38 38 records = Submission.where(problem_id: problem_id,user_id: user_id)
39 39 records = records.where('id >= ?',since_id) if since_id > 0
40 40 records = records.where('id <= ?',until_id) if until_id > 0
41 41 records.all
42 42 end
43 43
44 44 def self.find_last_for_all_available_problems(user_id)
45 45 submissions = Array.new
46 46 problems = Problem.find_available_problems
47 47 problems.each do |problem|
48 48 sub = Submission.find_last_by_user_and_problem(user_id, problem.id)
49 49 submissions << sub if sub!=nil
50 50 end
51 51 submissions
52 52 end
53 53
54 54 def self.find_by_user_problem_number(user_id, problem_id, number)
55 55 Submission.find(:first,
56 56 :conditions => {
57 57 :user_id => user_id,
58 58 :problem_id => problem_id,
59 59 :number => number
60 60 })
61 61 end
62 62
63 63 def self.find_all_by_user_problem(user_id, problem_id)
64 64 Submission.find(:all,
65 65 :conditions => {
66 66 :user_id => user_id,
67 67 :problem_id => problem_id,
68 68 })
69 69 end
70 70
71 71 def download_filename
72 72 if self.problem.output_only
73 73 return self.source_filename
74 74 else
75 75 timestamp = self.submitted_at.localtime.strftime("%H%M%S")
76 76 return "#{self.problem.name}-#{timestamp}.#{self.language.ext}"
deleted file
You need to be logged in to leave comments. Login now