class DataValidation::Comparison::RankingTableMwPrComparison

Public Instance Methods

api_path() click to toggle source
# File lib/data_validation/comparison/ranking_table_mw_pr_comparison.rb, line 7
def api_path
  '/rest/LaxPower/rankingTableMWpr'
end
compare() click to toggle source
# File lib/data_validation/comparison/ranking_table_mw_pr_comparison.rb, line 19
def compare
  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

  ## compare first table
  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
        next
      end

      if item.length < field_array.length && empty_field && empty_field == filed_name ## when the field is possibly 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])) ||
        (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

  compare_conf_standings api_data, data_access
end
conf_rank_api_url() click to toggle source
# File lib/data_validation/comparison/ranking_table_mw_pr_comparison.rb, line 66
def conf_rank_api_url
  DataValidation.api_request_host + '/rest/LaxPower/conferenceRankingTable'
end
empty_field() click to toggle source
# File lib/data_validation/comparison/ranking_table_mw_pr_comparison.rb, line 15
def empty_field
  'pollRank'
end
field_array() click to toggle source
# File lib/data_validation/comparison/ranking_table_mw_pr_comparison.rb, line 11
def field_array
  ['rank', 'teamName', 'powerRating', 'pollRank', 'sosRank', 'rpiRank', 'qwfRank', 'tsiRank', %w|record wins|, %w|record losses|, %w|record ties|]
end