class DataValidation::Comparison::RankingTableProPrComparison

Attributes

web_url[R]

Public Class Methods

new(web_url) click to toggle source
# File lib/data_validation/comparison/ranking_table_pro_pr_comparison.rb, line 7
def initialize(web_url)
  @web_url = web_url
end

Public Instance Methods

api_path() click to toggle source
# File lib/data_validation/comparison/ranking_table_pro_pr_comparison.rb, line 11
def api_path
  '/rest/LaxPower/rankingTableProPR'
end
compare() click to toggle source
# File lib/data_validation/comparison/ranking_table_pro_pr_comparison.rb, line 19
def compare
  div_id = web_url.match(/mll/) ? '12' : '11'
  season = 2017
  is_old_season = false

  web_data = DataValidation::DataAccess.get_pro_pr_table web_url

  api_data = (DataValidation::DataAccess.get_pr_for_pro season, 'PRO', div_id)
  if api_data.nil?
    season = 2016
    api_data = DataValidation::DataAccess.get_pr_for_pro season, 'PRO', div_id
    is_old_season = true
  end

  @logger_name = "log/#{season}/pro/pr/#{season}_pro_#{div_id}.log"
  if is_old_season
    puts 'This PR ranking is still for 2016'
  end

  if web_data.size != api_data.size
    logger.error 'team size is incorrect'
  else
    web_data.each_with_index do |web_record, index|
      api_record = api_data[index]
      field_array.each_with_index do |field_name, i|
        api_record_item = api_record[field_name]
        web_record_item = web_record[i]

        if (api_record_item.is_a?(String) && !api_record_item.include?(web_record_item.strip)) ||
          ((api_record_item.is_a?(Float) && api_record_item != web_record_item.to_f)) ||
          ((api_record_item.is_a?(Integer) && api_record_item != web_record_item.to_i))
          logger.error "team #{index + 1}'s #{field_name}: #{api_record_item} -- #{web_record_item}"
        end
      end
    end

  end
end
field_array() click to toggle source
# File lib/data_validation/comparison/ranking_table_pro_pr_comparison.rb, line 15
def field_array
  ['rank', 'teamName', 'powerRating', %w|record wins|, %w|record losses|]
end
logger() click to toggle source
# File lib/data_validation/comparison/ranking_table_pro_pr_comparison.rb, line 58
def logger
  @logger ||= begin
    tokens = @logger_name.split('/')
    1.upto(tokens.size - 1) do |n|
      dir = tokens[0...n].join('/')
      Dir.mkdir(dir) unless Dir.exist?(dir)
    end
    logger = Logger.new(File.new(@logger_name, 'w'))
    logger.info(web_url)
    logger
  end
end