class DhEasy::Qa::SaveOutput
Attributes
collection_name[R]
error_totals[R]
errors[R]
fields_to_ignore[R]
options[R]
outputs[R]
rules[R]
specific_validations_to_ignore[R]
summary[R]
total_items[R]
Public Class Methods
new(total_items, rules, errors, collection_name, outputs, options)
click to toggle source
# File lib/dh_easy/qa/save_output.rb, line 8 def initialize(total_items, rules, errors, collection_name, outputs, options) @total_items = total_items @rules = rules @errors = errors @collection_name = collection_name @outputs = outputs @options = options @summary = Hash.new(0) @error_totals = {} @fields_to_ignore = [] @specific_validations_to_ignore = [] end
Public Instance Methods
run()
click to toggle source
# File lib/dh_easy/qa/save_output.rb, line 21 def run gather_threshold_totals gather_validations_to_ignore save_group_errors save_errors save_summary end
Private Instance Methods
extract_field(field_sym)
click to toggle source
# File lib/dh_easy/qa/save_output.rb, line 151 def extract_field(field_sym) a = field_sym.to_s.split('_') a.pop a.join('_') end
gather_field_threshold_totals(field_to_validate, field_options)
click to toggle source
# File lib/dh_easy/qa/save_output.rb, line 43 def gather_field_threshold_totals(field_to_validate, field_options) error_total = errors[:errored_items].inject(0){|total, errored_item| failed_fields = errored_item[:failures].keys.collect{|failure_key| extract_field(failure_key) }.uniq total += 1 if failed_fields.include?(field_to_validate) total } error_totals[field_to_validate] = error_total end
gather_fields_to_ignore(field_to_validate, field_threshold)
click to toggle source
# File lib/dh_easy/qa/save_output.rb, line 81 def gather_fields_to_ignore(field_to_validate, field_threshold) total_errors = error_totals[field_to_validate] if total_errors success_ratio = (total_items - total_errors).to_f / total_items if success_ratio > field_threshold.to_f puts "Ignoring #{field_to_validate}" fields_to_ignore.push(field_to_validate) end end end
gather_specific_validation_totals(field_to_validate, field_options)
click to toggle source
# File lib/dh_easy/qa/save_output.rb, line 54 def gather_specific_validation_totals(field_to_validate, field_options) field_options.each do |validation| potential_failure_name = "#{field_to_validate}_#{validation[0]}_fail" if options['thresholds'] && options['thresholds'][potential_failure_name] error_total = errors[:errored_items].inject(0){|total, errored_item| failed_validations = errored_item[:failures].keys.collect{|failure_key| "#{failure_key}_fail" } total += 1 if failed_validations.include?(potential_failure_name) total } error_totals[potential_failure_name] = error_total end end end
gather_specific_validations_to_ignore(field_to_validate, field_options)
click to toggle source
# File lib/dh_easy/qa/save_output.rb, line 92 def gather_specific_validations_to_ignore(field_to_validate, field_options) field_options.each do |validation| potential_failure_name = "#{field_to_validate}_#{validation[0]}_fail" total_errors = error_totals[potential_failure_name] if total_errors specific_validation_threshold = options['thresholds'][potential_failure_name].to_f success_ratio = (total_items - total_errors).to_f / total_items if success_ratio > specific_validation_threshold || (specific_validation_threshold == 0.0 && success_ratio == 0.0) puts "Ignoring #{potential_failure_name}" specific_validations_to_ignore.push(potential_failure_name) end end end end
gather_threshold_totals()
click to toggle source
thresholds are a setting where you can ignore errors if they are under a specific error rate
# File lib/dh_easy/qa/save_output.rb, line 32 def gather_threshold_totals rules.each{|field_to_validate, field_options| field_threshold = return_threshold(field_to_validate, field_options) if field_threshold gather_field_threshold_totals(field_to_validate, field_options) else gather_specific_validation_totals(field_to_validate, field_options) end } end
gather_validations_to_ignore()
click to toggle source
# File lib/dh_easy/qa/save_output.rb, line 70 def gather_validations_to_ignore rules.each{|field_to_validate, field_options| field_threshold = return_threshold(field_to_validate, field_options) if field_threshold gather_fields_to_ignore(field_to_validate, field_threshold) else gather_specific_validations_to_ignore(field_to_validate, field_options) end } end
remove_threshold_failures(errored_item)
click to toggle source
# File lib/dh_easy/qa/save_output.rb, line 136 def remove_threshold_failures(errored_item) errored_item[:failures].delete_if{|error_name, fail| specific_validation_name = "#{error_name}_fail" field_name = extract_field(error_name) fields_to_ignore.include?(field_name) || specific_validations_to_ignore.include?(specific_validation_name) } end
return_threshold(field_to_validate, field_options)
click to toggle source
# File lib/dh_easy/qa/save_output.rb, line 107 def return_threshold(field_to_validate, field_options) if options['thresholds'] options['thresholds'][field_to_validate] else field_options['threshold'] || options['threshold'] end end
save_errors()
click to toggle source
# File lib/dh_easy/qa/save_output.rb, line 124 def save_errors errors[:errored_items].each do |errored_item| remove_threshold_failures(errored_item) if fields_to_ignore.any? || specific_validations_to_ignore.any? errored_item[:failures].each do |error_key, value| key = "#{error_key.to_s}_#{value.to_s}" summary[key] += 1 end errored_item['_collection'] = collection_name outputs << errored_item if errored_item[:failures].any? end end
save_group_errors()
click to toggle source
# File lib/dh_easy/qa/save_output.rb, line 115 def save_group_errors errors.each{|error_name, output_hash| if error_name != :errored_items error_name = output_hash.delete(:failure) summary["#{error_name}_fail"] = output_hash end } end
save_summary()
click to toggle source
# File lib/dh_easy/qa/save_output.rb, line 144 def save_summary summary['pass'] = 'true' if summary.empty? summary['_collection'] = "#{collection_name}_summary" summary['total_items'] = total_items outputs << summary end