ae_easy-qa 0.0.21 → 0.0.22

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
  SHA256:
3
- metadata.gz: b37b9eefd295fd1816c02b906a56eeb0ed2d0a8108c3e93992e4953f36786387
4
- data.tar.gz: f8e58457cf18340e6879d088e94031cdc869c05866324474a68465b9aa9318f7
3
+ metadata.gz: 0b72afb2dc8f9f4fa1511094aafff7f9a41eb21004e73a22a3428c528b5625d1
4
+ data.tar.gz: 48c731914135716f47ca59007bc708fd9f8552948f8f56d7db761a911a12f98c
5
5
  SHA512:
6
- metadata.gz: e2ed8e4b43bef024e4543255123a3df6423ffd6a3c3a72d4bb0b440bcc6eb92c86591ddcf9dbccf0ebcc53b42756c0cf6b191ac4ffa9c2f130a3964d47dbda4d
7
- data.tar.gz: 284d9e40adb10130d153a6758714af314e228352e805d6882dbf5acb695cd59ea41692db999305d3c294b93ee3e39f41832b63a9f2c7a05ee1567fb83747d398
6
+ metadata.gz: ca1cf82ef35e66bb1fe09d244a3d36adb4b4c3b58d360d4691a245d122f83034e431a8dfd89d6a9e6281bc9f09fe80f945bc1d7bb7710fccb451aba632e16cfb
7
+ data.tar.gz: f69ac55402c72d9524ea69a6e427c70f3fd7dd18a61b84bbd153dbcfe06b80d21188e5c921ee5bad33c8416eee81c01a571303a862ab4c62154dd588288303cd
@@ -20,7 +20,7 @@ module AeEasy
20
20
 
21
21
  def run
22
22
  gather_threshold_totals
23
- gather_fields_to_ignore
23
+ gather_validations_to_ignore
24
24
  save_group_errors
25
25
  save_errors
26
26
  save_summary
@@ -32,55 +32,77 @@ module AeEasy
32
32
  rules.each{|field_to_validate, field_options|
33
33
  field_threshold = return_threshold(field_to_validate, field_options)
34
34
  if field_threshold
35
+ gather_field_threshold_totals(field_to_validate, field_options)
36
+ else
37
+ gather_specific_validation_totals(field_to_validate, field_options)
38
+ end
39
+ }
40
+ end
41
+
42
+ def gather_field_threshold_totals(field_to_validate, field_options)
43
+ error_total = errors[:errored_items].inject(0){|total, errored_item|
44
+ failed_fields = errored_item[:failures].keys.collect{|failure_key|
45
+ extract_field(failure_key)
46
+ }.uniq
47
+ total += 1 if failed_fields.include?(field_to_validate)
48
+ total
49
+ }
50
+ error_totals[field_to_validate] = error_total
51
+ end
52
+
53
+ def gather_specific_validation_totals(field_to_validate, field_options)
54
+ field_options.each do |validation|
55
+ potential_failure_name = "#{field_to_validate}_#{validation[0]}_fail"
56
+ if options['thresholds'] && options['thresholds'][potential_failure_name]
35
57
  error_total = errors[:errored_items].inject(0){|total, errored_item|
36
- failed_fields = errored_item[:failures].keys.collect{|failure_key|
37
- extract_field(failure_key)
38
- }.uniq
39
- total += 1 if failed_fields.include?(field_to_validate)
58
+ failed_validations = errored_item[:failures].keys.collect{|failure_key|
59
+ "#{failure_key}_fail"
60
+ }
61
+ total += 1 if failed_validations.include?(potential_failure_name)
40
62
  total
41
63
  }
