Description:
Merge pull request #23 from nattee/master some bug fix
Commit status:
[Not Reviewed]
References:
merge default
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r768:f22301d0d070 - - 7 files changed: 12 inserted, 5 deleted

@@ -0,0 +1,5
1 + class ChangeSubmissionSourceSize < ActiveRecord::Migration
2 + def change
3 + change_column :submissions, :source, :text, :limit => 1.megabyte
4 + end
5 + end
@@ -166,49 +166,49
166 return
166 return
167 end
167 end
168 @submissions = Submission.includes(:user).includes(:language).where(problem_id: params[:id]).order(:user_id,:id)
168 @submissions = Submission.includes(:user).includes(:language).where(problem_id: params[:id]).order(:user_id,:id)
169
169
170 #stat summary
170 #stat summary
171 range =65
171 range =65
172 @histogram = { data: Array.new(range,0), summary: {} }
172 @histogram = { data: Array.new(range,0), summary: {} }
173 user = Hash.new(0)
173 user = Hash.new(0)
174 @submissions.find_each do |sub|
174 @submissions.find_each do |sub|
175 d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
175 d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
176 @histogram[:data][d.to_i] += 1 if d < range
176 @histogram[:data][d.to_i] += 1 if d < range
177 user[sub.user_id] = [user[sub.user_id], ((sub.try(:points) || 0) >= @problem.full_score) ? 1 : 0].max
177 user[sub.user_id] = [user[sub.user_id], ((sub.try(:points) || 0) >= @problem.full_score) ? 1 : 0].max
178 end
178 end
179 @histogram[:summary][:max] = [@histogram[:data].max,1].max
179 @histogram[:summary][:max] = [@histogram[:data].max,1].max
180
180
181 @summary = { attempt: user.count, solve: 0 }
181 @summary = { attempt: user.count, solve: 0 }
182 user.each_value { |v| @summary[:solve] += 1 if v == 1 }
182 user.each_value { |v| @summary[:solve] += 1 if v == 1 }
183 end
183 end
184
184
185 def manage
185 def manage
186 @problems = Problem.order(date_added: :desc)
186 @problems = Problem.order(date_added: :desc)
187 end
187 end
188
188
189 def do_manage
189 def do_manage
190 - if params.has_key? 'change_date_added'
190 + if params.has_key? 'change_date_added' and params[:date_added].strip.empty? == false
191 change_date_added
191 change_date_added
192 elsif params.has_key? 'add_to_contest'
192 elsif params.has_key? 'add_to_contest'
193 add_to_contest
193 add_to_contest
194 elsif params.has_key? 'enable_problem'
194 elsif params.has_key? 'enable_problem'
195 set_available(true)
195 set_available(true)
196 elsif params.has_key? 'disable_problem'
196 elsif params.has_key? 'disable_problem'
197 set_available(false)
197 set_available(false)
198 elsif params.has_key? 'add_group'
198 elsif params.has_key? 'add_group'
199 group = Group.find(params[:group_id])
199 group = Group.find(params[:group_id])
200 ok = []
200 ok = []
201 failed = []
201 failed = []
202 get_problems_from_params.each do |p|
202 get_problems_from_params.each do |p|
203 begin
203 begin
204 group.problems << p
204 group.problems << p
205 ok << p.full_name
205 ok << p.full_name
206 rescue => e
206 rescue => e
207 failed << p.full_name
207 failed << p.full_name
208 end
208 end
209 end
209 end
210 flash[:success] = "The following problems are added to the group #{group.name}: " + ok.join(', ') if ok.count > 0
210 flash[:success] = "The following problems are added to the group #{group.name}: " + ok.join(', ') if ok.count > 0
211 flash[:alert] = "The following problems are already in the group #{group.name}: " + failed.join(', ') if failed.count > 0
211 flash[:alert] = "The following problems are already in the group #{group.name}: " + failed.join(', ') if failed.count > 0
212 elsif params.has_key? 'add_tags'
212 elsif params.has_key? 'add_tags'
213 get_problems_from_params.each do |p|
213 get_problems_from_params.each do |p|
214 p.tag_ids += params[:tag_ids]
214 p.tag_ids += params[:tag_ids]
@@ -22,49 +22,49
22
22
23 #rencer accordingly
23 #rencer accordingly
24 if params[:button] == 'download' then
24 if params[:button] == 'download' then
25 csv = gen_csv_from_scorearray(@scorearray,@problems)
25 csv = gen_csv_from_scorearray(@scorearray,@problems)
26 send_data csv, filename: 'max_score.csv'
26 send_data csv, filename: 'max_score.csv'
27 else
27 else
28 #render template: 'user_admin/user_stat'
28 #render template: 'user_admin/user_stat'
29 render 'current_score'
29 render 'current_score'
30 end
30 end
31 end
31 end
32
32
33 def show_max_score
33 def show_max_score
34 #process parameters
34 #process parameters
35 #problems
35 #problems
36 @problems = []
36 @problems = []
37 if params[:problem_id]
37 if params[:problem_id]
38 params[:problem_id].each do |id|
38 params[:problem_id].each do |id|
39 next unless id.strip != ""
39 next unless id.strip != ""
40 pid = Problem.find_by_id(id.to_i)
40 pid = Problem.find_by_id(id.to_i)
41 @problems << pid if pid
41 @problems << pid if pid
42 end
42 end
43 end
43 end
44
44
45 #users
45 #users
46 - @users = if params[:user] == "all" then
46 + @users = if params[:users] == "all" then
47 User.includes(:contests).includes(:contest_stat)
47 User.includes(:contests).includes(:contest_stat)
48 else
48 else
49 User.includes(:contests).includes(:contest_stat).where(enabled: true)
49 User.includes(:contests).includes(:contest_stat).where(enabled: true)
50 end
50 end
51
51
52 #set up range from param
52 #set up range from param
53 @since_id = params.fetch(:from_id, 0).to_i
53 @since_id = params.fetch(:from_id, 0).to_i
54 @until_id = params.fetch(:to_id, 0).to_i
54 @until_id = params.fetch(:to_id, 0).to_i
55 @since_id = nil if @since_id == 0
55 @since_id = nil if @since_id == 0
56 @until_id = nil if @until_id == 0
56 @until_id = nil if @until_id == 0
57
57
58 #calculate the routine
58 #calculate the routine
59 @scorearray = calculate_max_score(@problems, @users, @since_id, @until_id)
59 @scorearray = calculate_max_score(@problems, @users, @since_id, @until_id)
60
60
61 #rencer accordingly
61 #rencer accordingly
62 if params[:button] == 'download' then
62 if params[:button] == 'download' then
63 csv = gen_csv_from_scorearray(@scorearray,@problems)
63 csv = gen_csv_from_scorearray(@scorearray,@problems)
64 send_data csv, filename: 'max_score.csv'
64 send_data csv, filename: 'max_score.csv'
65 else
65 else
66 #render template: 'user_admin/user_stat'
66 #render template: 'user_admin/user_stat'
67 render 'max_score'
67 render 'max_score'
68 end
68 end
69
69
70 end
70 end
@@ -1,35 +1,35
1 class Submission < ActiveRecord::Base
1 class Submission < ActiveRecord::Base
2
2
3 belongs_to :language
3 belongs_to :language
4 belongs_to :problem
4 belongs_to :problem
5 belongs_to :user
5 belongs_to :user
6
6
7 before_validation :assign_problem
7 before_validation :assign_problem
8 before_validation :assign_language
8 before_validation :assign_language
9
9
10 validates_presence_of :source
10 validates_presence_of :source
11 - validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long'
11 + validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'code too long, the limit is 100,000 bytes'
12 validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short'
12 validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short'
13 validate :must_have_valid_problem
13 validate :must_have_valid_problem
14 validate :must_specify_language
14 validate :must_specify_language
15
15
16 has_one :task
16 has_one :task
17
17
18 before_save :assign_latest_number_if_new_recond
18 before_save :assign_latest_number_if_new_recond
19
19
20 def self.find_last_by_user_and_problem(user_id, problem_id)
20 def self.find_last_by_user_and_problem(user_id, problem_id)
21 where("user_id = ? AND problem_id = ?",user_id,problem_id).last
21 where("user_id = ? AND problem_id = ?",user_id,problem_id).last
22 end
22 end
23
23
24 def self.find_all_last_by_problem(problem_id)
24 def self.find_all_last_by_problem(problem_id)
25 # need to put in SQL command, maybe there's a better way
25 # need to put in SQL command, maybe there's a better way
26 Submission.includes(:user).find_by_sql("SELECT * FROM submissions " +
26 Submission.includes(:user).find_by_sql("SELECT * FROM submissions " +
27 "WHERE id = " +
27 "WHERE id = " +
28 "(SELECT MAX(id) FROM submissions AS subs " +
28 "(SELECT MAX(id) FROM submissions AS subs " +
29 "WHERE subs.user_id = submissions.user_id AND " +
29 "WHERE subs.user_id = submissions.user_id AND " +
30 "problem_id = " + problem_id.to_s + " " +
30 "problem_id = " + problem_id.to_s + " " +
31 "GROUP BY user_id) " +
31 "GROUP BY user_id) " +
32 "ORDER BY user_id")
32 "ORDER BY user_id")
33 end
33 end
34
34
35 def self.find_in_range_by_user_and_problem(user_id, problem_id,since_id,until_id)
35 def self.find_in_range_by_user_and_problem(user_id, problem_id,since_id,until_id)
@@ -89,30 +89,31
89 %th Contests
89 %th Contests
90
90
91 %tbody
91 %tbody
92 - num = 0
92 - num = 0
93 - for problem in @problems
93 - for problem in @problems
94 - num += 1
94 - num += 1
95 %tr{:id => "row-prob-#{problem.id}", :name=> "prob-#{problem.id}"}
95 %tr{:id => "row-prob-#{problem.id}", :name=> "prob-#{problem.id}"}
96 %td= check_box_tag "prob-#{problem.id}-#{num}"
96 %td= check_box_tag "prob-#{problem.id}-#{num}"
97 %td= problem.name
97 %td= problem.name
98 %td= problem.full_name
98 %td= problem.full_name
99 %td
99 %td
100 - problem.tags.each do |t|
100 - problem.tags.each do |t|
101 %span.label.label-default= t.name
101 %span.label.label-default= t.name
102 %td= problem.available
102 %td= problem.available
103 %td= problem.date_added
103 %td= problem.date_added
104 - if GraderConfiguration.multicontests?
104 - if GraderConfiguration.multicontests?
105 %td
105 %td
106 - problem.contests.each do |contest|
106 - problem.contests.each do |contest|
107 = "(#{contest.name} [#{link_to 'x', :action => 'remove_contest', :id => problem.id, :contest_id => contest.id }])"
107 = "(#{contest.name} [#{link_to 'x', :action => 'remove_contest', :id => problem.id, :contest_id => contest.id }])"
108
108
109 :javascript
109 :javascript
110 $('.input-group.date').datetimepicker({
110 $('.input-group.date').datetimepicker({
111 format: 'DD/MMM/YYYY',
111 format: 'DD/MMM/YYYY',
112 showTodayButton: true,
112 showTodayButton: true,
113 + locale: 'en',
113 widgetPositioning: {horizontal: 'auto', vertical: 'bottom'},
114 widgetPositioning: {horizontal: 'auto', vertical: 'bottom'},
114
115
115 });
116 });
116 $('.datatable').DataTable({
117 $('.datatable').DataTable({
117 paging: false
118 paging: false
118 });
119 });
@@ -10,27 +10,28
10 = f.label :password, "Password"
10 = f.label :password, "Password"
11 = f.text_field :password, class: 'form-control'
11 = f.text_field :password, class: 'form-control'
12 .form-group.field
12 .form-group.field
13 = f.label :started, "Started"
13 = f.label :started, "Started"
14 = f.check_box :started, class: 'form-control'
14 = f.check_box :started, class: 'form-control'
15 .form-group.field
15 .form-group.field
16 = f.label :start_time, "Start time"
16 = f.label :start_time, "Start time"
17 -# = f.datetime_select :start_time, :include_blank => true
17 -# = f.datetime_select :start_time, :include_blank => true
18 .input-group.date
18 .input-group.date
19 = f.text_field :start_time, class:'form-control' , value: (@site.start_time ? @site.start_time.strftime('%d/%b/%Y %H:%M') : '')
19 = f.text_field :start_time, class:'form-control' , value: (@site.start_time ? @site.start_time.strftime('%d/%b/%Y %H:%M') : '')
20 %span.input-group-addon
20 %span.input-group-addon
21 %span.glyphicon.glyphicon-calendar
21 %span.glyphicon.glyphicon-calendar
22 .actions
22 .actions
23 = f.submit "Update", class: 'btn btn-primary'
23 = f.submit "Update", class: 'btn btn-primary'
24 .col-md-8
24 .col-md-8
25
25
26 = link_to 'Show', @site
26 = link_to 'Show', @site
27 |
27 |
28 = link_to 'Back', sites_path
28 = link_to 'Back', sites_path
29
29
30
30
31 :javascript
31 :javascript
32 $('.input-group.date').datetimepicker({
32 $('.input-group.date').datetimepicker({
33 format: 'DD/MMM/YYYY HH:mm',
33 format: 'DD/MMM/YYYY HH:mm',
34 + locale: 'en',
34 showTodayButton: true,
35 showTodayButton: true,
35 });
36 });
36
37
@@ -1,38 +1,38
1 # encoding: UTF-8
1 # encoding: UTF-8
2 # This file is auto-generated from the current state of the database. Instead
2 # This file is auto-generated from the current state of the database. Instead
3 # of editing this file, please use the migrations feature of Active Record to
3 # of editing this file, please use the migrations feature of Active Record to
4 # incrementally modify your database, and then regenerate this schema definition.
4 # incrementally modify your database, and then regenerate this schema definition.
5 #
5 #
6 # Note that this schema.rb definition is the authoritative source for your
6 # Note that this schema.rb definition is the authoritative source for your
7 # database schema. If you need to create the application database on another
7 # database schema. If you need to create the application database on another
8 # system, you should be using db:schema:load, not running all the migrations
8 # system, you should be using db:schema:load, not running all the migrations
9 # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9 # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10 # you'll amass, the slower it'll run and the greater likelihood for issues).
10 # you'll amass, the slower it'll run and the greater likelihood for issues).
11 #
11 #
12 # It's strongly recommended that you check this file into your version control system.
12 # It's strongly recommended that you check this file into your version control system.
13
13
14 - ActiveRecord::Schema.define(version: 20170914150742) do
14 + ActiveRecord::Schema.define(version: 20180612102327) do
15
15
16 create_table "announcements", force: :cascade do |t|
16 create_table "announcements", force: :cascade do |t|
17 t.string "author", limit: 255
17 t.string "author", limit: 255
18 t.text "body", limit: 65535
18 t.text "body", limit: 65535
19 t.boolean "published"
19 t.boolean "published"
20 t.datetime "created_at", null: false
20 t.datetime "created_at", null: false
21 t.datetime "updated_at", null: false
21 t.datetime "updated_at", null: false
22 t.boolean "frontpage", default: false
22 t.boolean "frontpage", default: false
23 t.boolean "contest_only", default: false
23 t.boolean "contest_only", default: false
24 t.string "title", limit: 255
24 t.string "title", limit: 255
25 t.string "notes", limit: 255
25 t.string "notes", limit: 255
26 end
26 end
27
27
28 create_table "contests", force: :cascade do |t|
28 create_table "contests", force: :cascade do |t|
29 t.string "title", limit: 255
29 t.string "title", limit: 255
30 t.boolean "enabled"
30 t.boolean "enabled"
31 t.datetime "created_at", null: false
31 t.datetime "created_at", null: false
32 t.datetime "updated_at", null: false
32 t.datetime "updated_at", null: false
33 t.string "name", limit: 255
33 t.string "name", limit: 255
34 end
34 end
35
35
36 create_table "contests_problems", id: false, force: :cascade do |t|
36 create_table "contests_problems", id: false, force: :cascade do |t|
37 t.integer "contest_id", limit: 4
37 t.integer "contest_id", limit: 4
38 t.integer "problem_id", limit: 4
38 t.integer "problem_id", limit: 4
@@ -188,49 +188,49
188 add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree
188 add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree
189 add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at", using: :btree
189 add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at", using: :btree
190
190
191 create_table "sites", force: :cascade do |t|
191 create_table "sites", force: :cascade do |t|
192 t.string "name", limit: 255
192 t.string "name", limit: 255
193 t.boolean "started"
193 t.boolean "started"
194 t.datetime "start_time"
194 t.datetime "start_time"
195 t.datetime "created_at", null: false
195 t.datetime "created_at", null: false
196 t.datetime "updated_at", null: false
196 t.datetime "updated_at", null: false
197 t.integer "country_id", limit: 4
197 t.integer "country_id", limit: 4
198 t.string "password", limit: 255
198 t.string "password", limit: 255
199 end
199 end
200
200
201 create_table "submission_view_logs", force: :cascade do |t|
201 create_table "submission_view_logs", force: :cascade do |t|
202 t.integer "user_id", limit: 4
202 t.integer "user_id", limit: 4
203 t.integer "submission_id", limit: 4
203 t.integer "submission_id", limit: 4
204 t.datetime "created_at", null: false
204 t.datetime "created_at", null: false
205 t.datetime "updated_at", null: false
205 t.datetime "updated_at", null: false
206 end
206 end
207
207
208 create_table "submissions", force: :cascade do |t|
208 create_table "submissions", force: :cascade do |t|
209 t.integer "user_id", limit: 4
209 t.integer "user_id", limit: 4
210 t.integer "problem_id", limit: 4
210 t.integer "problem_id", limit: 4
211 t.integer "language_id", limit: 4
211 t.integer "language_id", limit: 4
212 - t.text "source", limit: 65535
212 + t.text "source", limit: 16777215
213 t.binary "binary", limit: 65535
213 t.binary "binary", limit: 65535
214 t.datetime "submitted_at"
214 t.datetime "submitted_at"
215 t.datetime "compiled_at"
215 t.datetime "compiled_at"
216 t.text "compiler_message", limit: 65535
216 t.text "compiler_message", limit: 65535
217 t.datetime "graded_at"
217 t.datetime "graded_at"
218 t.integer "points", limit: 4
218 t.integer "points", limit: 4
219 t.text "grader_comment", limit: 65535
219 t.text "grader_comment", limit: 65535
220 t.integer "number", limit: 4
220 t.integer "number", limit: 4
221 t.string "source_filename", limit: 255
221 t.string "source_filename", limit: 255
222 t.float "max_runtime", limit: 24
222 t.float "max_runtime", limit: 24
223 t.integer "peak_memory", limit: 4
223 t.integer "peak_memory", limit: 4
224 t.integer "effective_code_length", limit: 4
224 t.integer "effective_code_length", limit: 4
225 t.string "ip_address", limit: 255
225 t.string "ip_address", limit: 255
226 end
226 end
227
227
228 add_index "submissions", ["user_id", "problem_id", "number"], name: "index_submissions_on_user_id_and_problem_id_and_number", unique: true, using: :btree
228 add_index "submissions", ["user_id", "problem_id", "number"], name: "index_submissions_on_user_id_and_problem_id_and_number", unique: true, using: :btree
229 add_index "submissions", ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id", using: :btree
229 add_index "submissions", ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id", using: :btree
230
230
231 create_table "tags", force: :cascade do |t|
231 create_table "tags", force: :cascade do |t|
232 t.string "name", limit: 255, null: false
232 t.string "name", limit: 255, null: false
233 t.text "description", limit: 65535
233 t.text "description", limit: 65535
234 t.boolean "public"
234 t.boolean "public"
235 t.datetime "created_at", null: false
235 t.datetime "created_at", null: false
236 t.datetime "updated_at", null: false
236 t.datetime "updated_at", null: false
You need to be logged in to leave comments. Login now