Description:
added problem identification from source filename
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@364 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
r167:e09937aa9f90 - - 1 file changed: 8 inserted, 3 deleted
@@ -74,66 +74,71 | |||
|
74 | 74 | return words[1] |
|
75 | 75 | end |
|
76 | 76 | i = i + 1 |
|
77 | 77 | if i==10 |
|
78 | 78 | return nil |
|
79 | 79 | end |
|
80 | 80 | end |
|
81 | 81 | return nil |
|
82 | 82 | end |
|
83 | 83 | |
|
84 | 84 | def self.find_language_in_source(source, source_filename="") |
|
85 | 85 | langopt = find_option_in_source(/^LANG:/,source) |
|
86 | 86 | if langopt |
|
87 | 87 | return (Language.find_by_name(langopt) || |
|
88 | 88 | Language.find_by_pretty_name(langopt)) |
|
89 | 89 | else |
|
90 | 90 | if source_filename |
|
91 | 91 | return Language.find_by_extension(source_filename.split('.').last) |
|
92 | 92 | else |
|
93 | 93 | return nil |
|
94 | 94 | end |
|
95 | 95 | end |
|
96 | 96 | end |
|
97 | 97 | |
|
98 | - def self.find_problem_in_source(source) | |
|
98 | + def self.find_problem_in_source(source, source_filename="") | |
|
99 | 99 | prob_opt = find_option_in_source(/^TASK:/,source) |
|
100 | 100 | if problem = Problem.find_by_name(prob_opt) |
|
101 | 101 | return problem |
|
102 | 102 | else |
|
103 | - return nil | |
|
103 | + if source_filename | |
|
104 | + return Problem.find_by_name(source_filename.split('.').first) | |
|
105 | + else | |
|
106 | + return nil | |
|
107 | + end | |
|
104 | 108 | end |
|
105 | 109 | end |
|
106 | 110 | |
|
107 | 111 | def assign_problem |
|
108 | 112 | if self.problem_id!=-1 |
|
109 | 113 | begin |
|
110 | 114 | self.problem = Problem.find(self.problem_id) |
|
111 | 115 | rescue ActiveRecord::RecordNotFound |
|
112 | 116 | self.problem = nil |
|
113 | 117 | end |
|
114 | 118 | else |
|
115 |
- self.problem = Submission.find_problem_in_source(self.source |
|
|
119 | + self.problem = Submission.find_problem_in_source(self.source, | |
|
120 | + self.source_filename) | |
|
116 | 121 | end |
|
117 | 122 | end |
|
118 | 123 | |
|
119 | 124 | def assign_language |
|
120 | 125 | self.language = Submission.find_language_in_source(self.source, |
|
121 | 126 | self.source_filename) |
|
122 | 127 | end |
|
123 | 128 | |
|
124 | 129 | # validation codes |
|
125 | 130 | def must_specify_language |
|
126 | 131 | return if self.source==nil |
|
127 | 132 | |
|
128 | 133 | # for output_only tasks |
|
129 | 134 | return if self.problem!=nil and self.problem.output_only |
|
130 | 135 | |
|
131 | 136 | if self.language==nil |
|
132 | 137 | errors.add('source',"must specify programming language") unless self.language!=nil |
|
133 | 138 | end |
|
134 | 139 | end |
|
135 | 140 | |
|
136 | 141 | def must_have_valid_problem |
|
137 | 142 | return if self.source==nil |
|
138 | 143 | if self.problem==nil |
|
139 | 144 | errors.add('problem',"must be specified.") |
You need to be logged in to leave comments.
Login now