42
- error_totals[field_to_validate] = error_total
43
- else
44
- field_options.each do |validation|
45
- potential_failure_name = "#{field_to_validate}_#{validation[0]}_fail"
46
- if options['thresholds'][potential_failure_name]
47
- error_total = errors[:errored_items].inject(0){|total, errored_item|
48
- failed_validations = errored_item[:failures].keys.collect{|failure_key|
49
- "#{failure_key}_fail"
50
- }
51
- total += 1 if failed_validations.include?(potential_failure_name)
52
- total
53
- }
54
- error_totals[potential_failure_name] = error_total
55
- end
56
- end
64
+ error_totals[potential_failure_name] = error_total
57
65
  end
58
- }
66
+ end
59
67
  end
60
68
 
61
- def gather_fields_to_ignore
69
+ def gather_validations_to_ignore
62
70
  rules.each{|field_to_validate, field_options|
63
71
  field_threshold = return_threshold(field_to_validate, field_options)
64
72
  if field_threshold
65
- total_errors = error_totals[field_to_validate]
66
- if total_errors
67
- success_ratio = (total_items - total_errors).to_f / total_items
68
- fields_to_ignore.push(field_to_validate) if success_ratio > field_threshold
69
- end
73
+ gather_fields_to_ignore(field_to_validate, field_threshold)
70
74
  else
71
- field_options.each do |validation|
72
- potential_failure_name = "#{field_to_validate}_#{validation[0]}_fail"
73
- total_errors = error_totals[potential_failure_name]
74
- if total_errors
75
- specific_validation_threshold = options['thresholds'][potential_failure_name].to_f
76
- success_ratio = (total_items - total_errors).to_f / total_items
77
- specific_validations_to_ignore.push(potential_failure_name) if success_ratio > specific_validation_threshold
78
- end
79
- end
75
+ gather_specific_validations_to_ignore(field_to_validate, field_options)
80
76
  end
81
77
  }
82
78
  end
83
79
 
80
+ def gather_fields_to_ignore(field_to_validate, field_threshold)
81
+ total_errors = error_totals[field_to_validate]
82
+ if total_errors
83
+ success_ratio = (total_items - total_errors).to_f / total_items
84
+ if success_ratio > field_threshold.to_f
85
+ puts "Ignoring #{field_to_validate}"
86
+ fields_to_ignore.push(field_to_validate)
87
+ end
88
+ end
89
+ end
90
+
91
+ def gather_specific_validations_to_ignore(field_to_validate, field_options)
92
+ field_options.each do |validation|
93
+ potential_failure_name = "#{field_to_validate}_#{validation[0]}_fail"
94
+ total_errors = error_totals[potential_failure_name]
95
+ if total_errors
96
+ specific_validation_threshold = options['thresholds'][potential_failure_name].to_f
97
+ success_ratio = (total_items - total_errors).to_f / total_items
98
+ if success_ratio > specific_validation_threshold
99
+ puts "Ignoring #{potential_failure_name}"
100
+ specific_validations_to_ignore.push(potential_failure_name)
101
+ end
102
+ end
103
+ end
104
+ end
105
+
84
106
  def return_threshold(field_to_validate, field_options)
85
107
  if options['thresholds']
86
108
  options['thresholds'][field_to_validate]
@@ -12,23 +12,38 @@ module AeEasy
12
12
  def run
13
13
  begin
14
14
  scrapers.each do |scraper_name, collections|
15
- ValidateScraper.new(scraper_name, collections, rules, outputs).run
15
+ ValidateScraper.new(scraper_name, collections, rules, outputs, thresholds).run
16
16
  end
17
17
  rescue StandardError => e
18
18
  puts "An error has occurred: #{e}"
19
19
  return nil
20
20
  end
21
21
  end
22
+
23
+ private
24
+
25
+ def thresholds
26
+ @thresholds ||= begin
27
+ file_path = File.expand_path('thresholds.yaml', Dir.pwd)
28
+ if File.exists? file_path
29
+ YAML.load(File.open(file_path))
30
+ else
31
+ nil
32
+ end
33
+ end
34
+ end
22
35
  end
23
36
 
24
37
  class ValidateScraper
