test_result_calculation 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/test_result_calculation.rb +5 -0
- data/lib/test_result_calculation/count_result.rb +55 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5b6a08b06d6d0a1acf275f307fe6d661f44978a2
|
4
|
+
data.tar.gz: 8a7c94fad389a41e6c9a315faefebe1fc9a9c5da
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2e01fa59ca75dabc722a9def9e90ccf146515827964feb83801e2aa08c1f9203333ed4eb5a559b0f7c062c585b63a47c2a1ee89327c6110af957a978968ba5bc
|
7
|
+
data.tar.gz: 34ec59e84ed5ce47f6a593fb9d02352c15dbda1dcd9cd890db8ef02a7c4018ab482af47e7f70946cb05fcf9f83ae40ed92b55c22124a36634049b315208c9574
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module TestResultCalculation
|
2
|
+
module CountResult
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
module LocalInstanceMethods
|
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
|
39
|
+
all_questions = self.test_setting.questions
|
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)
|
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
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
ActiveRecord::Base.include(TestResultCalculation::CountResult)
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: test_result_calculation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- zdubzdab
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: The simplest gem that calculate test result in percent. Add 'include
|
14
|
+
TestResultCalculation::CountResult::LocalInstanceMethods' and 'after_create :count_and_paste_test_result_into_test_table'
|
15
|
+
to test model
|
16
|
+
email: zdubzdab@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/test_result_calculation.rb
|
22
|
+
- lib/test_result_calculation/count_result.rb
|
23
|
+
homepage: http://rubygems.org/gems/test_result_calculation
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.3.0
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: Calculate test result
|
47
|
+
test_files: []
|