Show More
Commit Description:
small refactoring in Problem.new_from_import_form_params...
Commit Description:
small refactoring in Problem.new_from_import_form_params git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@439 6386c4cd-e34a-4fa8-8920-d93eb39b512e
File last commit:
Show/Diff file:
Action:
app/models/problem.rb | 93 lines | 2.4 KiB | text/x-ruby | RubyLexer |
pramook
initial commit...
r0 class Problem < ActiveRecord::Base
jittat
[web] refactor problem description, some styling...
r92 belongs_to :description
jittat
added quick new problem...
r171 validates_presence_of :name
jittat
import problem replaced old one, fixed small problems...
r205 validates_format_of :name, :with => /^\w+$/
jittat
added quick new problem...
r171 validates_presence_of :full_name
jittat
small refactoring in Problem.new_from_import_form_params...
r208
DEFAULT_TIME_LIMIT = 1
DEFAULT_MEMORY_LIMIT = 32
jittat
import problem replaced old one, fixed small problems...
r205
pramook
initial commit...
r0 def self.find_available_problems
jittat
fixed msg grammar...
r154 find(:all, :conditions => {:available => true}, :order => "date_added DESC")
pramook
initial commit...
r0 end
jittat
added problem import...
r204 def self.new_from_import_form_params(params)
problem = Problem.new
jittat
small refactoring in Problem.new_from_import_form_params...
r208 import_params = Problem.extract_params_and_check(params, problem)
jittat
added problem import...
r204
jittat
small refactoring in Problem.new_from_import_form_params...
r208 if not problem.valid?
return problem
end
jittat
added problem import...
r204
jittat
small refactoring in Problem.new_from_import_form_params...
r208 importer = TestdataImporter.new
if not importer.import_from_file(problem.name,
import_params[:file],
import_params[:time_limit],
import_params[:memory_limit])
problem.errors.add_to_base('Import error.')
end
jittat
added problem import...
r204
jittat
small refactoring in Problem.new_from_import_form_params...
r208 problem.full_score = 100
problem.date_added = Time.new
problem.test_allowed = true
problem.output_only = false
problem.available = false
return problem, importer.log_msg
end
protected
jittat
added problem import...
r204
jittat
small refactoring in Problem.new_from_import_form_params...
r208 def self.to_i_or_default(st, default)
if st!=''
st.to_i
else
default
end
end
def self.extract_params_and_check(params, problem)
time_limit = Problem.to_i_or_default(params[:time_limit],
DEFAULT_TIME_LIMIT)
memory_limit = Problem.to_i_or_default(params[:memory_limit],
DEFAULT_MEMORY_LIMIT)
jittat
added problem import...
r204
if time_limit==0 and time_limit_s!='0'
problem.errors.add_to_base('Time limit format errors.')
elsif time_limit<=0 or time_limit >60
problem.errors.add_to_base('Time limit out of range.')
end
if memory_limit==0 and memory_limit_s!='0'
problem.errors.add_to_base('Memory limit format errors.')
elsif memory_limit<=0 or memory_limit >512
problem.errors.add_to_base('Memory limit out of range.')
end
if params[:file]==nil or params[:file]==''
problem.errors.add_to_base('No testdata file.')
end
file = params[:file]
if problem.errors.length!=0
return problem
end
problem.name = params[:name]
if params[:full_name]!=''
problem.full_name = params[:full_name]
else
problem.full_name = params[:name]
end
jittat
small refactoring in Problem.new_from_import_form_params...
r208 return {
:time_limit => time_limit,
:memory_limit => memory_limit,
:file => file
}
jittat
added problem import...
r204 end
pramook
initial commit...
r0 end