Show More
Commit Description:
add model solution
Commit Description:
add model solution
File last commit:
Show/Diff file:
Action:
app/models/submission.rb | 170 lines | 4.9 KiB | text/x-ruby | RubyLexer |
pramook
initial commit...
r0 class Submission < ActiveRecord::Base
add model solution
r854 enum tag: {default: 0, model: 1}, _prefix: true
pramook
initial commit...
r0 belongs_to :language
belongs_to :problem
jittat
moved to ror 2.0.2, add user rel to model submission...
r1 belongs_to :user
pramook
initial commit...
r0
jittat
[web] added support for output only problems...
r99 before_validation :assign_problem
before_validation :assign_language
jittat
moved submission validation to model...
r31 validates_presence_of :source
resize submissions.source field from "TEXT" to "MEDIUMTEXT"
r712 validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'code too long, the limit is 100,000 bytes'
jittat
moved submission validation to model...
r31 validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short'
jittat
[web] added support for output only problems...
r99 validate :must_have_valid_problem
jittat
moved submission validation to model...
r31 validate :must_specify_language
add rejudge button
r645 has_one :task
jittat
fixed bug: increament of number on old records in submission...
r46 before_save :assign_latest_number_if_new_recond
jittat
added number (auto generated when submitting) to submissions...
r35
def self.find_last_by_user_and_problem(user_id, problem_id)
change find(:xxx) to correct syntax for rails 4
r619 where("user_id = ? AND problem_id = ?",user_id,problem_id).last
pramook
initial commit...
r0 end
jittat
added number (auto generated when submitting) to submissions...
r35 def self.find_all_last_by_problem(problem_id)
pramook
initial commit...
r0 # need to put in SQL command, maybe there's a better way
update problem stat to show all submissions...
r448 Submission.includes(:user).find_by_sql("SELECT * FROM submissions " +
add model solution
r854 "WHERE id = " +
"(SELECT MAX(id) FROM submissions AS subs " +
"WHERE subs.user_id = submissions.user_id AND " +
"problem_id = " + problem_id.to_s + " " +
"GROUP BY user_id) " +
"ORDER BY user_id")
pramook
initial commit...
r0 end
add feature check maximum score in submission ranges...
r350 def self.find_in_range_by_user_and_problem(user_id, problem_id,since_id,until_id)
records = Submission.where(problem_id: problem_id,user_id: user_id)
- after submission, redirecto to edit_submission_path...
r696 records = records.where('id >= ?',since_id) if since_id and since_id > 0
records = records.where('id <= ?',until_id) if until_id and until_id > 0
add feature check maximum score in submission ranges...
r350 records.all
end
jittat
test interface upload...
r36 def self.find_last_for_all_available_problems(user_id)
submissions = Array.new
change find(:xxx) to correct syntax for rails 4
r619 problems = Problem.available_problems
jittat
test interface upload...
r36 problems.each do |problem|
sub = Submission.find_last_by_user_and_problem(user_id, problem.id)
submissions << sub if sub!=nil
end
submissions
end
def self.find_by_user_problem_number(user_id, problem_id, number)
change find(:xxx) to correct syntax for rails 4
r619 where("user_id = ? AND problem_id = ? AND number = ?",user_id,problem_id,number).first
jittat
test interface upload...
r36 end
jittat
update views -- styling...
r51 def self.find_all_by_user_problem(user_id, problem_id)
change find(:xxx) to correct syntax for rails 4
r619 where("user_id = ? AND problem_id = ?",user_id,problem_id)
jittat
update views -- styling...
r51 end
jittat
added timestamp to source download...
r168 def download_filename
if self.problem.output_only
return self.source_filename
else
timestamp = self.submitted_at.localtime.strftime("%H%M%S")
return "#{self.problem.name}-#{timestamp}.#{self.language.ext}"
end
end
jittat
added number (auto generated when submitting) to submissions...
r35 protected
pramook
initial commit...
r0 def self.find_option_in_source(option, source)
jittat
moved submission validation to model...
r31 if source==nil
return nil
end
pramook
initial commit...
r0 i = 0
source.each_line do |s|
if s =~ option
add model solution
r854 words = s.split
return words[1]
pramook
initial commit...
r0 end
i = i + 1
if i==10
add model solution
r854 return nil
pramook
initial commit...
r0 end
end
return nil
end
jittat
added language identification using file extension...
r166 def self.find_language_in_source(source, source_filename="")
pramook
initial commit...
r0 langopt = find_option_in_source(/^LANG:/,source)
jittat
added language identification using file extension...
r166 if langopt
return (Language.find_by_name(langopt) ||
Language.find_by_pretty_name(langopt))
pramook
initial commit...
r0 else
jittat
added language identification using file extension...
r166 if source_filename
return Language.find_by_extension(source_filename.split('.').last)
else
return nil
end
pramook
initial commit...
r0 end
end
jittat
added problem identification from source filename...
r167 def self.find_problem_in_source(source, source_filename="")
pramook
initial commit...
r0 prob_opt = find_option_in_source(/^TASK:/,source)
if problem = Problem.find_by_name(prob_opt)
return problem
else
jittat
added problem identification from source filename...
r167 if source_filename
return Problem.find_by_name(source_filename.split('.').first)
else
return nil
end
pramook
initial commit...
r0 end
end
jittat
[web] added support for output only problems...
r99 def assign_problem
if self.problem_id!=-1
begin
self.problem = Problem.find(self.problem_id)
rescue ActiveRecord::RecordNotFound
self.problem = nil
end
else
jittat
added problem identification from source filename...
r167 self.problem = Submission.find_problem_in_source(self.source,
self.source_filename)
jittat
[web] added support for output only problems...
r99 end
end
def assign_language
Jittat Fakcharoenphol
prevents submission language assignment when already specified
r773 if self.language == nil
self.language = Submission.find_language_in_source(self.source,
self.source_filename)
end
jittat
[web] added support for output only problems...
r99 end
jittat
moved submission validation to model...
r31 # validation codes
def must_specify_language
return if self.source==nil
jittat
[web] added support for output only problems...
r99
# for output_only tasks
return if self.problem!=nil and self.problem.output_only
fix allow admin to submit to any problem
r682
Jittat Fakcharoenphol
prevents submission language assignment when already specified
r773 if self.language == nil
errors.add('source',"Cannot detect language. Did you submit a correct source file?")
jittat
[web] added support for output only problems...
r99 end
jittat
moved submission validation to model...
r31 end
def must_have_valid_problem
return if self.source==nil
jittat
[web] added support for output only problems...
r99 if self.problem==nil
jittat
[web] add validations to test_request and submission...
r87 errors.add('problem',"must be specified.")
fix allow admin to submit to any problem
r682 else
#admin always have right
return if self.user.admin?
#check if user has the right to submit the problem
fix error message when submission to closed problem
r797 errors[:base] << "Authorization error: you have no right to submit to this problem" if (!self.user.available_problems.include?(self.problem)) and (self.new_record?)
jittat
moved submission validation to model...
r31 end
end
jittat
added number (auto generated when submitting) to submissions...
r35 # callbacks
jittat
fixed bug: increament of number on old records in submission...
r46 def assign_latest_number_if_new_recond
return if !self.new_record?
jittat
added number (auto generated when submitting) to submissions...
r35 latest = Submission.find_last_by_user_and_problem(self.user_id, self.problem_id)
self.number = (latest==nil) ? 1 : latest.number + 1;
end
pramook
initial commit...
r0 end