parent
7dc99a9598
commit
83993dc99d
@ -0,0 +1,3 @@
|
|||||||
|
class ExerciseQuestionAnalysis < ApplicationRecord
|
||||||
|
belongs_to :exercise_question
|
||||||
|
end
|
@ -0,0 +1,63 @@
|
|||||||
|
class ExaminationBanks::SendToCourseService < ApplicationService
|
||||||
|
attr_reader :exam, :exercise
|
||||||
|
|
||||||
|
def initialize(exam, exercise)
|
||||||
|
@exam = exam
|
||||||
|
@exercise = exercise
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
exercise.exercise_name = exam.name
|
||||||
|
exercise.time = exam.duration.present? ? exam.duration : -1
|
||||||
|
exercise.save!
|
||||||
|
|
||||||
|
exam.examination_items.each_with_index do |item, index|
|
||||||
|
question = exercise.exercise_questions.new
|
||||||
|
question.question_type = question_type item.item_type
|
||||||
|
question.question_title = item.name
|
||||||
|
question.question_number = index + 1
|
||||||
|
question.question_score = item.score
|
||||||
|
question.is_md = false
|
||||||
|
|
||||||
|
if item.item_type == "PROGRAM"
|
||||||
|
new_hack = item.container.fork
|
||||||
|
question.hack_id = new_hack.id
|
||||||
|
question.save!
|
||||||
|
else
|
||||||
|
question.save!
|
||||||
|
ExerciseQuestionAnalysis.new(analysis: item.analysis, exercise_question_id: question.id)
|
||||||
|
item.item_choices.each_with_index do |choice, position|
|
||||||
|
question.exercise_choices << ExerciseChoice.new(choice_text: choice.choice_text, choice_position: position+1)
|
||||||
|
if choice.is_answer
|
||||||
|
question.exercise_standard_answers << ExerciseStandardAnswer.new(exercise_choice_id: position+1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
exam.increment!(:quotes)
|
||||||
|
end
|
||||||
|
exercise
|
||||||
|
end
|
||||||
|
|
||||||
|
def question_type item_type
|
||||||
|
question_type = case item_type
|
||||||
|
when 'SINGLE'
|
||||||
|
Exercise::SINGLE
|
||||||
|
when 'MULTIPLE'
|
||||||
|
Exercise::MULTIPLE
|
||||||
|
when 'JUDGMENT'
|
||||||
|
Exercise::JUDGMENT
|
||||||
|
when 'COMPLETION'
|
||||||
|
Exercise::COMPLETION
|
||||||
|
when 'SUBJECTIVE'
|
||||||
|
Exercise::SUBJECTIVE
|
||||||
|
when 'PRACTICAL'
|
||||||
|
Exercise::PRACTICAL
|
||||||
|
when 'PROGRAM'
|
||||||
|
Exercise::PROGRAM
|
||||||
|
end
|
||||||
|
question_type
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,5 @@
|
|||||||
|
class AddHackIdToExerciseQuestions < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :exercise_questions, :hack_id, :integer, default: 0
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,10 @@
|
|||||||
|
class CreateExerciseQuestionAnalyses < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :exercise_question_analyses do |t|
|
||||||
|
t.text :analysis
|
||||||
|
t.references :exercise_question, index: true, unique: true
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,5 @@
|
|||||||
|
class AddExaminationBankIdToExercise < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :exercises, :examination_bank_id, :integer, default: 0
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,5 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe ExerciseQuestionAnalysis, type: :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Loading…
Reference in new issue