lx_data_validation 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +14 -2
- data/bin/compare +5 -1
- data/lib/data_validation.rb +2 -0
- data/lib/data_validation/comparison/comparison_base.rb +18 -16
- data/lib/data_validation/comparison/comparison_factory.rb +3 -0
- data/lib/data_validation/comparison/div_ranking_pr_comparison.rb +1 -1
- data/lib/data_validation/comparison/ranking_table_mw_pr_comparison.rb +1 -1
- data/lib/data_validation/comparison/ranking_table_pro_pr_comparison.rb +73 -0
- data/lib/data_validation/data_access.rb +28 -0
- data/lib/data_validation/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e194bf49037ed8424cf3dcf33f3fabf5cb52760
|
4
|
+
data.tar.gz: 0647669d8cf15cb8f21e1c817c149ce4925f4225
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b165e44eea570728fb66fd5156eaf4136857ca877d6515279e90543dc70135935b55782231bd37cdab2c67b2da82453ac576cc3d791302d2f0974717e39e88e2
|
7
|
+
data.tar.gz: 7671e8e28c54168f2a659b661f118a4900be3b4208049b7af391d94453ee776e7542eb7825a7d2157c91e874c5688fccd7e1a994c2ceb30154ada490ab8389ae
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
# DataValidation
|
2
2
|
|
3
|
-
|
3
|
+
This gem validate the data between web page items and mobile api response.
|
4
4
|
|
5
|
+
It will validate stat pages of PRO, men, woman, boys and girls.
|
6
|
+
|
7
|
+
e.g. http://php.admin.laxpower.com/update17/binmen/rating01.php
|
5
8
|
|
6
9
|
## Installation
|
7
10
|
|
8
11
|
Add this line to your application's Gemfile:
|
9
12
|
|
10
13
|
```ruby
|
11
|
-
gem '
|
14
|
+
gem 'lx_data_validation'
|
12
15
|
```
|
13
16
|
|
14
17
|
And then execute:
|
@@ -20,7 +23,16 @@ Or install it yourself as:
|
|
20
23
|
$ gem install lx_data_validation
|
21
24
|
|
22
25
|
## Usage
|
26
|
+
|
27
|
+
Validate the data of 2017 season (the default season)
|
28
|
+
|
29
|
+
$ compare
|
30
|
+
|
31
|
+
Validate the data of 2016 season
|
32
|
+
|
33
|
+
$ compare 16
|
23
34
|
|
35
|
+
It will generate a new folder named log under your current directory. All mismatched data will be recorded into the log files in the sub-directories
|
24
36
|
|
25
37
|
## Development
|
26
38
|
|
data/bin/compare
CHANGED
data/lib/data_validation.rb
CHANGED
@@ -21,6 +21,8 @@ module DataValidation
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def compare_with_season(season = '17')
|
24
|
+
compare_with_url(web_request_host + '/mll')
|
25
|
+
compare_with_url(web_request_host + '/nll')
|
24
26
|
%w|men women boys girls|.each { |category| compare_with_season_and_category season, category }
|
25
27
|
end
|
26
28
|
|
@@ -56,7 +56,7 @@ module DataValidation
|
|
56
56
|
(team_value.is_a?(Float) && team_value == item[i].to_f) ||
|
57
57
|
(team_value.is_a?(Integer) && team_value == item[i].to_i)
|
58
58
|
|
59
|
-
logger.error "team #{item[0]}'s #{filed_name}
|
59
|
+
logger.error "team #{item[0]}'s #{filed_name}: #{item[i]} -- #{team_value}"
|
60
60
|
end
|
61
61
|
|
62
62
|
i += 1
|
@@ -91,23 +91,23 @@ module DataValidation
|
|
91
91
|
record.each_with_index do |item, index|
|
92
92
|
if index == 0 && item.to_i != team_data['rank']
|
93
93
|
elsif index == 1 && item.to_f != team_data['powerRating']
|
94
|
-
logger.error "team #{i}
|
94
|
+
logger.error "team #{i} powerRating in #{full_conf}: #{item.to_f} -- #{team_data['powerRating']}"
|
95
95
|
elsif index == 2 && item.to_i != team_data['conference']['wins']
|
96
|
-
logger.error "team #{i}
|
96
|
+
logger.error "team #{i} conference wins in #{full_conf}: #{item.to_i} -- #{team_data['conference']['wins']}"
|
97
97
|
elsif index == 3 && item.to_i != team_data['conference']['losses']
|
98
|
-
logger.error "team #{i}
|
98
|
+
logger.error "team #{i} conference losses in #{full_conf}: #{item.to_i} -- #{team_data['conference']['losses']}"
|
99
99
|
elsif index == 4 && item.to_i != team_data['conference']['ties']
|
100
|
-
logger.error "team #{i}
|
100
|
+
logger.error "team #{i} conference ties in #{full_conf}: #{item.to_i} -- #{team_data['conference']['ties']}"
|
101
101
|
elsif index == 5 && item.to_f != team_data['winLossConf']
|
102
|
-
logger.error "team #{i}
|
102
|
+
logger.error "team #{i} winLossConf in #{full_conf}: #{item.to_f} -- #{team_data['winLossConf']}"
|
103
103
|
elsif index == 6 && item.to_i != team_data['total']['wins']
|
104
|
-
logger.error "team #{i}
|
104
|
+
logger.error "team #{i} total wins in #{full_conf}: #{item.to_i} -- #{team_data['total']['wins']}"
|
105
105
|
elsif index == 7 && item.to_i != team_data['total']['losses']
|
106
|
-
logger.error "team #{i}
|
106
|
+
logger.error "team #{i} total losses in #{full_conf}: #{item.to_i} -- #{team_data['total']['losses']}"
|
107
107
|
elsif index == 8 && item.to_i != team_data['total']['ties']
|
108
|
-
logger.error "team #{i}
|
108
|
+
logger.error "team #{i} total ties in #{full_conf}: #{item.to_i} -- #{team_data['total']['ties']}"
|
109
109
|
elsif index == 9 && item.to_f != team_data['winLossTotal']
|
110
|
-
logger.error "team #{i}
|
110
|
+
logger.error "team #{i} winLossTotal in #{full_conf}: #{item.to_f} -- #{team_data['winLossTotal']}"
|
111
111
|
end
|
112
112
|
end
|
113
113
|
end
|
@@ -134,12 +134,14 @@ module DataValidation
|
|
134
134
|
|
135
135
|
def logger
|
136
136
|
@logger ||= begin
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
137
|
+
tokens = logger_name.split('/')
|
138
|
+
1.upto(tokens.size - 1) do |n|
|
139
|
+
dir = tokens[0...n].join('/')
|
140
|
+
Dir.mkdir(dir) unless Dir.exist?(dir)
|
141
|
+
end
|
142
|
+
logger = Logger.new(File.new(logger_name, 'w'))
|
143
|
+
logger.info(web_url)
|
144
|
+
logger
|
143
145
|
end
|
144
146
|
end
|
145
147
|
|
@@ -7,6 +7,7 @@ require 'data_validation/comparison/ranking_table_mw_poll_comparison'
|
|
7
7
|
require 'data_validation/comparison/ranking_table_mw_trend_comparison'
|
8
8
|
require 'data_validation/comparison/ranking_table_mw_tsi_comparison'
|
9
9
|
require 'data_validation/comparison/ranking_table_mw_pr_comparison'
|
10
|
+
require 'data_validation/comparison/ranking_table_pro_pr_comparison'
|
10
11
|
|
11
12
|
module DataValidation
|
12
13
|
module Comparison
|
@@ -30,6 +31,8 @@ module DataValidation
|
|
30
31
|
return RankingTableMwTrendComparison.new url
|
31
32
|
elsif url.match /update\d\d\/bin\S+\/tsi\d+.php/ # Trend page for collage division
|
32
33
|
return RankingTableMwTsiComparison.new url
|
34
|
+
elsif url.match /\.com\/(mll|nll)/ # Pro ranking page
|
35
|
+
return RankingTableProPrComparison.new url
|
33
36
|
end
|
34
37
|
end
|
35
38
|
end
|
@@ -55,7 +55,7 @@ module DataValidation
|
|
55
55
|
(team_value.is_a?(Float) && team_value == item[i].to_f) ||
|
56
56
|
(team_value.is_a?(Integer) && team_value == item[i].to_i)
|
57
57
|
|
58
|
-
logger.error "team #{item[0]}'s #{filed_name}
|
58
|
+
logger.error "team #{item[0]}'s #{filed_name}: #{item[i]} -- #{team_value}"
|
59
59
|
end
|
60
60
|
|
61
61
|
i += 1
|
@@ -54,7 +54,7 @@ module DataValidation
|
|
54
54
|
(team_value.is_a?(Float) && team_value == item[i].to_f) ||
|
55
55
|
(team_value.is_a?(Integer) && team_value == item[i].to_i)
|
56
56
|
|
57
|
-
logger.error "team #{item[0]}'s #{filed_name}
|
57
|
+
logger.error "team #{item[0]}'s #{filed_name}: #{item[i]} -- #{team_value}"
|
58
58
|
end
|
59
59
|
|
60
60
|
i += 1
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module DataValidation
|
2
|
+
module Comparison
|
3
|
+
class RankingTableProPrComparison
|
4
|
+
|
5
|
+
attr_reader :web_url
|
6
|
+
|
7
|
+
def initialize(web_url)
|
8
|
+
@web_url = web_url
|
9
|
+
end
|
10
|
+
|
11
|
+
def api_path
|
12
|
+
'/rest/LaxPower/rankingTableProPR'
|
13
|
+
end
|
14
|
+
|
15
|
+
def field_array
|
16
|
+
['rank', 'teamName', 'powerRating', %w|record wins|, %w|record losses|]
|
17
|
+
end
|
18
|
+
|
19
|
+
def compare
|
20
|
+
div_id = web_url.match(/mll/) ? '12' : '11'
|
21
|
+
season = 2017
|
22
|
+
is_old_season = false
|
23
|
+
|
24
|
+
web_data = DataValidation::DataAccess.get_pro_pr_table web_url
|
25
|
+
|
26
|
+
api_data = (DataValidation::DataAccess.get_pr_for_pro season, 'PRO', div_id)
|
27
|
+
if api_data.nil?
|
28
|
+
season = 2016
|
29
|
+
api_data = DataValidation::DataAccess.get_pr_for_pro season, 'PRO', div_id
|
30
|
+
is_old_season = true
|
31
|
+
end
|
32
|
+
|
33
|
+
@logger_name = "log/#{season}/pro/pr/#{season}_pro_#{div_id}.log"
|
34
|
+
if is_old_season
|
35
|
+
puts 'This PR ranking is still for 2016'
|
36
|
+
end
|
37
|
+
|
38
|
+
if web_data.size != api_data.size
|
39
|
+
logger.error 'team size is incorrect'
|
40
|
+
else
|
41
|
+
web_data.each_with_index do |web_record, index|
|
42
|
+
api_record = api_data[index]
|
43
|
+
field_array.each_with_index do |field_name, i|
|
44
|
+
api_record_item = api_record[field_name]
|
45
|
+
web_record_item = web_record[i]
|
46
|
+
|
47
|
+
if (api_record_item.is_a?(String) && !api_record_item.include?(web_record_item.strip)) ||
|
48
|
+
((api_record_item.is_a?(Float) && api_record_item != web_record_item.to_f)) ||
|
49
|
+
((api_record_item.is_a?(Integer) && api_record_item != web_record_item.to_i))
|
50
|
+
logger.error "team #{index + 1}'s #{field_name}: #{api_record_item} -- #{web_record_item}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def logger
|
59
|
+
@logger ||= begin
|
60
|
+
tokens = @logger_name.split('/')
|
61
|
+
1.upto(tokens.size - 1) do |n|
|
62
|
+
dir = tokens[0...n].join('/')
|
63
|
+
Dir.mkdir(dir) unless Dir.exist?(dir)
|
64
|
+
end
|
65
|
+
logger = Logger.new(File.new(@logger_name, 'w'))
|
66
|
+
logger.info(web_url)
|
67
|
+
logger
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -88,6 +88,8 @@ module DataValidation
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
+
|
92
|
+
|
91
93
|
def get_response_from_mobile_api
|
92
94
|
HTTParty.post(api_url, headers: {'Content-Type' => 'application/json'}, body: api_body)
|
93
95
|
end
|
@@ -103,6 +105,32 @@ module DataValidation
|
|
103
105
|
body: %Q|{"season": "#{season}","category": "#{category}", "divisionId": #{div_id}}|)
|
104
106
|
end
|
105
107
|
|
108
|
+
# for pro only
|
109
|
+
def self.get_pro_pr_table html_url
|
110
|
+
table = []
|
111
|
+
doc = Nokogiri::HTML(open(html_url))
|
112
|
+
doc.search('div#content_well td:nth-of-type(3) > div:nth-of-type(2) tr:not(:first-of-type)').map do |team|
|
113
|
+
team_data = []
|
114
|
+
team.children.each_with_index do |item, index|
|
115
|
+
value = item.text
|
116
|
+
if index == 3 # number of win and loss
|
117
|
+
value.split('-').each { |n| team_data << n }
|
118
|
+
else
|
119
|
+
team_data << value
|
120
|
+
end
|
121
|
+
end
|
122
|
+
table << team_data
|
123
|
+
end
|
124
|
+
table
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.get_pr_for_pro(season, category, div_id)
|
128
|
+
puts "get PR ranking for #{season}, #{category}, #{div_id} from " + DataValidation.api_request_host + '/rest/LaxPower/rankingTableProPR'
|
129
|
+
HTTParty.post(DataValidation.api_request_host + '/rest/LaxPower/rankingTableProPR',
|
130
|
+
headers: {'Content-Type' => 'application/json'},
|
131
|
+
body: %Q|{"season": "#{season}","category": "#{category}", "divisionId": #{div_id}, "pageSize": 1000, "currPage": 1}|)['results']['results']['teams']
|
132
|
+
end
|
133
|
+
|
106
134
|
def self.get_high_school_div_stat_urls(season='17', category='boys')
|
107
135
|
is_for_hs = category == 'boys' || category == 'girls'
|
108
136
|
high_school_div_stat_main_url = if is_for_hs
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lx_data_validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roger Tong
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- lib/data_validation/comparison/ranking_table_mw_sos_comparison.rb
|
71
71
|
- lib/data_validation/comparison/ranking_table_mw_trend_comparison.rb
|
72
72
|
- lib/data_validation/comparison/ranking_table_mw_tsi_comparison.rb
|
73
|
+
- lib/data_validation/comparison/ranking_table_pro_pr_comparison.rb
|
73
74
|
- lib/data_validation/data_access.rb
|
74
75
|
- lib/data_validation/version.rb
|
75
76
|
homepage: https://gitlab.dev.activenetwork.com/rtong/data-validation-for-laxpower
|