Class: DataValidation::Comparison::ComparisonBase
- Inherits:
-
Object
- Object
- DataValidation::Comparison::ComparisonBase
- Defined in:
- lib/data_validation/comparison/comparison_base.rb
Direct Known Subclasses
DivRankingPrComparison, DivRankingWlComparison, RankingTableMwPollComparison, RankingTableMwPrComparison, RankingTableMwQwComparison, RankingTableMwRpiComparison, RankingTableMwSosComparison, RankingTableMwTrendComparison, RankingTableMwTsiComparison
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#division_id ⇒ Object
readonly
Returns the value of attribute division_id.
-
#logger_name ⇒ Object
readonly
Returns the value of attribute logger_name.
-
#season ⇒ Object
readonly
Returns the value of attribute season.
-
#web_url ⇒ Object
readonly
Returns the value of attribute web_url.
Instance Method Summary collapse
- #compare ⇒ Object
- #compare_conf_standings(api_data, data_access) ⇒ Object
-
#initialize(web_url) ⇒ ComparisonBase
constructor
A new instance of ComparisonBase.
Constructor Details
#initialize(web_url) ⇒ ComparisonBase
Returns a new instance of ComparisonBase.
9 10 11 |
# File 'lib/data_validation/comparison/comparison_base.rb', line 9 def initialize(web_url) @web_url = web_url end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
7 8 9 |
# File 'lib/data_validation/comparison/comparison_base.rb', line 7 def category @category end |
#division_id ⇒ Object (readonly)
Returns the value of attribute division_id.
7 8 9 |
# File 'lib/data_validation/comparison/comparison_base.rb', line 7 def division_id @division_id end |
#logger_name ⇒ Object (readonly)
Returns the value of attribute logger_name.
7 8 9 |
# File 'lib/data_validation/comparison/comparison_base.rb', line 7 def logger_name @logger_name end |
#season ⇒ Object (readonly)
Returns the value of attribute season.
7 8 9 |
# File 'lib/data_validation/comparison/comparison_base.rb', line 7 def season @season end |
#web_url ⇒ Object (readonly)
Returns the value of attribute web_url.
7 8 9 |
# File 'lib/data_validation/comparison/comparison_base.rb', line 7 def web_url @web_url end |
Instance Method Details
#compare ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/data_validation/comparison/comparison_base.rb', line 13 def compare if api_path.nil? raise 'Please define api_path' end if field_array.nil? raise 'Please define field_array' end data_access = DataValidation::DataAccess.new(web_url, DataValidation.api_request_host + api_path, determine_request_body_and_logger_name) puts 'requesting web page...' web_data = data_access.get_main_table_data puts 'requesting mobile api data: ' + DataValidation.api_request_host + api_path api_data = data_access.get_response_from_mobile_api if web_data.length != api_data['results']['results']['total'] logger.error "The record size between web page and api data is not the same: #{web_data.length} -- #{api_data['results']['results']['total']}" return end web_data.each_with_index do |item, index| team = api_data['results']['results']['teams'][index] i = 0 field_array.each do |filed_name| if filed_name.is_a? String team_value = team[filed_name] elsif filed_name.is_a? Array team_value = team[filed_name[0]][filed_name[1]] else i += 1 next end if item.length < field_array.length && empty_field && empty_field == filed_name ## when the field is empty in the table logger.error "team #{item[0]}'s #{filed_name} is not empty: #{team_value}" unless (team_value == 0 || team_value.nil?) next end unless (team_value.is_a?(String) && team_value.include?(item[i].strip)) || (team_value.is_a?(Float) && team_value == item[i].to_f) || (team_value.is_a?(Integer) && team_value == item[i].to_i) logger.error "team #{item[0]}'s #{filed_name}: #{item[i]} -- #{team_value}" end i += 1 end end end |
#compare_conf_standings(api_data, data_access) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/data_validation/comparison/comparison_base.rb', line 68 def compare_conf_standings(api_data, data_access) puts 'Start to compare conf ranking tables' conf_standing_data = data_access.conf_standing_data conf_standing_data.each do |standing| full_conf = '' standing.each_with_index do |record, i| if i == 0 state = record[0] team_class = record[1] conf = record[2] full_conf = "#{state}, #{team_class}, #{conf}" api_data = data_access.get_response_from_mobile_api_with_params(conf_rank_api_url, %Q|{"season": "#{season}", "conference": {"category": "#{category}", "conference": "#{conf}", "divisionId": #{division_id.to_i}, "state": "#{state}", "teamClass": "#{team_class}"}, "currPage": 1, "pageSize": 1000}|) if api_data['results']['results']['total'] != standing.length - 1 logger.error "standing for #{full_conf} has incorrect length: #{standing.length - 1} : #{api_data['results']['results']['total']}" break end else team_data = api_data['results']['results']['teams'][i - 1] record.each_with_index do |item, index| if index == 0 && item.to_i != team_data['rank'] elsif index == 1 && item.to_f != team_data['powerRating'] logger.error "team #{i} powerRating in #{full_conf}: #{item.to_f} -- #{team_data['powerRating']}" elsif index == 2 && item.to_i != team_data['conference']['wins'] logger.error "team #{i} conference wins in #{full_conf}: #{item.to_i} -- #{team_data['conference']['wins']}" elsif index == 3 && item.to_i != team_data['conference']['losses'] logger.error "team #{i} conference losses in #{full_conf}: #{item.to_i} -- #{team_data['conference']['losses']}" elsif index == 4 && item.to_i != team_data['conference']['ties'] logger.error "team #{i} conference ties in #{full_conf}: #{item.to_i} -- #{team_data['conference']['ties']}" elsif index == 5 && item.to_f != team_data['winLossConf'] logger.error "team #{i} winLossConf in #{full_conf}: #{item.to_f} -- #{team_data['winLossConf']}" elsif index == 6 && item.to_i != team_data['total']['wins'] logger.error "team #{i} total wins in #{full_conf}: #{item.to_i} -- #{team_data['total']['wins']}" elsif index == 7 && item.to_i != team_data['total']['losses'] logger.error "team #{i} total losses in #{full_conf}: #{item.to_i} -- #{team_data['total']['losses']}" elsif index == 8 && item.to_i != team_data['total']['ties'] logger.error "team #{i} total ties in #{full_conf}: #{item.to_i} -- #{team_data['total']['ties']}" elsif index == 9 && item.to_f != team_data['winLossTotal'] logger.error "team #{i} winLossTotal in #{full_conf}: #{item.to_f} -- #{team_data['winLossTotal']}" end end end end end end |