football_stats_filter_tool 0.2.5 → 0.2.9
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/bin/football-stats-filter-tool +5 -0
- data/config/environment.rb +9 -0
- data/lib/football_stats_filter_tool/command_line_interface.rb +308 -0
- data/lib/football_stats_filter_tool/data_scraper.rb +47 -0
- data/lib/football_stats_filter_tool/player.rb +137 -0
- data/lib/football_stats_filter_tool/version.rb +1 -1
- metadata +14 -32
- data/.github/workflows/main.yml +0 -18
- data/.gitignore +0 -11
- data/.rspec +0 -3
- data/Gemfile +0 -13
- data/LICENSE.txt +0 -21
- data/README.md +0 -37
- data/Rakefile +0 -8
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/football_stats_filter_tool.gemspec +0 -41
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b4f3a1e07c0a057078064141554fcf58861c807c27da4979145dd4e9bd4d578e
|
|
4
|
+
data.tar.gz: 66c1fb62e6106a05d76c863b5248fb89a8732047932b357621c8a240fdd7c088
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5c74aedd444c34266772f1d910d2e20a0212596fe984eeb2dcbea13d31937745c73d9b23dd33c4881c89e1975bd8e6b8ebfd1b4bcc0f2c1deda9e383999e2fa6
|
|
7
|
+
data.tar.gz: 013d8a5f24386887767fb1ea63364952a2624d22cd4a8ac19acde5d20adfa7759f27aa536fc9e24569c361466265c3086f00ca7dad1d0fd9c17df1e062699ee7
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require 'pry'
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
require 'open-uri'
|
|
4
|
+
|
|
5
|
+
require_relative "../lib/football_stats_filter_tool/command_line_interface.rb"
|
|
6
|
+
require_relative "../lib/football_stats_filter_tool/player.rb"
|
|
7
|
+
require_relative "../lib/football_stats_filter_tool/data_scraper.rb"
|
|
8
|
+
|
|
9
|
+
require_relative "../lib/football_stats_filter_tool/version.rb"
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
require_relative './player'
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
require 'pry'
|
|
4
|
+
|
|
5
|
+
class FootballStatsFilterTool::CommandLineInterface
|
|
6
|
+
attr_accessor :stats_list, :filter_list, :sort_stat, :sort_value, :player_data
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def self.run
|
|
10
|
+
user_cli = FootballStatsFilterTool::CommandLineInterface.new
|
|
11
|
+
user_cli.start
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def start
|
|
15
|
+
puts "Welcome to Football Stats Filter Tool"
|
|
16
|
+
puts "Would you like to load some football stats (y/n)"
|
|
17
|
+
input = gets.chomp
|
|
18
|
+
while(input == "y")
|
|
19
|
+
request_year
|
|
20
|
+
print_allowable_attributes
|
|
21
|
+
loop do
|
|
22
|
+
run_query
|
|
23
|
+
puts "Would you like to query another list from this year? (y/n)"
|
|
24
|
+
input = gets.chomp
|
|
25
|
+
if(input != "y")
|
|
26
|
+
break
|
|
27
|
+
end
|
|
28
|
+
@player_data = FootballStatsFilterTool::Player.all
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
puts "Would you like to load another year? (y/n)"
|
|
32
|
+
input = gets.chomp
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
puts "Thank you for using the Football stats filter tool, have a nice day"
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def run_query
|
|
40
|
+
request_stats_list
|
|
41
|
+
request_filter_list
|
|
42
|
+
request_sort
|
|
43
|
+
filter_player_data
|
|
44
|
+
sort_player_data
|
|
45
|
+
display_current_player_data
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def display_current_player_data
|
|
49
|
+
puts stats_list_header
|
|
50
|
+
@player_data.each.with_index do |player, i|
|
|
51
|
+
out = "#{i+1}.\t"
|
|
52
|
+
@stats_list.each do |stat|
|
|
53
|
+
value = player.instance_variable_get("@#{stat}")
|
|
54
|
+
out+= "#{value}#{determine_table_tabs(stat, value)}"
|
|
55
|
+
end
|
|
56
|
+
puts out
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def sort_player_data
|
|
61
|
+
if(@sort_value == "ASC")
|
|
62
|
+
@player_data.sort!{|player_a, player_b| player_a.instance_variable_get("@#{@sort_stat}") <=> player_b.instance_variable_get("@#{@sort_stat}")}
|
|
63
|
+
elsif(@sort_value == "DESC")
|
|
64
|
+
@player_data.sort!{|player_a, player_b| player_b.instance_variable_get("@#{@sort_stat}") <=> player_a.instance_variable_get("@#{@sort_stat}")}
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def filter_player_data
|
|
69
|
+
out = []
|
|
70
|
+
@filter_list.each do |filter_entry|
|
|
71
|
+
stat = filter_entry[:stat]
|
|
72
|
+
value = filter_entry[:value]
|
|
73
|
+
compare_type = filter_entry[:compare_type]
|
|
74
|
+
|
|
75
|
+
@player_data.each do |player_entry|
|
|
76
|
+
entry_value = player_entry.instance_variable_get("@#{stat}")
|
|
77
|
+
if(entry_value!=nil)
|
|
78
|
+
if(compare_type == ">" && entry_value>value)
|
|
79
|
+
out.push(player_entry)
|
|
80
|
+
end
|
|
81
|
+
if(compare_type == "<" && entry_value<value)
|
|
82
|
+
out.push(player_entry)
|
|
83
|
+
end
|
|
84
|
+
if(compare_type == "=" && entry_value==value)
|
|
85
|
+
out.push(player_entry)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
@player_data = out
|
|
90
|
+
out = []
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def request_year
|
|
95
|
+
FootballStatsFilterTool::Player.delete_all
|
|
96
|
+
puts "Please select a year to load"
|
|
97
|
+
year = gets.chomp.to_i
|
|
98
|
+
|
|
99
|
+
begin
|
|
100
|
+
FootballStatsFilterTool::Player.import(year)
|
|
101
|
+
@player_data = FootballStatsFilterTool::Player.all
|
|
102
|
+
rescue OpenURI::HTTPError => error
|
|
103
|
+
if error.message == '404 Not Found'
|
|
104
|
+
puts "Invalid year selection"
|
|
105
|
+
request_year
|
|
106
|
+
else
|
|
107
|
+
raise error
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def stats_list_header
|
|
113
|
+
out ="\tname\t\t\t"
|
|
114
|
+
tab_length = 8;
|
|
115
|
+
|
|
116
|
+
@stats_list.each do |entry|
|
|
117
|
+
if(entry!=:name)
|
|
118
|
+
out += entry.to_s
|
|
119
|
+
out+="\t"
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
out
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def determine_table_tabs(stat_symbol, value)#returns the appropriate number of tabs for a given table entry
|
|
126
|
+
value_length = value.to_s.length
|
|
127
|
+
stat_symbol_length = stat_symbol.to_s.length
|
|
128
|
+
tab_length = 8;
|
|
129
|
+
name_defaults_tabs =3;
|
|
130
|
+
num_tabs = 0;
|
|
131
|
+
if(stat_symbol == :name)
|
|
132
|
+
num_tabs = name_defaults_tabs-(value_length)/tab_length
|
|
133
|
+
else
|
|
134
|
+
num_tabs = 1 + (stat_symbol_length)/tab_length - (value_length)/tab_length
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
out = ""
|
|
138
|
+
|
|
139
|
+
num_tabs.times{out += "\t"}
|
|
140
|
+
return out
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def request_stats_list
|
|
144
|
+
puts "Give a list of the stats you would like display along with the player name (e.g. team, sacks, tackles)"
|
|
145
|
+
stats_input = gets.chomp
|
|
146
|
+
stats_interpreted = interpret_stat_selection(stats_input)
|
|
147
|
+
if(stats_interpreted[:invalid_data].length>0)
|
|
148
|
+
puts "The following entries were invalid and will be discarded"
|
|
149
|
+
stats_interpreted[:invalid_data].each do |entry|
|
|
150
|
+
puts entry
|
|
151
|
+
end
|
|
152
|
+
puts "Would you like to repeat this step? (y/n)"
|
|
153
|
+
input = gets.chomp
|
|
154
|
+
if(input == "y")
|
|
155
|
+
request_stats_list
|
|
156
|
+
else
|
|
157
|
+
@stats_list = stats_interpreted[:valid_data]
|
|
158
|
+
end
|
|
159
|
+
else
|
|
160
|
+
@stats_list = stats_interpreted[:valid_data]
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def request_filter_list
|
|
165
|
+
puts "Give a list of conditions that should be met with the player to be included (e.g sacks > 8, pass_touchdowns > 25, team = SEA)"
|
|
166
|
+
filters_input = gets.chomp
|
|
167
|
+
filters_interpreted = interpret_filter_selection(filters_input)
|
|
168
|
+
if(filters_interpreted[:invalid_data].length>0)
|
|
169
|
+
puts "The following entries were invalid and will be discarded"
|
|
170
|
+
filters_interpreted[:invalid_data].each do |entry|
|
|
171
|
+
puts entry[:string]
|
|
172
|
+
end
|
|
173
|
+
puts "Would you like to repeat this step? (y/n)"
|
|
174
|
+
input = gets.chomp
|
|
175
|
+
if(input == "y")
|
|
176
|
+
request_filter_list
|
|
177
|
+
else
|
|
178
|
+
@filter_list = filters_interpreted[:valid_data]
|
|
179
|
+
end
|
|
180
|
+
else
|
|
181
|
+
@filter_list = filters_interpreted[:valid_data]
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def request_sort
|
|
187
|
+
puts "How would you like to sort the data, give a stat and ASC or DESC"
|
|
188
|
+
sort_input = gets.chomp
|
|
189
|
+
sort_interpreted = interpret_sort_selection(sort_input)
|
|
190
|
+
if(sort_interpreted[:return_type] == "invalid_data")
|
|
191
|
+
"Your entry was invlalid and will be discarded"
|
|
192
|
+
puts "Would you like to repeat this step? (y/n)"
|
|
193
|
+
if(input == "y")
|
|
194
|
+
request_sort
|
|
195
|
+
else #default to sort by name ascending
|
|
196
|
+
@sort_stat = "name"
|
|
197
|
+
@sort_value = "ASC"
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
else
|
|
201
|
+
@sort_stat = sort_interpreted[:sort_stat]
|
|
202
|
+
@sort_value = sort_interpreted[:sort_value]
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def interpret_stat_selection(input)
|
|
208
|
+
out = input.strip.split(/[\s,]+/)
|
|
209
|
+
out.unshift("name")
|
|
210
|
+
valid_entries = []
|
|
211
|
+
invalid_entries = []
|
|
212
|
+
|
|
213
|
+
out.each do |attribute|
|
|
214
|
+
if(allows_atribute?(attribute))
|
|
215
|
+
valid_entries.push(attribute.to_sym)
|
|
216
|
+
else
|
|
217
|
+
invalid_entries.push(attribute)
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
:valid_data => valid_entries.uniq,
|
|
223
|
+
:invalid_data => invalid_entries.uniq
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def interpret_filter_selection(input)
|
|
229
|
+
list = input.strip.split(/,+/)
|
|
230
|
+
out = []
|
|
231
|
+
valid_entries = []
|
|
232
|
+
invalid_entries = []
|
|
233
|
+
list.each do |entry|
|
|
234
|
+
hash = {}
|
|
235
|
+
compare_type = entry.match(/[=<>]/)
|
|
236
|
+
if(compare_type == nil)#indicates no compare operator (>, <, =) was found
|
|
237
|
+
hash[:type] = "invalid compare statement"
|
|
238
|
+
hash[:string] = entry
|
|
239
|
+
else
|
|
240
|
+
compare_type = compare_type[0]
|
|
241
|
+
entry_data = entry.gsub(/\s+/, "").split(compare_type)
|
|
242
|
+
if(entry_data.length != 2)#indicates either no stat, no value or too many compare operators
|
|
243
|
+
hash[:type] = "invalid compare statement"
|
|
244
|
+
hash[:string] = entry
|
|
245
|
+
elsif(!allows_atribute?(entry_data[0]))
|
|
246
|
+
hash[:type] = "invalid compare statement"
|
|
247
|
+
hash[:string] = entry
|
|
248
|
+
else
|
|
249
|
+
hash[:type] = "valid compare statement"
|
|
250
|
+
hash[:compare_type] = compare_type
|
|
251
|
+
hash[:stat] = entry_data[0].gsub(/\s+/, "").to_sym
|
|
252
|
+
hash[:value] = entry_data[1].gsub(/\s+/, "").to_f
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
if(hash[:type] == "invalid compare statement")
|
|
256
|
+
invalid_entries.push(hash)
|
|
257
|
+
elsif(hash[:type] == "valid compare statement")
|
|
258
|
+
valid_entries.push(hash)
|
|
259
|
+
end
|
|
260
|
+
out.push(hash[:type] == "invalid compare statement")
|
|
261
|
+
end
|
|
262
|
+
return {
|
|
263
|
+
:valid_data => valid_entries,
|
|
264
|
+
:invalid_data => invalid_entries
|
|
265
|
+
}
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
def interpret_sort_selection(input)
|
|
269
|
+
out = input.strip.split(/[\s,]+/)
|
|
270
|
+
output_data = {}
|
|
271
|
+
if(out.length>2 || !allows_atribute?(out[0]))
|
|
272
|
+
output_data[:return_type] = "invalid data"
|
|
273
|
+
elsif(out.length == 2)
|
|
274
|
+
sort_priority = out[1].upcase
|
|
275
|
+
if(sort_priority != "ASC" && sort_priority != "DESC")
|
|
276
|
+
output_data[:return_type] = "invalid data"
|
|
277
|
+
else
|
|
278
|
+
output_data[:return_type] = "valid data"
|
|
279
|
+
output_data[:sort_stat] = out[0].to_sym
|
|
280
|
+
output_data[:sort_value] = sort_priority
|
|
281
|
+
end
|
|
282
|
+
elsif(out.length == 1)
|
|
283
|
+
output_data[:sort_stat] = out[0].to_sym
|
|
284
|
+
output_data[:sort_value] = "ASC"
|
|
285
|
+
else
|
|
286
|
+
output_data[:sort_stat] = :name
|
|
287
|
+
output_data[:sort_value] = "ASC"
|
|
288
|
+
end
|
|
289
|
+
output_data
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
def allows_atribute?(attribute)
|
|
293
|
+
first_data_instance = player_data[0]
|
|
294
|
+
first_data_instance.has_attribute?(attribute)
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
def print_allowable_attributes
|
|
298
|
+
first_data_instance = player_data[0]
|
|
299
|
+
puts "The following attributes exist in this data set"
|
|
300
|
+
puts "\n"
|
|
301
|
+
current_string = "";
|
|
302
|
+
first_data_instance.class.allowable_attributes.each_with_index do |attribute, i|
|
|
303
|
+
puts attribute
|
|
304
|
+
end
|
|
305
|
+
puts "\n"
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'open-uri'
|
|
2
|
+
class FootballStatsFilterTool::DataScraper
|
|
3
|
+
|
|
4
|
+
def self.scrape_data(url, stat_type)
|
|
5
|
+
html = Nokogiri::HTML(URI.open(url))
|
|
6
|
+
data = html.css('tr:not(.thead)')
|
|
7
|
+
out = []
|
|
8
|
+
data.each do |entry|
|
|
9
|
+
name = entry.css('td[data-stat="player"]').text
|
|
10
|
+
hash = {}
|
|
11
|
+
if(name != "")
|
|
12
|
+
hash[:name] = entry.css('td[data-stat="player"]').text.match(/.*[a-zA-Z]/)[0]#remove excess whitespace and extra characters
|
|
13
|
+
hash[:age] = entry.css('td[data-stat="age"]').text.to_i
|
|
14
|
+
hash[:position] = entry.css('td[data-stat="pos"]').text.upcase
|
|
15
|
+
hash[:team] = entry.css('td[data-stat="team"]').text
|
|
16
|
+
if(stat_type == "passing")
|
|
17
|
+
hash[:pass_completions] = entry.css('td[data-stat="pass_cmp"]').text.to_f
|
|
18
|
+
hash[:pass_attempts] = entry.css('td[data-stat="pass_att"]').text.to_f
|
|
19
|
+
hash[:pass_completion_percentage] = entry.css('td[data-stat="pass_cmp_perc"]').text.to_f
|
|
20
|
+
hash[:pass_touchdowns] = entry.css('td[data-stat="pass_td"]').text.to_f
|
|
21
|
+
hash[:interceptions_thrown] = entry.css('td[data-stat="pass_int"]').text.to_f
|
|
22
|
+
hash[:pass_yards] = entry.css('td[data-stat="pass_yds"]').text.to_f
|
|
23
|
+
hash[:yards_per_pass_attempt] = entry.css('td[data-stat="pass_yds_per_att"]').text.to_f
|
|
24
|
+
elsif(stat_type == "rushing")
|
|
25
|
+
hash[:carries] = entry.css('td[data-stat="rush_att"]').text.to_f
|
|
26
|
+
hash[:rush_yards] = entry.css('td[data-stat="rush_yds"]').text.to_f
|
|
27
|
+
hash[:rush_yards_per_attempt] = entry.css('td[data-stat="rush_yds_per_att"]').text.to_f
|
|
28
|
+
hash[:rush_touchdowns] = entry.css('td[data-stat="rush_td"]').text.to_f
|
|
29
|
+
elsif(stat_type == "receiving")
|
|
30
|
+
hash[:receptions] = entry.css('td[data-stat="rec"]').text.to_f
|
|
31
|
+
hash[:receiving_yards] = entry.css('td[data-stat="rec_yds"]').text.to_f
|
|
32
|
+
hash[:receiving_yards_per_catch] = entry.css('td[data-stat="rec_yds_per_att"]').text.to_f
|
|
33
|
+
hash[:receiving_touchdowns] = entry.css('td[data-stat="rec_td"]').text.to_f
|
|
34
|
+
elsif(stat_type == "defense")
|
|
35
|
+
hash[:interceptions_caught] = entry.css('td[data-stat="def_int"]').text.to_f
|
|
36
|
+
hash[:passes_defended] = entry.css('td[data-stat="pass_defended"]').text.to_f
|
|
37
|
+
hash[:tackles] = entry.css('td[data-stat="tackles_combined"]').text.to_f
|
|
38
|
+
hash[:sacks] = entry.css('td[data-stat="sacks"]').text.to_f
|
|
39
|
+
hash[:tackles_for_loss] = entry.css('td[data-stat="tackles_loss"]').text.to_f
|
|
40
|
+
hash[:quarterback_hits] = entry.css('td[data-stat="qn_hits"]').text.to_f
|
|
41
|
+
end
|
|
42
|
+
out.push(hash)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
return out
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
require_relative "./data_scraper"
|
|
2
|
+
|
|
3
|
+
class FootballStatsFilterTool::Player
|
|
4
|
+
@@allowable_attributes = [
|
|
5
|
+
"name",
|
|
6
|
+
"age",
|
|
7
|
+
"position",
|
|
8
|
+
"team",
|
|
9
|
+
"pass_completions",
|
|
10
|
+
"pass_attempts",
|
|
11
|
+
"pass_completion_percentage",
|
|
12
|
+
"pass_touchdowns",
|
|
13
|
+
"interceptions_thrown",
|
|
14
|
+
"pass_yards",
|
|
15
|
+
"yards_per_pass_attempt",
|
|
16
|
+
"carries",
|
|
17
|
+
"rush_yards",
|
|
18
|
+
"rush_yards_per_attempt",
|
|
19
|
+
"rush_touchdowns",
|
|
20
|
+
"receptions",
|
|
21
|
+
"receiving_yards",
|
|
22
|
+
"receiving_yards_per_catch",
|
|
23
|
+
"receiving_touchdowns",
|
|
24
|
+
"sacks",
|
|
25
|
+
"interceptions_caught",
|
|
26
|
+
"passes_defended",
|
|
27
|
+
"tackles",
|
|
28
|
+
"tackles_for_loss",
|
|
29
|
+
"quarterback_hits",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
@@allowable_attributes.each do |attribute|
|
|
33
|
+
attr_accessor attribute.to_sym
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.allowable_attributes
|
|
37
|
+
@@allowable_attributes
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def has_attribute?(attribute)
|
|
41
|
+
self.class.allowable_attributes.include?(attribute)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
@@all = []
|
|
45
|
+
|
|
46
|
+
def initialize(data_hash)
|
|
47
|
+
data_hash.each {|key, value| self.send(("#{key}="), value)}
|
|
48
|
+
@@all.push(self)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.all
|
|
52
|
+
return @@all
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.delete_all
|
|
56
|
+
all.clear
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def self.find_by_name (name) #returns array of results if multipe are found
|
|
60
|
+
out = nil
|
|
61
|
+
all.select do |player|
|
|
62
|
+
player.name == name
|
|
63
|
+
end
|
|
64
|
+
if(out == nil)
|
|
65
|
+
out_data = {
|
|
66
|
+
:type => "No Results",
|
|
67
|
+
:data => nil
|
|
68
|
+
}
|
|
69
|
+
elsif(out.size == 1)
|
|
70
|
+
out_data = {
|
|
71
|
+
:type => "Unique Result",
|
|
72
|
+
:data => out[0]
|
|
73
|
+
}
|
|
74
|
+
elsif(out.size > 1)
|
|
75
|
+
out_data = {
|
|
76
|
+
:type => "Multiple Results",
|
|
77
|
+
:data => out
|
|
78
|
+
}
|
|
79
|
+
end
|
|
80
|
+
out_data
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def self.find(name, team)
|
|
84
|
+
out = nil
|
|
85
|
+
all.each do |player|
|
|
86
|
+
if(player.name == name && player.team == team)
|
|
87
|
+
out = player
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
return out
|
|
91
|
+
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def self.create_or_update(data_hash)
|
|
97
|
+
name = data_hash[:name]
|
|
98
|
+
team = data_hash[:team]
|
|
99
|
+
find_player = FootballStatsFilterTool::Player.find(name, team)
|
|
100
|
+
if(find_player == nil)
|
|
101
|
+
find_player = FootballStatsFilterTool::Player.new(data_hash)
|
|
102
|
+
else
|
|
103
|
+
data_hash.each do |key, value|
|
|
104
|
+
current_value = find_player.instance_variable_get("@#{key}")
|
|
105
|
+
if(current_value == 0 || current_value = "" || current_value == nil || current_value == 0.0)#ensures not overiding good data
|
|
106
|
+
find_player.send(("#{key}="), value)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
return find_player
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def self.display_all
|
|
114
|
+
all.each do|player|
|
|
115
|
+
if(player.team = "SEA")
|
|
116
|
+
puts "#{player.name}, #{player.position}, #{player.team}"
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def self.import(year)
|
|
122
|
+
url_passing = "https://www.pro-football-reference.com/years/#{year}/passing.htm"
|
|
123
|
+
url_rushing = "https://www.pro-football-reference.com/years/#{year}/rushing.htm"
|
|
124
|
+
url_receiving = "https://www.pro-football-reference.com/years/#{year}/receiving.htm"
|
|
125
|
+
url_defense = "https://www.pro-football-reference.com/years/#{year}/defense.htm"
|
|
126
|
+
|
|
127
|
+
data_passing = FootballStatsFilterTool::DataScraper.scrape_data(url_passing, "passing")
|
|
128
|
+
data_rushing = FootballStatsFilterTool::DataScraper.scrape_data(url_rushing, "rushing")
|
|
129
|
+
data_receiving = FootballStatsFilterTool::DataScraper.scrape_data(url_receiving, "receiving")
|
|
130
|
+
data_defense = FootballStatsFilterTool::DataScraper.scrape_data(url_defense, "defense")
|
|
131
|
+
|
|
132
|
+
data_passing.each{|entry| FootballStatsFilterTool::Player.create_or_update(entry)}
|
|
133
|
+
data_rushing.each{|entry| FootballStatsFilterTool::Player.create_or_update(entry)}
|
|
134
|
+
data_receiving.each{|entry| FootballStatsFilterTool::Player.create_or_update(entry)}
|
|
135
|
+
data_defense.each{|entry| FootballStatsFilterTool::Player.create_or_update(entry)}
|
|
136
|
+
end
|
|
137
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: football_stats_filter_tool
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Fuget
|
|
8
8
|
autorequire:
|
|
9
|
-
bindir:
|
|
9
|
+
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-01-
|
|
11
|
+
date: 2021-01-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: pry
|
|
@@ -52,47 +52,29 @@ dependencies:
|
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '12.0'
|
|
55
|
-
- !ruby/object:Gem::Dependency
|
|
56
|
-
name: rspec
|
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
|
58
|
-
requirements:
|
|
59
|
-
- - "~>"
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: '3.0'
|
|
62
|
-
type: :runtime
|
|
63
|
-
prerelease: false
|
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
-
requirements:
|
|
66
|
-
- - "~>"
|
|
67
|
-
- !ruby/object:Gem::Version
|
|
68
|
-
version: '3.0'
|
|
69
55
|
description: Pulls stats from the current football season and generates filtered and
|
|
70
56
|
sorted lists basaed on user input
|
|
71
57
|
email:
|
|
72
58
|
- michaelfuget@gmail.com
|
|
73
|
-
executables:
|
|
59
|
+
executables:
|
|
60
|
+
- football-stats-filter-tool
|
|
74
61
|
extensions: []
|
|
75
62
|
extra_rdoc_files: []
|
|
76
63
|
files:
|
|
77
|
-
-
|
|
78
|
-
-
|
|
79
|
-
- ".rspec"
|
|
80
|
-
- Gemfile
|
|
81
|
-
- LICENSE.txt
|
|
82
|
-
- README.md
|
|
83
|
-
- Rakefile
|
|
84
|
-
- bin/console
|
|
85
|
-
- bin/setup
|
|
86
|
-
- football_stats_filter_tool.gemspec
|
|
64
|
+
- bin/football-stats-filter-tool
|
|
65
|
+
- config/environment.rb
|
|
87
66
|
- lib/football_stats_filter_tool.rb
|
|
67
|
+
- lib/football_stats_filter_tool/command_line_interface.rb
|
|
68
|
+
- lib/football_stats_filter_tool/data_scraper.rb
|
|
69
|
+
- lib/football_stats_filter_tool/player.rb
|
|
88
70
|
- lib/football_stats_filter_tool/version.rb
|
|
89
|
-
homepage: https://github.com/mkfuget/Football-Stats-Filter-CLI-
|
|
71
|
+
homepage: https://github.com/mkfuget/Football-Stats-Filter-CLI-3.0
|
|
90
72
|
licenses:
|
|
91
73
|
- MIT
|
|
92
74
|
metadata:
|
|
93
75
|
allowed_push_host: https://rubygems.org/
|
|
94
|
-
homepage_uri: https://github.com/mkfuget/Football-Stats-Filter-CLI-
|
|
95
|
-
source_code_uri: https://github.com/mkfuget/Football-Stats-Filter-CLI-
|
|
76
|
+
homepage_uri: https://github.com/mkfuget/Football-Stats-Filter-CLI-3.0
|
|
77
|
+
source_code_uri: https://github.com/mkfuget/Football-Stats-Filter-CLI-3.0
|
|
96
78
|
post_install_message:
|
|
97
79
|
rdoc_options: []
|
|
98
80
|
require_paths:
|
|
@@ -101,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
101
83
|
requirements:
|
|
102
84
|
- - ">="
|
|
103
85
|
- !ruby/object:Gem::Version
|
|
104
|
-
version: 2.
|
|
86
|
+
version: 2.3.0
|
|
105
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
88
|
requirements:
|
|
107
89
|
- - ">="
|
data/.github/workflows/main.yml
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
name: Ruby
|
|
2
|
-
|
|
3
|
-
on: [push,pull_request]
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
build:
|
|
7
|
-
runs-on: ubuntu-latest
|
|
8
|
-
steps:
|
|
9
|
-
- uses: actions/checkout@v2
|
|
10
|
-
- name: Set up Ruby
|
|
11
|
-
uses: ruby/setup-ruby@v1
|
|
12
|
-
with:
|
|
13
|
-
ruby-version: 2.7.1
|
|
14
|
-
- name: Run the default task
|
|
15
|
-
run: |
|
|
16
|
-
gem install bundler -v 2.2.4
|
|
17
|
-
bundle install
|
|
18
|
-
bundle exec rake
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/Gemfile
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
source "https://rubygems.org"
|
|
4
|
-
|
|
5
|
-
# Specify your gem's dependencies in football_stats_filter_tool.gemspec
|
|
6
|
-
gemspec
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
ruby '2.7.0'
|
|
10
|
-
gem 'pry'
|
|
11
|
-
gem 'nokogiri', '1.10.8'
|
|
12
|
-
gem "rake", "~> 12.0"
|
|
13
|
-
gem "rspec", "~> 3.0"
|
data/LICENSE.txt
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 mkfuget
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
data/README.md
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# FootballStatsFilterTool
|
|
2
|
-
|
|
3
|
-
This is a CLI program that allows users to pull stats from NFL players filtert them down based on conditions and show sorted lists
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
Add this line to your application's Gemfile:
|
|
8
|
-
|
|
9
|
-
```ruby
|
|
10
|
-
gem 'football_stats_filter_tool'
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
And then execute:
|
|
14
|
-
|
|
15
|
-
$ bundle install
|
|
16
|
-
|
|
17
|
-
Or install it yourself as:
|
|
18
|
-
|
|
19
|
-
$ gem install football_stats_filter_tool
|
|
20
|
-
|
|
21
|
-
## Usage
|
|
22
|
-
|
|
23
|
-
TODO: Write usage instructions here
|
|
24
|
-
|
|
25
|
-
## Development
|
|
26
|
-
|
|
27
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
28
|
-
|
|
29
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
30
|
-
|
|
31
|
-
## Contributing
|
|
32
|
-
|
|
33
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/football_stats_filter_tool.
|
|
34
|
-
|
|
35
|
-
## License
|
|
36
|
-
|
|
37
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
DELETED
data/bin/console
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require "bundler/setup"
|
|
5
|
-
require "football_stats_filter_tool"
|
|
6
|
-
|
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
-
|
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
-
# require "pry"
|
|
12
|
-
# Pry.start
|
|
13
|
-
|
|
14
|
-
require "irb"
|
|
15
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "lib/football_stats_filter_tool/version"
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name = "football_stats_filter_tool"
|
|
7
|
-
spec.version = FootballStatsFilterTool::VERSION
|
|
8
|
-
spec.authors = ["Michael Fuget"]
|
|
9
|
-
spec.email = ["michaelfuget@gmail.com"]
|
|
10
|
-
|
|
11
|
-
spec.summary = "Football Stats filter tool 2.3"
|
|
12
|
-
spec.description = "Pulls stats from the current football season and generates filtered and sorted lists basaed on user input"
|
|
13
|
-
spec.homepage = "https://github.com/mkfuget/Football-Stats-Filter-CLI-2.0"
|
|
14
|
-
spec.license = "MIT"
|
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
|
16
|
-
|
|
17
|
-
spec.metadata["allowed_push_host"] = 'https://rubygems.org/'
|
|
18
|
-
|
|
19
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
|
20
|
-
spec.metadata["source_code_uri"] = "https://github.com/mkfuget/Football-Stats-Filter-CLI-2.0"
|
|
21
|
-
|
|
22
|
-
# Specify which files should be added to the gem when it is released.
|
|
23
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
24
|
-
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
25
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
|
26
|
-
end
|
|
27
|
-
spec.bindir = "exe"
|
|
28
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
29
|
-
spec.require_paths = ["lib"]
|
|
30
|
-
|
|
31
|
-
# Uncomment to register a new dependency of your gem
|
|
32
|
-
# spec.add_dependency "example-gem", "~> 1.0"
|
|
33
|
-
|
|
34
|
-
spec.add_dependency 'pry'
|
|
35
|
-
spec.add_dependency 'nokogiri', '1.10.8'
|
|
36
|
-
spec.add_dependency "rake", "~> 12.0"
|
|
37
|
-
spec.add_dependency "rspec", "~> 3.0"
|
|
38
|
-
|
|
39
|
-
# For more information and examples about making a new gem, checkout our
|
|
40
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
|
41
|
-
end
|