zdubzdab_hola 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 702dca3a3b04c6c4a689188cb8b5b1a555f31a28
4
- data.tar.gz: 65bc03bec2c4ba3979162aa8a963f42c7c9525b7
3
+ metadata.gz: 94cbbd9d187f2a21df9f8239568453f1b15dc479
4
+ data.tar.gz: 48ab0f3aa73e9d3112b1dbfb68dbae1b8be08bfd
5
5
  SHA512:
6
- metadata.gz: b9f390f9aa8d1b4cf34d75d5940a8f407d8424eb5b5013aa525c9a89daa531a186c5069b92ca6f72e6cdd6c240137212db7527d67344bf357c6631a5ac363969
7
- data.tar.gz: 49eb324e1b59af9b3b4d46ba493250a8c4fbe224c606b19de01af23f4045963a32d79c2fe31d4cd20b95c1a9f20fcbf5b5ad95a4f56095e0d426ded07baacf4a
6
+ metadata.gz: e026f5c1c1253e8852cfb2fdfe21cc8926229463d636393ccaaff4f77ae216f515bd411831ff80841a2af4ec3068953fdde89dcc2797410903dddb435e02f5ba
7
+ data.tar.gz: f07b081a9507ce5b080128d6299634916cdfece878fc5ac20d5fce4db86924879f939c2c7eada9138fbbc6af2fb62ca2f8245547716c86b4626eacffc6f04c32
@@ -9,14 +9,45 @@ module ZdubzdabHola
9
9
  end
10
10
 
11
11
  module LocalInstanceMethods
12
- def count_result
13
- true_answers = Answer.belongs_to_current_test(self.id)
14
- .with_true.joins(:answer_setting)
15
- .where( answer_settings: {rigth: 'true'} )
12
+ def count_and_paste_test_result_into_test_table
13
+ create_hash_with_key_question_id_and_value_number_of_answers
14
+ create_array_with_question_id_that_has_true_answ
15
+ pull_true_answers_from_questions_with_one_answer
16
+ count_and_paste_test_result
17
+ end
18
+
19
+ def create_hash_with_key_question_id_and_value_number_of_answers
20
+ test_answers = self.answers
21
+ .where( answers: {checked: 'true'} )
22
+ .group_by(&:question_id)
23
+ array_with_question_id_and_answers_number = test_answers.map {|k,v| [k, v.length]}.flatten
24
+ hash_with_question_id_and_answers_number = Hash[*array_with_question_id_and_answers_number]
25
+ hash_with_question_id_and_answers_number.select {|k,v| v > 1}
26
+ end
27
+
28
+ def create_array_with_question_id_that_has_true_answ
29
+ true_answers.map{ |t_a| t_a.question_id }
30
+ end
31
+
32
+ def pull_true_answers_from_questions_with_one_answer
33
+ array_with_number_of_tries_bigger_1 = create_hash_with_key_question_id_and_value_number_of_answers.map {|k,v| k}
34
+ array_with_number_common_elements = array_with_number_of_tries_bigger_1 & create_array_with_question_id_that_has_true_answ
35
+ true_answers.count - array_with_number_common_elements.size
36
+ end
37
+
38
+ def count_and_paste_test_result
16
39
  all_questions = self.test_setting.questions
17
- result = Float(true_answers.count) / (all_questions.count.nonzero? || 1) * 100
18
- self.update_attributes(complete_pers: result)
40
+ test_result = Float(pull_true_answers_from_questions_with_one_answer) / (all_questions.count.nonzero? || 1) * 100
41
+ self.update_attributes(complete_pers: test_result)
19
42
  end
43
+
44
+ private
45
+ def true_answers
46
+ @true_answers ||= Answer.belongs_to_current_test(self.id)
47
+ .with_true
48
+ .joins(:answer_setting)
49
+ .where( answer_settings: {rigth: 'true'} )
50
+ end
20
51
  end
21
52
  end
22
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zdubzdab_hola
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - zdubzdab