Module: TestResultCalculation::CountResult::LocalInstanceMethods
- Defined in:
- lib/test_result_calculation/count_result.rb
Instance Method Summary collapse
- #count_and_paste_test_result ⇒ Object
- #count_and_paste_test_result_into_test_table ⇒ Object
- #create_array_with_question_id_that_has_true_answ ⇒ Object
- #create_hash_with_key_question_id_and_value_number_of_answers ⇒ Object
- #pull_true_answers_from_questions_with_one_answer ⇒ Object
Instance Method Details
#count_and_paste_test_result ⇒ Object
38 39 40 41 42 |
# 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 ⇒ Object
12 13 14 15 16 17 |
# 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 ⇒ Object
28 29 30 |
# 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 ⇒ Object
19 20 21 22 23 24 25 26 |
# 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 ⇒ Object
32 33 34 35 36 |
# 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 |