Class: DataValidation::Comparison::DivRankingPrComparison

Inherits:
ComparisonBase
  • Object
show all
Defined in:
lib/data_validation/comparison/div_ranking_pr_comparison.rb

Instance Attribute Summary

Attributes inherited from ComparisonBase

#category, #division_id, #logger_name, #season, #web_url

Instance Method Summary collapse

Methods inherited from ComparisonBase

#compare_conf_standings, #initialize

Constructor Details

This class inherits a constructor from DataValidation::Comparison::ComparisonBase

Instance Method Details

#api_pathObject



7
8
9
# File 'lib/data_validation/comparison/div_ranking_pr_comparison.rb', line 7

def api_path
  '/rest/LaxPower/divisionRankingPr'
end

#compareObject



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
67
68
# File 'lib/data_validation/comparison/div_ranking_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 standing tables
  compare_conf_standings(api_data, data_access)
end

#conf_rank_api_urlObject



72
73
74
# File 'lib/data_validation/comparison/div_ranking_pr_comparison.rb', line 72

def conf_rank_api_url
  DataValidation.api_request_host + '/rest/LaxPower/conferenceRankingTable'
end

#empty_fieldObject



15
16
17
# File 'lib/data_validation/comparison/div_ranking_pr_comparison.rb', line 15

def empty_field
  ''
end

#field_arrayObject



11
12
13
# File 'lib/data_validation/comparison/div_ranking_pr_comparison.rb', line 11

def field_array
  ['rank', 'teamName', 'powerRating', 'regInPr', 'correction', 'championship', 'winLossTotal', %w|record wins|, %w|record losses|, %w|record ties|]
end