Description:
- start adding testcases into database
- fix download button for score report
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r607:350b2d080045 - - 7 files changed: 77 inserted, 6 deleted
@@ -0,0 +1,4 | |||
|
1 | + class Testcase < ActiveRecord::Base | |
|
2 | + belongs_to :problem | |
|
3 | + attr_accessible :group, :input, :num, :score, :sol | |
|
4 | + end |
@@ -0,0 +1,15 | |||
|
1 | + class CreateTestcases < ActiveRecord::Migration | |
|
2 | + def change | |
|
3 | + create_table :testcases do |t| | |
|
4 | + t.references :problem | |
|
5 | + t.integer :num | |
|
6 | + t.integer :group | |
|
7 | + t.integer :score | |
|
8 | + t.text :input | |
|
9 | + t.text :sol | |
|
10 | + | |
|
11 | + t.timestamps | |
|
12 | + end | |
|
13 | + add_index :testcases, :problem_id | |
|
14 | + end | |
|
15 | + end |
@@ -0,0 +1,5 | |||
|
1 | + require 'spec_helper' | |
|
2 | + | |
|
3 | + describe Testcases do | |
|
4 | + pending "add some examples to (or delete) #{__FILE__}" | |
|
5 | + end |
@@ -1,84 +1,86 | |||
|
1 | + require 'csv' | |
|
2 | + | |
|
1 | 3 | class ReportController < ApplicationController |
|
2 | 4 | |
|
3 | 5 | before_filter :authenticate |
|
4 | 6 | |
|
5 | 7 | before_filter :admin_authorization, only: [:login_stat,:submission_stat, :stuck, :cheat_report, :cheat_scruntinize, :show_max_score] |
|
6 | 8 | |
|
7 | 9 | before_filter(only: [:problem_hof]) { |c| |
|
8 | 10 | return false unless authenticate |
|
9 | 11 | |
|
10 | 12 | if GraderConfiguration["right.user_view_submission"] |
|
11 | 13 | return true; |
|
12 | 14 | end |
|
13 | 15 | |
|
14 | 16 | admin_authorization |
|
15 | 17 | } |
|
16 | 18 | |
|
17 | 19 | def max_score |
|
18 | 20 | end |
|
19 | 21 | |
|
20 | 22 | def current_score |
|
21 | 23 | @problems = Problem.find_available_problems |
|
22 | 24 | @users = User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
23 | 25 | @scorearray = calculate_max_score(@problems, @users,0,0,true) |
|
24 | 26 | |
|
25 | 27 | #rencer accordingly |
|
26 |
- if params[: |
|
|
28 | + if params[:button] == 'download' then | |
|
27 | 29 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
28 | 30 | send_data csv, filename: 'max_score.csv' |
|
29 | 31 | else |
|
30 | 32 | #render template: 'user_admin/user_stat' |
|
31 | 33 | render 'current_score' |
|
32 | 34 | end |
|
33 | 35 | end |
|
34 | 36 | |
|
35 | 37 | def show_max_score |
|
36 | 38 | #process parameters |
|
37 | 39 | #problems |
|
38 | 40 | @problems = [] |
|
39 | 41 | params[:problem_id].each do |id| |
|
40 | 42 | next unless id.strip != "" |
|
41 | 43 | pid = Problem.find_by_id(id.to_i) |
|
42 | 44 | @problems << pid if pid |
|
43 | 45 | end |
|
44 | 46 | |
|
45 | 47 | #users |
|
46 | 48 | @users = if params[:user] == "all" then |
|
47 | 49 | User.find(:all, :include => [:contests, :contest_stat]) |
|
48 | 50 | else |
|
49 | 51 | User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
50 | 52 | end |
|
51 | 53 | |
|
52 | 54 | #set up range from param |
|
53 | 55 | since_id = params.fetch(:min_id, 0).to_i |
|
54 | 56 | until_id = params.fetch(:max_id, 0).to_i |
|
55 | 57 | |
|
56 | 58 | #calculate the routine |
|
57 | 59 | @scorearray = calculate_max_score(@problems, @users,since_id,until_id) |
|
58 | 60 | |
|
59 | 61 | #rencer accordingly |
|
60 |
- if params[: |
|
|
62 | + if params[:button] == 'download' then | |
|
61 | 63 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
62 | 64 | send_data csv, filename: 'max_score.csv' |
|
63 | 65 | else |
|
64 | 66 | #render template: 'user_admin/user_stat' |
|
65 | 67 | render 'max_score' |
|
66 | 68 | end |
|
67 | 69 | |
|
68 | 70 | end |
|
69 | 71 | |
|
70 | 72 | def score |
|
71 | 73 | if params[:commit] == 'download csv' |
|
72 | 74 | @problems = Problem.all |
|
73 | 75 | else |
|
74 | 76 | @problems = Problem.find_available_problems |
|
75 | 77 | end |
|
76 | 78 | @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true) |
|
77 | 79 | @scorearray = Array.new |
|
78 | 80 | @users.each do |u| |
|
79 | 81 | ustat = Array.new |
|
80 | 82 | ustat[0] = u |
|
81 | 83 | @problems.each do |p| |
|
82 | 84 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
83 | 85 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
84 | 86 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
@@ -464,25 +466,56 | |||
|
464 | 466 | ustat[0] = u |
|
465 | 467 | problems.each do |p| |
|
466 | 468 | unless get_last_score |
|
467 | 469 | #get max score |
|
468 | 470 | max_points = 0 |
|
469 | 471 | Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| |
|
470 | 472 | max_points = sub.points if sub and sub.points and (sub.points > max_points) |
|
471 | 473 | end |
|
472 | 474 | ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)] |
|
473 | 475 | else |
|
474 | 476 | #get latest score |
|
475 | 477 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
476 | 478 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
477 | 479 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
478 | 480 | else |
|
479 | 481 | ustat << [0,false] |
|
480 | 482 | end |
|
481 | 483 | end |
|
482 | 484 | end |
|
483 | 485 | scorearray << ustat |
|
484 | 486 | end |
|
485 | 487 | return scorearray |
|
486 | 488 | end |
|
487 | 489 | |
|
490 | + def gen_csv_from_scorearray(scorearray,problem) | |
|
491 | + CSV.generate do |csv| | |
|
492 | + #add header | |
|
493 | + header = ['User','Name', 'Activated?', 'Logged in', 'Contest'] | |
|
494 | + problem.each { |p| header << p.name } | |
|
495 | + header += ['Total','Passed'] | |
|
496 | + csv << header | |
|
497 | + #add data | |
|
498 | + scorearray.each do |sc| | |
|
499 | + total = num_passed = 0 | |
|
500 | + row = Array.new | |
|
501 | + sc.each_index do |i| | |
|
502 | + if i == 0 | |
|
503 | + row << sc[i].login | |
|
504 | + row << sc[i].full_name | |
|
505 | + row << sc[i].activated | |
|
506 | + row << (sc[i].try(:contest_stat).try(:started_at)!=nil ? 'yes' : 'no') | |
|
507 | + row << sc[i].contests.collect {|c| c.name}.join(', ') | |
|
508 | + else | |
|
509 | + row << sc[i][0] | |
|
510 | + total += sc[i][0] | |
|
511 | + num_passed += 1 if sc[i][1] | |
|
488 | 512 | end |
|
513 | + end | |
|
514 | + row << total | |
|
515 | + row << num_passed | |
|
516 | + csv << row | |
|
517 | + end | |
|
518 | + end | |
|
519 | + end | |
|
520 | + | |
|
521 | + end |
@@ -1,29 +1,30 | |||
|
1 | 1 | class Problem < ActiveRecord::Base |
|
2 | 2 | |
|
3 | 3 | belongs_to :description |
|
4 | 4 | has_and_belongs_to_many :contests, :uniq => true |
|
5 | 5 | has_many :test_pairs, :dependent => :delete_all |
|
6 | + has_many :testcases, :dependent => :destroy | |
|
6 | 7 | |
|
7 | 8 | validates_presence_of :name |
|
8 | 9 | validates_format_of :name, :with => /^\w+$/ |
|
9 | 10 | validates_presence_of :full_name |
|
10 | 11 | |
|
11 | 12 | scope :available, :conditions => {:available => true} |
|
12 | 13 | |
|
13 | 14 | DEFAULT_TIME_LIMIT = 1 |
|
14 | 15 | DEFAULT_MEMORY_LIMIT = 32 |
|
15 | 16 | |
|
16 | 17 | def self.find_available_problems |
|
17 | 18 | Problem.available.all(:order => "date_added DESC, name ASC") |
|
18 | 19 | end |
|
19 | 20 | |
|
20 | 21 | def self.create_from_import_form_params(params, old_problem=nil) |
|
21 | 22 | org_problem = old_problem || Problem.new |
|
22 | 23 | import_params, problem = Problem.extract_params_and_check(params, |
|
23 | 24 | org_problem) |
|
24 | 25 | |
|
25 | 26 | if !problem.errors.empty? |
|
26 | 27 | return problem, 'Error importing' |
|
27 | 28 | end |
|
28 | 29 | |
|
29 | 30 | problem.full_score = 100 |
@@ -1,49 +1,49 | |||
|
1 | 1 | %h1 Maximum score |
|
2 | 2 | |
|
3 | 3 | = form_tag report_show_max_score_path |
|
4 | 4 | .row |
|
5 | 5 | .col-md-4 |
|
6 | 6 | .panel.panel-primary |
|
7 | 7 | .panel-heading |
|
8 | 8 | Problems |
|
9 | 9 | .panel-body |
|
10 | 10 | %p |
|
11 | 11 | Select problem(s) that we wish to know the score. |
|
12 | 12 | = label_tag :problem_id, "Problems" |
|
13 | 13 | = select_tag 'problem_id[]', |
|
14 | - options_for_select(Problem.all.collect {|p| ["[#{p.name}] #{p.full_name}", p.id]}), | |
|
14 | + options_for_select(Problem.all.collect {|p| ["[#{p.name}] #{p.full_name}", p.id]},params[:problem_id]), | |
|
15 | 15 | { class: 'select2 form-control', multiple: "true" } |
|
16 | 16 | .col-md-4 |
|
17 | 17 | .panel.panel-primary |
|
18 | 18 | .panel-heading |
|
19 | 19 | Submission range |
|
20 | 20 | .panel-body |
|
21 | 21 | %p |
|
22 | 22 | Input minimum and maximum range of submission ID that should be included. A blank value for min and max means -1 and infinity, respectively. |
|
23 | 23 | .form-group |
|
24 | 24 | = label_tag :from, "Min" |
|
25 | 25 | = text_field_tag 'from_id', nil, class: "form-control" |
|
26 | 26 | .form-group |
|
27 | 27 | = label_tag :from, "Max" |
|
28 | 28 | = text_field_tag 'to_id', nil, class: "form-control" |
|
29 | 29 | .col-md-4 |
|
30 | 30 | .panel.panel-primary |
|
31 | 31 | .panel-heading |
|
32 | 32 | Users |
|
33 | 33 | .panel-body |
|
34 | 34 | .radio |
|
35 | 35 | %label |
|
36 | 36 | = radio_button_tag 'users', 'all', true |
|
37 | 37 | All users |
|
38 | 38 | .radio |
|
39 | 39 | %label |
|
40 | 40 | = radio_button_tag 'users', 'enabled' |
|
41 | 41 | Only enabled users |
|
42 | 42 | .row |
|
43 | 43 | .col-md-12 |
|
44 | - = button_tag 'Show', class: "btn btn-primary btn-large" | |
|
45 | - = button_tag 'Download CSV', class: "btn btn-primary btn-large" | |
|
44 | + = button_tag 'Show', class: "btn btn-primary btn-large", value: "show" | |
|
45 | + = button_tag 'Download CSV', class: "btn btn-primary btn-large", value: "download" | |
|
46 | 46 | |
|
47 | 47 | - if @scorearray |
|
48 | 48 | %h2 Result |
|
49 | 49 | =render "score_table" |
@@ -1,38 +1,38 | |||
|
1 | 1 | # encoding: UTF-8 |
|
2 | 2 | # This file is auto-generated from the current state of the database. Instead |
|
3 | 3 | # of editing this file, please use the migrations feature of Active Record to |
|
4 | 4 | # incrementally modify your database, and then regenerate this schema definition. |
|
5 | 5 | # |
|
6 | 6 | # Note that this schema.rb definition is the authoritative source for your |
|
7 | 7 | # database schema. If you need to create the application database on another |
|
8 | 8 | # system, you should be using db:schema:load, not running all the migrations |
|
9 | 9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
10 | 10 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
11 | 11 | # |
|
12 | 12 | # It's strongly recommended to check this file into your version control system. |
|
13 | 13 | |
|
14 |
- ActiveRecord::Schema.define(:version => 201610 |
|
|
14 | + ActiveRecord::Schema.define(:version => 20161014091417) do | |
|
15 | 15 | |
|
16 | 16 | create_table "announcements", :force => true do |t| |
|
17 | 17 | t.string "author" |
|
18 | 18 | t.text "body" |
|
19 | 19 | t.boolean "published" |
|
20 | 20 | t.datetime "created_at", :null => false |
|
21 | 21 | t.datetime "updated_at", :null => false |
|
22 | 22 | t.boolean "frontpage", :default => false |
|
23 | 23 | t.boolean "contest_only", :default => false |
|
24 | 24 | t.string "title" |
|
25 | 25 | t.string "notes" |
|
26 | 26 | end |
|
27 | 27 | |
|
28 | 28 | create_table "contests", :force => true do |t| |
|
29 | 29 | t.string "title" |
|
30 | 30 | t.boolean "enabled" |
|
31 | 31 | t.datetime "created_at", :null => false |
|
32 | 32 | t.datetime "updated_at", :null => false |
|
33 | 33 | t.string "name" |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | create_table "contests_problems", :id => false, :force => true do |t| |
|
37 | 37 | t.integer "contest_id" |
|
38 | 38 | t.integer "problem_id" |
@@ -215,48 +215,61 | |||
|
215 | 215 | end |
|
216 | 216 | |
|
217 | 217 | create_table "test_requests", :force => true do |t| |
|
218 | 218 | t.integer "user_id" |
|
219 | 219 | t.integer "problem_id" |
|
220 | 220 | t.integer "submission_id" |
|
221 | 221 | t.string "input_file_name" |
|
222 | 222 | t.string "output_file_name" |
|
223 | 223 | t.string "running_stat" |
|
224 | 224 | t.integer "status" |
|
225 | 225 | t.datetime "updated_at", :null => false |
|
226 | 226 | t.datetime "submitted_at" |
|
227 | 227 | t.datetime "compiled_at" |
|
228 | 228 | t.text "compiler_message" |
|
229 | 229 | t.datetime "graded_at" |
|
230 | 230 | t.string "grader_comment" |
|
231 | 231 | t.datetime "created_at", :null => false |
|
232 | 232 | t.float "running_time" |
|
233 | 233 | t.string "exit_status" |
|
234 | 234 | t.integer "memory_usage" |
|
235 | 235 | end |
|
236 | 236 | |
|
237 | 237 | add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id" |
|
238 | 238 | |
|
239 | + create_table "testcases", :force => true do |t| | |
|
240 | + t.integer "problem_id" | |
|
241 | + t.integer "num" | |
|
242 | + t.integer "group" | |
|
243 | + t.integer "score" | |
|
244 | + t.text "input" | |
|
245 | + t.text "sol" | |
|
246 | + t.datetime "created_at", :null => false | |
|
247 | + t.datetime "updated_at", :null => false | |
|
248 | + end | |
|
249 | + | |
|
250 | + add_index "testcases", ["problem_id"], :name => "index_testcases_on_problem_id" | |
|
251 | + | |
|
239 | 252 | create_table "user_contest_stats", :force => true do |t| |
|
240 | 253 | t.integer "user_id" |
|
241 | 254 | t.datetime "started_at" |
|
242 | 255 | t.datetime "created_at", :null => false |
|
243 | 256 | t.datetime "updated_at", :null => false |
|
244 | 257 | t.boolean "forced_logout" |
|
245 | 258 | end |
|
246 | 259 | |
|
247 | 260 | create_table "users", :force => true do |t| |
|
248 | 261 | t.string "login", :limit => 50 |
|
249 | 262 | t.string "full_name" |
|
250 | 263 | t.string "hashed_password" |
|
251 | 264 | t.string "salt", :limit => 5 |
|
252 | 265 | t.string "alias" |
|
253 | 266 | t.string "email" |
|
254 | 267 | t.integer "site_id" |
|
255 | 268 | t.integer "country_id" |
|
256 | 269 | t.boolean "activated", :default => false |
|
257 | 270 | t.datetime "created_at" |
|
258 | 271 | t.datetime "updated_at" |
|
259 | 272 | t.boolean "enabled", :default => true |
|
260 | 273 | t.string "remark" |
|
261 | 274 | t.string "last_ip" |
|
262 | 275 | t.string "section" |
You need to be logged in to leave comments.
Login now