nba-stats 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nba_stats/cli.rb +27 -20
- data/lib/nba_stats/player.rb +2 -1
- data/lib/nba_stats/scraper.rb +12 -17
- data/lib/nba_stats/team.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e43371a99a71996e7735c6e5c2fd02912bc8a00f
|
4
|
+
data.tar.gz: 03a7804220468aafb1ec96a3e7d93c903add0b33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e00aece67b40ab210427da70d05aecb1914983126fe1ed95c287d0c41975be3ac4dc6b80eea60e202b671ceb0257aa55631d195715808666f4e479c778109b52
|
7
|
+
data.tar.gz: 80074837c175dcd034201eeb9104bdd5076bd425767ba2c417d4d40f391cef44fd0404b4cce9636846c89a80129e00432edff0b451367011d16384ccbfcaa893
|
data/lib/nba_stats/cli.rb
CHANGED
@@ -10,20 +10,7 @@ class NbaStats::CLI
|
|
10
10
|
puts "Input exit to leave this program."
|
11
11
|
puts "Here's the list of current teams"
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
rows = [["Eastern Conference", "Western Conference"]]
|
16
|
-
west_teams = NbaStats::Team.western_names
|
17
|
-
east_teams = NbaStats::Team.eastern_names
|
18
|
-
|
19
|
-
i = 0
|
20
|
-
while i < 15
|
21
|
-
rows << [east_teams[i], west_teams[i]]
|
22
|
-
i += 1
|
23
|
-
end
|
24
|
-
|
25
|
-
team_table = Terminal::Table.new rows: rows
|
26
|
-
puts team_table
|
13
|
+
display_teams
|
27
14
|
|
28
15
|
input = ""
|
29
16
|
while input != "exit"
|
@@ -52,27 +39,47 @@ class NbaStats::CLI
|
|
52
39
|
NbaStats::Team.create_from_collection(teams_array)
|
53
40
|
end
|
54
41
|
|
42
|
+
def display_teams
|
43
|
+
make_teams if NbaStats::Team.all.empty?
|
44
|
+
|
45
|
+
rows = [["Eastern Conference", "Western Conference"]]
|
46
|
+
west_teams = NbaStats::Team.western_names
|
47
|
+
east_teams = NbaStats::Team.eastern_names
|
48
|
+
|
49
|
+
i = 0
|
50
|
+
while i < 15
|
51
|
+
rows << [east_teams[i], west_teams[i]]
|
52
|
+
i += 1
|
53
|
+
end
|
54
|
+
|
55
|
+
puts Terminal::Table.new rows: rows
|
56
|
+
end
|
57
|
+
|
55
58
|
def display_roster(requested_team)
|
56
59
|
team = NbaStats::Team.all.detect {|team| team.name == requested_team}
|
60
|
+
|
57
61
|
team.add_players if team.players.empty?
|
62
|
+
|
58
63
|
puts team.name + " roster:"
|
64
|
+
|
59
65
|
rows = [["Number", "Name", "Position", "Height", "Experience"]]
|
60
66
|
team.players.each do |player|
|
61
67
|
rows << [player.number, player.name, player.position, player.height, player.experience]
|
62
68
|
end
|
63
|
-
|
64
|
-
puts
|
69
|
+
|
70
|
+
puts Terminal::Table.new rows: rows
|
65
71
|
end
|
66
72
|
|
67
73
|
def display_player_stats(requested_player)
|
68
74
|
player = NbaStats::Player.all.detect {|player| player.name == requested_player}
|
69
|
-
|
70
|
-
player.add_player_stats
|
75
|
+
|
76
|
+
player.add_player_stats
|
77
|
+
|
71
78
|
rows = [["Points/Game", "Assists/Game", "Rebounds/Game", "Blocks/Game", "Steals/Game", "FG%", "3P%", "FT%", "Minutes/Game",]]
|
72
79
|
rows << [player.points_pg, player.assists_pg, player.rebounds_pg, player.blocks_pg, player.steals_pg, player.fg_percentage, player.three_percentage, player.ft_percentage, player.minutes_pg]
|
80
|
+
|
73
81
|
puts "Here are #{player.name}'s 2015-16 stats: "
|
74
|
-
|
75
|
-
puts stats_table
|
82
|
+
puts Terminal::Table.new rows: rows
|
76
83
|
end
|
77
84
|
|
78
85
|
end
|
data/lib/nba_stats/player.rb
CHANGED
data/lib/nba_stats/scraper.rb
CHANGED
@@ -17,7 +17,7 @@ class NbaStats::Scraper
|
|
17
17
|
assigned_teams = []
|
18
18
|
teams.each do |team|
|
19
19
|
name = team.text
|
20
|
-
team_url = "http://www.basketball-reference.com"+ team["href"]
|
20
|
+
team_url = "http://www.basketball-reference.com" + team["href"]
|
21
21
|
hash = {name: name, team_url: team_url, conference: conference}
|
22
22
|
assigned_teams << hash unless assigned_teams.include? hash
|
23
23
|
end
|
@@ -35,11 +35,7 @@ class NbaStats::Scraper
|
|
35
35
|
position = data_array[3]
|
36
36
|
height = data_array[4]
|
37
37
|
data_array[8] == "R" ? experience = "Rookie" : experience = data_array[8] + " Years"
|
38
|
-
|
39
|
-
#Below is messy workaround
|
40
|
-
#Cleaner player.css("a").first["href"] works outside of .each loop, but returns "undefined method '[]' for nil" inside .each
|
41
|
-
player_url = player.css("a").map {|element| element["href"]}.first
|
42
|
-
player_url = "http://www.basketball-reference.com" + player_url.to_s
|
38
|
+
player_url = "http://www.basketball-reference.com" + player.css("a").first["href"]
|
43
39
|
|
44
40
|
hash = {name: name, number: number, position: position, height: height, experience: experience, player_url: player_url}
|
45
41
|
players_array << hash
|
@@ -51,18 +47,17 @@ class NbaStats::Scraper
|
|
51
47
|
page = open_page(player.player_url)
|
52
48
|
|
53
49
|
season = page.css("table#per_game tr.full_table").last
|
54
|
-
stats_array = season.text.
|
55
|
-
|
50
|
+
stats_array = season.text.split("\n").map {|x| x.strip}
|
56
51
|
stats_hash = {
|
57
|
-
points_pg: stats_array[
|
58
|
-
assists_pg: stats_array[
|
59
|
-
rebounds_pg: stats_array[
|
60
|
-
blocks_pg: stats_array[
|
61
|
-
steals_pg: stats_array[
|
62
|
-
minutes_pg: stats_array[
|
63
|
-
fg_percentage: stats_array[
|
64
|
-
three_percentage: stats_array[
|
65
|
-
ft_percentage: stats_array[
|
52
|
+
points_pg: stats_array[30],
|
53
|
+
assists_pg: stats_array[25],
|
54
|
+
rebounds_pg: stats_array[24],
|
55
|
+
blocks_pg: stats_array[27],
|
56
|
+
steals_pg: stats_array[26],
|
57
|
+
minutes_pg: stats_array[8],
|
58
|
+
fg_percentage: stats_array[11],
|
59
|
+
three_percentage: stats_array[14],
|
60
|
+
ft_percentage: stats_array[21]
|
66
61
|
}
|
67
62
|
|
68
63
|
end
|
data/lib/nba_stats/team.rb
CHANGED