Sha256: 3c350b952b727b0e74962c797d0b06dc3057bee5114a3230f7990ccd13c15d20

Contents?: true

Size: 1.23 KB

Versions: 37

Compression:

Stored size: 1.23 KB

Contents

class Mumuki::Domain::Submission::Base
  include ActiveModel::Model

  required :try_evaluate!

  demodulized_model_name

  ATTRIBUTES = [:solution, :status, :result, :expectation_results, :feedback, :test_results,
                :submission_id, :queries, :query_results, :manual_evaluation_comment]

  attr_accessor *ATTRIBUTES

  def self.from_attributes(*args)
    new ATTRIBUTES.zip(args).to_h
  end

  def self.mapping_attributes
    ATTRIBUTES
  end

  def run!(assignment, evaluation)
    save_submission! assignment
    results = evaluation.evaluate! assignment, self
    save_results! results, assignment
    notify_results! results, assignment
    results
  end

  def evaluate!(assignment)
    try_evaluate! assignment
  rescue => e
    Rails.logger.error "Evaluation failed: #{e} \n#{e.backtrace.join("\n")}"
    {status: :errored, result: e.message}
  end

  def id
    @id ||= SecureRandom.hex(8)
  end

  private

  def save_submission!(assignment)
    assignment.content = content
    assignment.save!
  end

  def save_results!(results, assignment)
    assignment.assign_attributes results
    assignment.increment_attempts!
    assignment.save! results
  end

  def notify_results!(results, assignment)
    assignment.notify!
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
mumuki-domain-7.2.1 lib/mumuki/domain/submission/base.rb
mumuki-domain-7.2.0 lib/mumuki/domain/submission/base.rb
mumuki-laboratory-7.1.0 vendor/bundle/ruby/2.3.0/bundler/gems/mumuki-domain-925adf85cca8/lib/mumuki/domain/submission/base.rb
mumuki-domain-7.1.0 lib/mumuki/domain/submission/base.rb
mumuki-laboratory-7.0.12 vendor/bundle/ruby/2.3.0/bundler/gems/mumuki-domain-74da3d4af98c/lib/mumuki/domain/submission/base.rb
mumuki-domain-7.0.6 lib/mumuki/domain/submission/base.rb
mumuki-domain-7.0.5 lib/mumuki/domain/submission/base.rb
mumuki-domain-7.0.4 lib/mumuki/domain/submission/base.rb
mumuki-domain-7.0.3 lib/mumuki/domain/submission/base.rb
mumuki-laboratory-7.0.11 vendor/bundle/ruby/2.3.0/bundler/gems/mumuki-domain-f892f79c60f0/lib/mumuki/domain/submission/base.rb
mumuki-domain-7.0.2 lib/mumuki/domain/submission/base.rb
mumuki-domain-7.0.1 lib/mumuki/domain/submission/base.rb
mumuki-domain-7.0.0 lib/mumuki/domain/submission/base.rb
mumuki-domain-6.7.2 lib/mumuki/domain/submission/base.rb
mumuki-domain-6.7.1 lib/mumuki/domain/submission/base.rb
mumuki-domain-6.7.0 lib/mumuki/domain/submission/base.rb
mumuki-domain-6.6.2 lib/mumuki/domain/submission/base.rb
mumuki-domain-6.6.1 lib/mumuki/domain/submission/base.rb
mumuki-domain-6.6.0 lib/mumuki/domain/submission/base.rb
mumuki-domain-6.5.1 lib/mumuki/domain/submission/base.rb