Description:
added name_of to TestRequest for dealing with null problem
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@87 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
r39:7df73373290b - - 1 file changed: 22 inserted, 1 deleted
@@ -1,12 +1,25 | |||
|
1 | + # | |
|
2 | + # A TestRequest is a composition of submission with user's testdata. | |
|
3 | + # | |
|
4 | + # Note about TestRequest#problem: Usually, A TestRequest has to be | |
|
5 | + # associated with a problem, so that execution environment can be | |
|
6 | + # determined. However, to be more flexible, we have to ensure that | |
|
7 | + # it works as well with problem=nil. In this case, we shall provide | |
|
8 | + # a "default" execution environment for it. This can be done | |
|
9 | + # seamlessly by using TestRequest#name_of when retrieving the name | |
|
10 | + # of the problem: name_of would return problem.name when | |
|
11 | + # problem!=nil and it would return "default" when problem=nil. | |
|
12 | + # | |
|
13 | + | |
|
1 | 14 | require 'fileutils' |
|
2 | 15 | |
|
3 | 16 | class TestRequest < Task |
|
4 | 17 | |
|
5 | 18 | set_table_name "test_requests" |
|
6 | 19 | |
|
7 | 20 | belongs_to :user |
|
8 | 21 | belongs_to :problem |
|
9 | 22 | belongs_to :submission |
|
10 | 23 | |
|
11 | 24 | def self.get_inqueue_and_change_status(status) |
|
12 | 25 | # since there will be only one grader grading TestRequest |
@@ -30,27 +43,35 | |||
|
30 | 43 | problem = Problem.find(params[:problem_id]) |
|
31 | 44 | test_request.problem = problem |
|
32 | 45 | test_request.submission = |
|
33 | 46 | Submission.find_by_user_problem_number(user.id, |
|
34 | 47 | problem.id, |
|
35 | 48 | params[:submission_number]) |
|
36 | 49 | test_request.input_file_name = save_input_file(params[:input_file], user, problem) |
|
37 | 50 | test_request.submitted_at = Time.new |
|
38 | 51 | test_request.status_inqueue |
|
39 | 52 | test_request |
|
40 | 53 | end |
|
41 | 54 | |
|
55 | + def self.name_of(problem) | |
|
56 | + if problem!=nil | |
|
57 | + problem.name | |
|
58 | + else | |
|
59 | + "default" | |
|
60 | + end | |
|
61 | + end | |
|
62 | + | |
|
42 | 63 | protected |
|
43 | 64 | def self.input_file_name(user,problem) |
|
44 | - problem_name = (problem!=nil) ? problem.name : "" | |
|
65 | + problem_name = TestRequest.name_of(problem) | |
|
45 | 66 | begin |
|
46 | 67 | tmpname = TEST_REQUEST_INPUT_FILE_DIR + "/#{user.login}/#{problem_name}/#{rand(10000)}" |
|
47 | 68 | end while File.exists?(tmpname) |
|
48 | 69 | tmpname |
|
49 | 70 | end |
|
50 | 71 | |
|
51 | 72 | def self.save_input_file(tempfile, user, problem) |
|
52 | 73 | new_file_name = input_file_name(user,problem) |
|
53 | 74 | dirname = File.dirname(new_file_name) |
|
54 | 75 | FileUtils.mkdir_p(File.dirname(new_file_name)) if !File.exists?(dirname) |
|
55 | 76 | if tempfile.instance_of?(Tempfile) |
|
56 | 77 | tempfile.close |
You need to be logged in to leave comments.
Login now