Description:
updated test_request.rb to work with grader
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@92 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r43:305f703e60aa - - 1 file changed: 10 inserted, 6 deleted
@@ -20,12 +20,20 | |||
|
20 | 20 | set_table_name "test_requests" |
|
21 | 21 | |
|
22 | 22 | belongs_to :user |
|
23 | 23 | belongs_to :problem |
|
24 | 24 | belongs_to :submission |
|
25 | 25 | |
|
26 | + def problem_name | |
|
27 | + TestRequest.name_of(self.problem) | |
|
28 | + end | |
|
29 | + | |
|
30 | + def language | |
|
31 | + self.submission.language | |
|
32 | + end | |
|
33 | + | |
|
26 | 34 | def self.get_inqueue_and_change_status(status) |
|
27 | 35 | # since there will be only one grader grading TestRequest |
|
28 | 36 | # we do not need locking (hopefully) |
|
29 | 37 | |
|
30 | 38 | task = Task.find(:first, |
|
31 | 39 | :order => "created_at", |
@@ -51,36 +59,32 | |||
|
51 | 59 | test_request.input_file_name = save_input_file(params[:input_file], user, problem) |
|
52 | 60 | test_request.submitted_at = Time.new |
|
53 | 61 | test_request.status_inqueue |
|
54 | 62 | test_request |
|
55 | 63 | end |
|
56 | 64 | |
|
57 | - def problem_name | |
|
58 | - TestRequest.name_of(self.problem) | |
|
59 | - end | |
|
60 | - | |
|
61 | 65 | protected |
|
62 | 66 | |
|
63 | 67 | def self.name_of(problem) |
|
64 | 68 | if problem!=nil |
|
65 | 69 | problem.name |
|
66 | 70 | else |
|
67 | 71 | "default" |
|
68 | 72 | end |
|
69 | 73 | end |
|
70 | 74 | |
|
71 | - def self.input_file_name(user,problem) | |
|
75 | + def self.random_input_file_name(user,problem) | |
|
72 | 76 | problem_name = TestRequest.name_of(problem) |
|
73 | 77 | begin |
|
74 | 78 | tmpname = TEST_REQUEST_INPUT_FILE_DIR + "/#{user.login}/#{problem_name}/#{rand(10000)}" |
|
75 | 79 | end while File.exists?(tmpname) |
|
76 | 80 | tmpname |
|
77 | 81 | end |
|
78 | 82 | |
|
79 | 83 | def self.save_input_file(tempfile, user, problem) |
|
80 | - new_file_name = input_file_name(user,problem) | |
|
84 | + new_file_name = random_input_file_name(user,problem) | |
|
81 | 85 | dirname = File.dirname(new_file_name) |
|
82 | 86 | FileUtils.mkdir_p(File.dirname(new_file_name)) if !File.exists?(dirname) |
|
83 | 87 | if tempfile.instance_of?(Tempfile) |
|
84 | 88 | tempfile.close |
|
85 | 89 | FileUtils.move(tempfile.path,new_file_name) |
|
86 | 90 | else |
You need to be logged in to leave comments.
Login now