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:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r39:7df73373290b - - 1 file changed: 22 inserted, 1 deleted

@@ -1,6 +1,19
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 require 'fileutils'
14 require 'fileutils'
2
15
3 class TestRequest < Task
16 class TestRequest < Task
4
17
5 set_table_name "test_requests"
18 set_table_name "test_requests"
6
19
@@ -36,15 +49,23
36 test_request.input_file_name = save_input_file(params[:input_file], user, problem)
49 test_request.input_file_name = save_input_file(params[:input_file], user, problem)
37 test_request.submitted_at = Time.new
50 test_request.submitted_at = Time.new
38 test_request.status_inqueue
51 test_request.status_inqueue
39 test_request
52 test_request
40 end
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 protected
63 protected
43 def self.input_file_name(user,problem)
64 def self.input_file_name(user,problem)
44 - problem_name = (problem!=nil) ? problem.name : ""
65 + problem_name = TestRequest.name_of(problem)
45 begin
66 begin
46 tmpname = TEST_REQUEST_INPUT_FILE_DIR + "/#{user.login}/#{problem_name}/#{rand(10000)}"
67 tmpname = TEST_REQUEST_INPUT_FILE_DIR + "/#{user.login}/#{problem_name}/#{rand(10000)}"
47 end while File.exists?(tmpname)
68 end while File.exists?(tmpname)
48 tmpname
69 tmpname
49 end
70 end
50
71
You need to be logged in to leave comments. Login now