module TestResultCalculation::CountResult::LocalInstanceMethods
Public Instance Methods
count_and_paste_test_result()
click to toggle source
# File lib/test_result_calculation/count_result.rb, line 38 def count_and_paste_test_result all_questions = self.test_setting.questions test_result = Float(pull_true_answers_from_questions_with_one_answer) / (all_questions.count.nonzero? || 1) * 100 self.update_attributes(complete_pers: test_result) end
count_and_paste_test_result_into_test_table()
click to toggle source
# File lib/test_result_calculation/count_result.rb, line 12 def count_and_paste_test_result_into_test_table create_hash_with_key_question_id_and_value_number_of_answers create_array_with_question_id_that_has_true_answ pull_true_answers_from_questions_with_one_answer count_and_paste_test_result end
create_array_with_question_id_that_has_true_answ()
click to toggle source
# File lib/test_result_calculation/count_result.rb, line 28 def create_array_with_question_id_that_has_true_answ true_answers.map{ |t_a| t_a.question_id } end
create_hash_with_key_question_id_and_value_number_of_answers()
click to toggle source
# File lib/test_result_calculation/count_result.rb, line 19 def create_hash_with_key_question_id_and_value_number_of_answers test_answers = self.answers .where( answers: {checked: 'true'} ) .group_by(&:question_id) array_with_question_id_and_answers_number = test_answers.map {|k,v| [k, v.length]}.flatten hash_with_question_id_and_answers_number = Hash[*array_with_question_id_and_answers_number] hash_with_question_id_and_answers_number.select {|k,v| v > 1} end
pull_true_answers_from_questions_with_one_answer()
click to toggle source
# File lib/test_result_calculation/count_result.rb, line 32 def pull_true_answers_from_questions_with_one_answer array_with_number_of_tries_bigger_1 = create_hash_with_key_question_id_and_value_number_of_answers.map {|k,v| k} array_with_number_common_elements = array_with_number_of_tries_bigger_1 & create_array_with_question_id_that_has_true_answ true_answers.count - array_with_number_common_elements.size end
Private Instance Methods
true_answers()
click to toggle source
# File lib/test_result_calculation/count_result.rb, line 45 def true_answers @true_answers ||= Answer.belongs_to_current_test(self.id) .with_true .joins(:answer_setting) .where( answer_settings: {rigth: 'true'} ) end