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 +4 -4
- data/lib/zdubzdab_hola/count_result.rb +37 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94cbbd9d187f2a21df9f8239568453f1b15dc479
|
4
|
+
data.tar.gz: 48ab0f3aa73e9d3112b1dbfb68dbae1b8be08bfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
18
|
-
self.update_attributes(complete_pers:
|
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
|