25
- attr_reader :scraper_name, :collections, :rules, :outputs
38
+ attr_reader :scraper_name, :collections, :rules, :outputs, :options
26
39
 
27
- def initialize(scraper_name, collections, rules, outputs)
40
+ def initialize(scraper_name, collections, rules, outputs, thresholds)
28
41
  @scraper_name = scraper_name
29
42
  @collections = collections
30
43
  @rules = rules
31
44
  @outputs = outputs
45
+ @options = {}
46
+ options['thresholds'] = thresholds[scraper_name] if thresholds && thresholds[scraper_name]
32
47
  end
33
48
 
34
49
  def run
@@ -44,41 +59,51 @@ module AeEasy
44
59
  private
45
60
 
46
61
  def output_scraper
47
- puts "Validating scraper: #{scraper_name}"
62
+ puts "validating scraper: #{scraper_name}"
48
63
  end
49
64
 
50
65
  def status_ok?
51
- collection_counts.code == 200
66
+ !collection_response.parsed_response.nil? && collection_response.code == 200
52
67
  end
53
68
 
54
69
  def validate_collections
55
70
  collections.each do |collection_name|
56
- ValidateCollection.new(scraper_name, collection_name, total_records(collection_name), rules, outputs).run
71
+ collection = collection_counts.find{|collection_hash| collection_hash['collection'] == collection_name }
72
+ if collection
73
+ ValidateCollection.new(scraper_name, collection_name, collection['outputs'], rules, outputs, options).run
74
+ else
75
+ puts "collection #{collection_name} is missing"
76
+ end
57
77
  end
58
78
  end
59
79
 
60
80
  def output_response
61
- puts collection_counts.parsed_response['message']
81
+ if collection_response.parsed_response.nil?
82
+ puts "collection response is null"
83
+ else
84
+ puts collection_response.parsed_response['message']
85
+ end
62
86
  end
63
87
 
64
- def total_records(collection_name)
65
- collection_counts.find{|collection_hash| collection_hash['collection'] == collection_name }['outputs']
88
+ def collection_counts
89
+ @collection_counts ||= collection_response.parsed_response
66
90
  end
67
91
 
68
- def collection_counts
69
- @collection_counts ||= AnswersEngine::Client::ScraperJobOutput.new.collections(scraper_name)
92
+ def collection_response
93
+ @collection_response || AnswersEngine::Client::ScraperJobOutput.new.collections(scraper_name)
70
94
  end
71
95
  end
72
96
 
73
97
  class ValidateCollection
74
- attr_reader :scraper_name, :collection_name, :total_records, :rules, :errors, :outputs
98
+ attr_reader :scraper_name, :collection_name, :total_records, :rules, :errors, :outputs, :options
75
99
 
76
- def initialize(scraper_name, collection_name, total_records, rules, outputs)
100
+ def initialize(scraper_name, collection_name, total_records, rules, outputs, options)
77
101
  @scraper_name = scraper_name
78
102
  @collection_name = collection_name
79
103
  @total_records = total_records
80
104
  @rules = rules
81
105
  @outputs = outputs
106
+ @options = options
82
107
  @errors = { errored_items: [] }
83
108
  end
84
109
 
@@ -88,7 +113,7 @@ module AeEasy
88
113
  ValidateGroups.new(data, scraper_name, collection_name, errors).run
89
114
  ValidateRules.new(data, errors, rules).run if rules
90
115
  end
91
- SaveOutput.new(data.count, rules, errors, outputs_collection_name, outputs, {}).run
116
+ SaveOutput.new(data.count, rules, errors, outputs_collection_name, outputs, options).run
92
117
  end
93
118
 
94
119
  private
@@ -1,5 +1,5 @@
1
1
  module AeEasy
2
2
  module Qa
3
- VERSION = "0.0.21"
3
+ VERSION = "0.0.22"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ae_easy-qa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Lynam
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-29 00:00:00.000000000 Z
11
+ date: 2019-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: answersengine