Merge remote-tracking branch 'origin/master' into exercise-anomaly-detection
# Conflicts: # Capfile # Gemfile.lock # db/schema.rb
This commit is contained in:
@ -47,7 +47,7 @@ class ExecutionEnvironment < ActiveRecord::Base
|
||||
private :validate_docker_image?
|
||||
|
||||
def working_docker_image?
|
||||
DockerClient.pull(docker_image) unless DockerClient.image_tags.include?(docker_image)
|
||||
DockerClient.pull(docker_image) unless DockerClient.find_image_by_tag(docker_image).blank?
|
||||
output = DockerClient.new(execution_environment: self).execute_arbitrary_command(VALIDATION_COMMAND)
|
||||
errors.add(:docker_image, "error: #{output[:stderr]}") if output[:stderr].present?
|
||||
rescue DockerClient::Error => error
|
||||
|
@ -10,7 +10,13 @@ class RequestForComment < ActiveRecord::Base
|
||||
scope :unsolved, -> { where(solved: [false, nil]) }
|
||||
|
||||
def self.last_per_user(n = 5)
|
||||
from("(#{row_number_user_sql}) as request_for_comments").where("row_number <= ?", n)
|
||||
from("(#{row_number_user_sql}) as request_for_comments")
|
||||
.where("row_number <= ?", n)
|
||||
.group('request_for_comments.id, request_for_comments.user_id, request_for_comments.exercise_id,
|
||||
request_for_comments.file_id, request_for_comments.question, request_for_comments.created_at,
|
||||
request_for_comments.updated_at, request_for_comments.user_type, request_for_comments.solved,
|
||||
request_for_comments.full_score_reached, request_for_comments.submission_id, request_for_comments.row_number')
|
||||
# ugly, but necessary
|
||||
end
|
||||
|
||||
# not used right now, finds the last submission for the respective user and exercise.
|
||||
@ -46,12 +52,20 @@ class RequestForComment < ActiveRecord::Base
|
||||
commenters.uniq {|user| user.id}
|
||||
end
|
||||
|
||||
def self.with_last_activity
|
||||
self.joins('join "submissions" s on s.id = request_for_comments.submission_id
|
||||
left outer join "files" f on f.context_id = s.id
|
||||
left outer join "comments" c on c.file_id = f.id')
|
||||
.group('request_for_comments.id')
|
||||
.select('request_for_comments.*, max(c.updated_at) as last_comment')
|
||||
end
|
||||
|
||||
def to_s
|
||||
"RFC-" + self.id.to_s
|
||||
end
|
||||
|
||||
private
|
||||
def self.row_number_user_sql
|
||||
select("id, user_id, exercise_id, file_id, question, created_at, updated_at, user_type, solved, submission_id, row_number() OVER (PARTITION BY user_id ORDER BY created_at DESC) as row_number").to_sql
|
||||
select("id, user_id, exercise_id, file_id, question, created_at, updated_at, user_type, solved, full_score_reached, submission_id, row_number() OVER (PARTITION BY user_id ORDER BY created_at DESC) as row_number").to_sql
|
||||
end
|
||||
end
|
||||
|
@ -1,9 +1,10 @@
|
||||
class StructuredError < ActiveRecord::Base
|
||||
belongs_to :error_template
|
||||
belongs_to :submission
|
||||
belongs_to :file, class_name: 'CodeOcean::File'
|
||||
|
||||
def self.create_from_template(template, message_buffer)
|
||||
instance = self.create(error_template: template)
|
||||
def self.create_from_template(template, message_buffer, submission)
|
||||
instance = self.create(error_template: template, submission: submission)
|
||||
template.error_template_attributes.each do |attribute|
|
||||
StructuredErrorAttribute.create_from_template(attribute, instance, message_buffer)
|
||||
end
|
||||
|
@ -3,15 +3,13 @@ class StructuredErrorAttribute < ActiveRecord::Base
|
||||
belongs_to :error_template_attribute
|
||||
|
||||
def self.create_from_template(attribute, structured_error, message_buffer)
|
||||
match = false
|
||||
value = nil
|
||||
result = message_buffer.match(attribute.regex)
|
||||
if result != nil
|
||||
match = true
|
||||
if result.captures.size > 0
|
||||
value = result.captures[0]
|
||||
end
|
||||
end
|
||||
self.create(structured_error: structured_error, error_template_attribute: attribute, value: value, match: match)
|
||||
self.create(structured_error: structured_error, error_template_attribute: attribute, value: value, match: result != nil)
|
||||
end
|
||||
end
|
||||
|
@ -8,6 +8,7 @@ class Submission < ActiveRecord::Base
|
||||
belongs_to :exercise
|
||||
|
||||
has_many :testruns
|
||||
has_many :structured_errors
|
||||
has_many :comments, through: :files
|
||||
|
||||
delegate :execution_environment, to: :exercise
|
||||
|
Reference in New Issue
Block a user