big_3 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 31c886aa17a5b0b9b20b077fc79ee05460c69613
4
+ data.tar.gz: 359f1002c985c3ba9637dbb44b7a8f703f2a24e4
5
+ SHA512:
6
+ metadata.gz: 59355c372c4b86c01b75759e808ecc53d91e55524ce99ca07927afa831027e2fe34975b13d45d30917bba26573773526b2b5e70fe13067599076de9c7b0f7d27
7
+ data.tar.gz: 6536738c64778db9f06b2804cd848583570510e31cad803ffe4cf7a08785f82b0812827e6ba3abcb19a53ccafdebee35d62697367ca24ca7fa94a0cf14f54216
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.15.4
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Anthony
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.
@@ -0,0 +1,57 @@
1
+ # Big3
2
+
3
+ Big3 adds stats from all games played in the Big3 basketball league. This includes:
4
+
5
+ * Team stats
6
+ * Player stats
7
+ * Season averages
8
+ * Scores
9
+ * Rosters
10
+
11
+
12
+ ## Installation
13
+
14
+ $ gem install big_3
15
+
16
+ ## Usage
17
+
18
+ ```ruby
19
+ big_3 = Big3::League.new
20
+ all_games = big_3.team_stats["games"]
21
+ # => Returns a hash containing team stats and scores from all games
22
+ ```
23
+
24
+ Filtering games by team name
25
+
26
+ ```ruby
27
+ big_3.team_name = "Ball Hogs"
28
+ ```
29
+
30
+ Viewing individual player stats
31
+
32
+ ```ruby
33
+ big_3.player_name = "Moochie Norris"
34
+ big_3.player_stats["season"] # season averages
35
+ # => {"@min"=>"5.67", "@fga"=>"1.67", "@fgm"=>"0.33", "@fga3"=>"1.33", "@fgm3"=>"0.33", "@fga4"=>"0.0", "@fgm4"=>"0.0", "@fta2"=>"0.67", "@ftm2"=>"0.0", "@fta3"=>"0.0", "@ftm3"=>"0.0", "@fta4"=>"0.0", "@ftm4"=>"0.0", "@fta1"=>"0.0", "@ftm1"=>"0.0", "@fta"=>"0.67", "@ftm"=>"0.0", "@treb"=>"1.33", "@oreb"=>"0.33", "@dreb"=>"1.0", "@ast"=>"0.67", "@stl"=>"0.67", "@blk"=>"0.0", "@pf"=>"1.0", "@tp"=>"1.0", "@eff"=>"1.67", "@net"=>"23.87", "@plusminus"=>"-3.33", "@to"=>"0.67"}
36
+ ```
37
+
38
+ Optional parameters
39
+
40
+ ```ruby
41
+ Big3::League.new(team_name: "Trilogy", player_name: "Mike Bibby")
42
+ ```
43
+
44
+ Finding teams and players
45
+
46
+ ```ruby
47
+ big_3.rosters
48
+ # => {"3 Headed Monsters"=>["Rashard Lewis", "Kwame Brown", "Eddie Basden", "Hakim Warrick", "Mahmoud Abdul-Rauf", "Jason Williams", "Kareem Rush"], .etc}
49
+ ```
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aseli1/big_3.
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "big_3/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "big_3"
8
+ spec.version = Big3::VERSION
9
+ spec.authors = ["Anthony"]
10
+ spec.email = ["anthony.seliga@gmail.com"]
11
+
12
+ spec.summary = %q{Big3 statistics}
13
+ spec.description = %q{Team and player statistics from the Big3 basketball league.}
14
+ spec.homepage = "https://github.com/aseli1/Big3.git"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = 'https://rubygems.org'
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib","lib/big_3"]
32
+
33
+ spec.add_runtime_dependency "nokogiri", "~> 1.6"
34
+ spec.add_runtime_dependency "nori", "~> 2.6"
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.15"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "minitest", "~> 5.0"
39
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "big_3"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ require "big_3/version"
2
+ require "big_3/league"
3
+ require "big_3/game_manager"
4
+ require "big_3/game"
5
+
6
+ module Big3
7
+
8
+ end
@@ -0,0 +1,64 @@
1
+ module Big3
2
+ class Game
3
+ attr_accessor :id, :url, :information, :stats, :home_team, :home_team_name, :home_team_players, :away_team, :away_team_name, :away_team_players
4
+
5
+ def initialize(id)
6
+ @id = id
7
+ end
8
+
9
+ def url
10
+ @url = "http://archive.statbroadcast.com/#{id}.xml"
11
+ @url
12
+ end
13
+
14
+ def information
15
+ @information = Nokogiri::XML(open(url)).to_s
16
+ @information
17
+ end
18
+
19
+ def stats
20
+ parser = Nori.new
21
+ parser = parser.parse(information)['bbgame']
22
+ @stats = parser
23
+ end
24
+
25
+ def home_team
26
+ @home_team = stats["team"][1]
27
+ end
28
+
29
+ def home_team_name
30
+ @home_team_name = stats["team"][1]["@name"]
31
+ end
32
+
33
+ def home_team_players
34
+ @home_team_players = stats["team"][1]["player"]
35
+ end
36
+
37
+ def away_team
38
+ @away_team = stats["team"][0]
39
+ end
40
+
41
+ def away_team_players
42
+ @away_team_players = stats["team"][0]["player"]
43
+ end
44
+
45
+ def away_team_name
46
+ @away_team_name = stats["team"][0]["@name"]
47
+ end
48
+
49
+ def venue
50
+ @venue = stats['venue']
51
+ @venue
52
+ end
53
+
54
+ def location
55
+ @location = stats["venue"]["@location"]
56
+ @location
57
+ end
58
+
59
+ def date
60
+ @date = stats["venue"]["@date"]
61
+ @date
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,15 @@
1
+ module Big3
2
+ class GameManager
3
+ attr_accessor :ids
4
+
5
+ def initialize(args={})
6
+ @ids = args[:ids]
7
+ end
8
+
9
+ def create_games
10
+ unordered_games = ids.map { |id| Game.new(id) }
11
+ games = unordered_games.sort! { |a, b| a.date <=> b.date }
12
+ games
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,193 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'nori'
4
+
5
+ module Big3
6
+ class League
7
+ attr_accessor :games, :game_ids, :game_stats, :player_name, :player_stats, :team_name, :p_s, :t_s
8
+
9
+ def initialize(args={})
10
+ @player_name = args[:player_name] ||= nil
11
+ @team_name = args[:team_name] ||= nil
12
+ retrieve_game_data
13
+ end
14
+
15
+ def team_stats
16
+ @t_s = Hash.new { |h, k| h[k] = [] }
17
+ @t_s["season"] = Hash.new { |h, k| h[k] = 0 }
18
+ game_stats.each.with_index(1) do |teams, game_count|
19
+ scores = {}
20
+ if team_name.nil?
21
+ add_scoring(scores, teams.away_team, teams.home_team)
22
+ add_stats(scores, teams.away_team, teams.home_team, t_s, teams.location, game_count)
23
+ else
24
+ filter_team_stats(scores, teams.away_team, teams.home_team, t_s, teams.away_team, teams.location, game_count)
25
+ end
26
+ end
27
+ unless team_name.nil?
28
+ find_season_averages(t_s)
29
+ else
30
+ @t_s.delete("season")
31
+ end
32
+ @t_s
33
+ end
34
+
35
+ def player_stats
36
+ unless player_name.nil?
37
+ @p_s = Hash.new { |hash, key| hash[key] = [] }
38
+ @p_s["season"] = Hash.new { |hash, key| hash[key] = 0 }
39
+ game_stats.each do |teams|
40
+ parse_game_stats(teams.away_team_players, p_s, teams.location)
41
+ parse_game_stats(teams.home_team_players, p_s, teams.location)
42
+ end
43
+ find_season_averages(p_s)
44
+ @p_s
45
+ else
46
+ raise NameError, "player_name is not defined"
47
+ end
48
+ end
49
+
50
+ def parse_game_stats(players,
51
+ stats,
52
+ location)
53
+ players.each do |player|
54
+ if names_match?(player, player_name)
55
+ stats["games"] << { "stats" => player["stats"],
56
+ "location" => location,
57
+ "game_number" => "#{stats["games"].length + 1}" }
58
+ player["stats"].each do |k, v|
59
+ v = v.to_f
60
+ stats["season"][k] += v
61
+ end
62
+ else
63
+ next
64
+ end
65
+ end
66
+ end
67
+
68
+ def add_scoring(scores,
69
+ away_team,
70
+ home_team)
71
+ scores["first half"] = { "home" => home_team['linescore']["lineprd"][0]["@score"],
72
+ "away" => away_team['linescore']["lineprd"][0]["@score"] }
73
+ scores["second half"] = { "home" => home_team['linescore']["lineprd"][1]["@score"],
74
+ "away" => away_team['linescore']["lineprd"][1]["@score"] }
75
+ scores["final"] = { "home" => home_team['linescore']["@score"],
76
+ "away" => away_team['linescore']["@score"] }
77
+ end
78
+
79
+ def add_stats_to_season(stats,
80
+ team)
81
+ team["totals"]["stats"].each do |k, v|
82
+ v = v.to_f
83
+ stats["season"][k] += v
84
+ end
85
+ end
86
+
87
+ def find_season_averages(stats)
88
+ stats["season"].each do |k, v|
89
+ average = v / stats["games"].length
90
+ stats["season"][k] = average.round(2).to_s
91
+ end
92
+ end
93
+
94
+ def add_game(scores,
95
+ away_team,
96
+ home_team,
97
+ stats,
98
+ season_team,
99
+ location,
100
+ game_count)
101
+ add_scoring(scores, away_team, home_team)
102
+ add_stats(scores, away_team, home_team, stats, location, game_count)
103
+ add_stats_to_season(stats, season_team)
104
+ end
105
+
106
+ def names_match?(item,
107
+ passed_item)
108
+ item["@name"].gsub(/[^A-Za-z]/, "").downcase == passed_item.gsub(/[^A-Za-z]/, "").downcase
109
+ end
110
+
111
+ def add_stats(scores,
112
+ away_team,
113
+ home_team,
114
+ stats,
115
+ location,
116
+ game_count)
117
+ from_both_teams = { "home" => home_team["totals"]["stats"],
118
+ "away" => away_team["totals"]["stats"] }
119
+ stats["games"] << { "matchup" => "#{home_team["@name"]} vs #{away_team["@name"]}",
120
+ "home team" => home_team["@name"],
121
+ "away team" => away_team["@name"],
122
+ "scores" => scores,
123
+ "stats" => from_both_teams,
124
+ "location" => location,
125
+ "game_number" => game_count.to_s }
126
+ end
127
+
128
+ def filter_team_stats(scores,
129
+ away_team,
130
+ home_team,
131
+ stats,
132
+ season_team,
133
+ location,
134
+ game_count)
135
+ stats["name"] = team_name.split.map(&:capitalize).join(' ')
136
+ if names_match?(away_team, team_name)
137
+ add_game(scores, away_team, home_team, stats, season_team, location, game_count)
138
+ elsif names_match?(home_team, team_name)
139
+ add_game(scores, away_team, home_team, stats, season_team, location, game_count)
140
+ end
141
+ end
142
+
143
+ def games
144
+ events_page = Nokogiri::HTML(open("http://statbroadcast.com/events/archive.php?gid=bigthr"))
145
+ @games = events_page.css(".bcs_newsarticle_link")
146
+ @games
147
+ end
148
+
149
+ def game_ids
150
+ @game_ids = games.map { |entry| entry['href'].to_s.gsub("archived.php?id=", "")}
151
+ @game_ids.pop
152
+ @game_ids
153
+ end
154
+
155
+ def retrieve_game_data
156
+ @game_stats = GameManager.new({ids: game_ids}).create_games
157
+ @game_stats
158
+ end
159
+
160
+ def teams
161
+ @teams = ["Tri State", "Killer 3s", "Ball Hogs", "3 Headed Monsters", "Trilogy", "Power", "Ghost Ballers", "3's Company"]
162
+ @teams
163
+ end
164
+
165
+ def rosters
166
+ @rosters ||= find_rosters
167
+ end
168
+
169
+ def find_rosters
170
+ @rosters = Hash.new { |h, k| h[k] = [] }
171
+ game_stats.each do |team|
172
+ add_players(team.away_team_players, team.away_team_name, rosters)
173
+ add_players(team.home_team_players, team.home_team_name, rosters)
174
+ end
175
+ @rosters
176
+ end
177
+
178
+ def add_players(players,
179
+ team_name,
180
+ league)
181
+ players.each do |player|
182
+ team_name = team_name.sub("3s","3's")
183
+ player_name = player['@name']
184
+ player_name = player_name.sub("Mahmoud-","Mahmoud ")
185
+ if teams.include?(player_name) || player_name.include?("TEAM") || league[team_name].include?(player_name)
186
+ next
187
+ else
188
+ league[team_name] << player_name
189
+ end
190
+ end
191
+ end
192
+ end
193
+ end
@@ -0,0 +1,3 @@
1
+ module Big3
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: big_3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Anthony
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nori
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description: Team and player statistics from the Big3 basketball league.
84
+ email:
85
+ - anthony.seliga@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - big_3.gemspec
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/big_3.rb
100
+ - lib/big_3/game.rb
101
+ - lib/big_3/game_manager.rb
102
+ - lib/big_3/league.rb
103
+ - lib/big_3/version.rb
104
+ homepage: https://github.com/aseli1/Big3.git
105
+ licenses:
106
+ - MIT
107
+ metadata:
108
+ allowed_push_host: https://rubygems.org
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ - lib/big_3
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.6.8
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Big3 statistics
130
+ test_files: []