From 7dc2792303b6b12aa294a3f7f8b455d2bc936049 Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Mon, 29 Jul 2024 20:20:19 -0600 Subject: [PATCH 01/97] Initial commit --- README.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1273090ee6..70a625ef4e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,52 @@ # Futbol -Starter repository for the [Turing School](https://turing.io/) Futbol project. +## Deliverables + +**Outline of Check-ins** + * We are planning on having a standup meeting 30 minutes before class, as well as a daily post class check in. + * We plan on a larger meeting to redefine DTR on friday(tentatively). + +**Plan Organization** + * We are utilizing Github Project as our primary organization source. + * [Link to Github Project](https://github.com/users/kylomite/projects/3/views/1) + * Using Google Docs to organize more qualitative team building points. + * [Link to Google Doc](https://docs.google.com/document/d/15GMwPuLY4e56yfuwuGLphfTAbCh9uTJGeSz-cAkhpqg/edit) + * Frequent communication via Slack will be the standard. + +**Project Organizer Discussion** + * When discussing the project organization tool, we considered Mirrorboard and Github Projects, but ultimately chose Github Projects due to its utility and seamless integration with our repository. + * We all agreed Github Project is most likely the industry standard and it would behoove us to familiarize ourselves with the application. + +**Code Design** + * Expand upon this. + * We have implemented a style guide to adhere to for consistency. + * [Link to Style Guide](https://docs.google.com/document/d/1AS3GIR84IMyoNUbN8eiSnuM3o6o9fscvlKvjhJSxokc/edit) + +**DTRs** + * [First DTR 7/29/24](https://docs.google.com/document/d/1HEdpmbyhJbeJtJJ8pkOvZ5zeb07FeqkCZlBai6aSP0s/edit) + + + +## Contributors + +* **Chirchirillo, Joe** + * [Github](https://github.com/jchirch) + * [LinkedIn](https://www.linkedin.com/in/joe-chirchirillo-a73b09318/) + +* **Delaney, Kyle** + * [Github](https://github.com/kylomite) + * [LinkedIn](https://www.linkedin.com/in/kyle-delaney-115164172/edit/forms/next-action/after-connect-add-position/) + +* **Hill, John** + * [Github](https://github.com/jphill19) + * [LinkedIn](https://www.linkedin.com/in/john-hill-309715245/) + +* **Thompson, Shawn** + * [Github](https://github.com/SThompson05) + * [LinkedIn](https://www.linkedin.com/in/shawn-thompson-16956267/) + +* **Willett, Bryan** + * [Github](https://github.com/bwillett2003) + * [LinkedIn](https://www.youtube.com/watch?v=ub82Xb1C8os&ab_channel=JuiceboxHero) + + From fd61c3e403e068baacc2fd3328985ab2e43442b2 Mon Sep 17 00:00:00 2001 From: John Hill Date: Tue, 30 Jul 2024 08:27:05 -0600 Subject: [PATCH 02/97] Add: gemfile --- Gemfile | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Gemfile diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..22287a6025 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gem 'rspec' +gem 'simplecov' \ No newline at end of file From eb21b4b9d0a2381039b09974d49b06b03e0f32ac Mon Sep 17 00:00:00 2001 From: John Hill Date: Tue, 30 Jul 2024 08:27:16 -0600 Subject: [PATCH 03/97] Add: spec_helper.rb --- spec/spec_helper.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 spec/spec_helper.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000000..e69de29bb2 From d7bd802433738c6989592e96c14c819c366b6dc5 Mon Sep 17 00:00:00 2001 From: John Hill Date: Tue, 30 Jul 2024 11:21:45 -0600 Subject: [PATCH 04/97] Feat: add simplecov require & .gitignore --- .gitignore | 55 +++++++++++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 3 +++ 2 files changed, 58 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..f8e92c116f --- /dev/null +++ b/.gitignore @@ -0,0 +1,55 @@ +# Ignore bundler config +/.bundle + +# Ignore the SimpleCov coverage directory +/coverage + +# Ignore logs and temp files +/log/* +!/log/.keep +/tmp +/pids + +# Ignore Byebug command history file. +.byebug_history + +# Ignore SQLite database files +*.sqlite3 +*.sqlite3-journal + +# Ignore Node modules (if you're using Node.js with your Ruby project) +/node_modules + +# Ignore Yarn lock file (if you're using Yarn) +/yarn.lock + +# Ignore the .env file containing environment variables +.env + +# Ignore OSX and Linux file system files +.DS_Store +*.swp + +# Ignore RSpec example metadata +.rspec_example +.rspec_status + +# Ignore Ruby version management files +.ruby-version +.ruby-gemset + +# Ignore coverage results from Code Climate +/.resultset.json + +# Ignore coverage results from SimpleCov +/coverage/ + +# Ignore installed dependencies in vendor/bundle +/vendor/bundle + +# Ignore the Gemfile.lock file if you're not committing it +# Gemfile.lock + +# Ignore project-specific artifacts +/.idea +/.vscode diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e69de29bb2..a93d2421bf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -0,0 +1,3 @@ +require 'simplecov' +SimpleCov.start +### Require your class files below here vvv ### From 4ca7fc738f2eff2aa4264ac2bdc8cfb51d5b268e Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Tue, 30 Jul 2024 16:08:23 -0400 Subject: [PATCH 05/97] feat- set up structure for StatTracker --- Gemfile.lock | 35 +++++++++++++++++++++++ README.md | 68 ++++++++++++++++++++++----------------------- lib/stat_tracker.rb | 22 +++++++++++++++ runner.rb | 13 +++++++++ 4 files changed, 103 insertions(+), 35 deletions(-) create mode 100644 Gemfile.lock create mode 100644 lib/stat_tracker.rb create mode 100644 runner.rb diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000..29a2d02d2d --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,35 @@ +GEM + remote: https://rubygems.org/ + specs: + diff-lcs (1.5.1) + docile (1.4.1) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + simplecov (0.22.0) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) + +PLATFORMS + arm64-darwin-22 + ruby + +DEPENDENCIES + rspec + simplecov + +BUNDLED WITH + 2.5.13 diff --git a/README.md b/README.md index 70a625ef4e..3f67a6f9e4 100644 --- a/README.md +++ b/README.md @@ -2,51 +2,49 @@ ## Deliverables -**Outline of Check-ins** - * We are planning on having a standup meeting 30 minutes before class, as well as a daily post class check in. - * We plan on a larger meeting to redefine DTR on friday(tentatively). + **Outline of Check-ins** + * We are planning on having a standup meeting 30 minutes before class, as well as a daily post class check in. + * We plan on a larger meeting to redefine DTR on friday(tentatively). -**Plan Organization** - * We are utilizing Github Project as our primary organization source. - * [Link to Github Project](https://github.com/users/kylomite/projects/3/views/1) - * Using Google Docs to organize more qualitative team building points. - * [Link to Google Doc](https://docs.google.com/document/d/15GMwPuLY4e56yfuwuGLphfTAbCh9uTJGeSz-cAkhpqg/edit) - * Frequent communication via Slack will be the standard. + **Plan Organization** + * We are utilizing Github Project as our primary organization source. + * [Link to Github Project](https://github.com/users/kylomite/projects/3/views/1) + * Using Google Docs to organize more qualitative team building points. + * [Link to Google Doc](https://docs.google.com/document/d/15GMwPuLY4e56yfuwuGLphfTAbCh9uTJGeSz-cAkhpqg/edit) + * Frequent communication via Slack will be the standard. -**Project Organizer Discussion** - * When discussing the project organization tool, we considered Mirrorboard and Github Projects, but ultimately chose Github Projects due to its utility and seamless integration with our repository. - * We all agreed Github Project is most likely the industry standard and it would behoove us to familiarize ourselves with the application. - -**Code Design** - * Expand upon this. - * We have implemented a style guide to adhere to for consistency. - * [Link to Style Guide](https://docs.google.com/document/d/1AS3GIR84IMyoNUbN8eiSnuM3o6o9fscvlKvjhJSxokc/edit) - -**DTRs** - * [First DTR 7/29/24](https://docs.google.com/document/d/1HEdpmbyhJbeJtJJ8pkOvZ5zeb07FeqkCZlBai6aSP0s/edit) + **Project Organizer Discussion** + * When discussing the project organization tool, we considered Mirrorboard and Github Projects, but ultimately chose Github Projects due to its utility and seamless integration with our repository. + * We all agreed Github Project is most likely the industry standard and it would behoove us to familiarize ourselves with the application. + **Code Design** + * Expand upon this. + * We have implemented a style guide to adhere to for consistency. + * [Link to Style Guide](https://docs.google.com/document/d/1AS3GIR84IMyoNUbN8eiSnuM3o6o9fscvlKvjhJSxokc/edit) + **DTRs** + * [First DTR 7/29/24](https://docs.google.com/document/d/1HEdpmbyhJbeJtJJ8pkOvZ5zeb07FeqkCZlBai6aSP0s/edit) ## Contributors -* **Chirchirillo, Joe** - * [Github](https://github.com/jchirch) - * [LinkedIn](https://www.linkedin.com/in/joe-chirchirillo-a73b09318/) + * **Chirchirillo, Joe** + * [Github](https://github.com/jchirch) + * [LinkedIn](https://www.linkedin.com/in/joe-chirchirillo-a73b09318/) -* **Delaney, Kyle** - * [Github](https://github.com/kylomite) - * [LinkedIn](https://www.linkedin.com/in/kyle-delaney-115164172/edit/forms/next-action/after-connect-add-position/) + * **Delaney, Kyle** + * [Github](https://github.com/kylomite) + * [LinkedIn](https://www.linkedin.com/in/kyle-delaney-115164172/edit/forms/next-action/after-connect-add-position/) -* **Hill, John** - * [Github](https://github.com/jphill19) - * [LinkedIn](https://www.linkedin.com/in/john-hill-309715245/) + * **Hill, John** + * [Github](https://github.com/jphill19) + * [LinkedIn](https://www.linkedin.com/in/john-hill-309715245/) -* **Thompson, Shawn** - * [Github](https://github.com/SThompson05) - * [LinkedIn](https://www.linkedin.com/in/shawn-thompson-16956267/) + * **Thompson, Shawn** + * [Github](https://github.com/SThompson05) + * [LinkedIn](https://www.linkedin.com/in/shawn-thompson-16956267/) -* **Willett, Bryan** - * [Github](https://github.com/bwillett2003) - * [LinkedIn](https://www.youtube.com/watch?v=ub82Xb1C8os&ab_channel=JuiceboxHero) + * **Willett, Bryan** + * [Github](https://github.com/bwillett2003) + * [LinkedIn](https://www.youtube.com/watch?v=ub82Xb1C8os&ab_channel=JuiceboxHero) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb new file mode 100644 index 0000000000..f223e74784 --- /dev/null +++ b/lib/stat_tracker.rb @@ -0,0 +1,22 @@ +require 'csv' + +class StatTracker + + def self.from_csv(season_data) + game_reader(season_data[:games]) + teams_reader(season_data[:teams]) + games_and_teams_reader(season_data[:game_teams]) + end + + def self.game_reader + + end + + def self.teams_reader + + end + + def self.game_teams_reader + + end +end \ No newline at end of file diff --git a/runner.rb b/runner.rb new file mode 100644 index 0000000000..274fe39598 --- /dev/null +++ b/runner.rb @@ -0,0 +1,13 @@ +require './lib/stat_tracker' + +game_path = './data/games.csv' +team_path = './data/teams.csv' +game_teams_path = './data/game_teams.csv' + +season_data = { + games: game_path, + teams: team_path, + game_teams: game_teams_path +} + +stat_tracker = StatTracker.from_csv(season_data) \ No newline at end of file From 0548ae25f3441897ec674f4309a8647532fe2d0d Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Tue, 30 Jul 2024 16:27:24 -0400 Subject: [PATCH 06/97] feat- add game class --- lib/game.rb | 16 ++++++++++++++++ spec/game_spec.rb | 0 spec/spec_helper.rb | 3 +++ 3 files changed, 19 insertions(+) create mode 100644 lib/game.rb create mode 100644 spec/game_spec.rb diff --git a/lib/game.rb b/lib/game.rb new file mode 100644 index 0000000000..06dce8287b --- /dev/null +++ b/lib/game.rb @@ -0,0 +1,16 @@ +class Game + attr_reader + + def initialize(data) + data.default = 0 + @game_id = data[:game_id] + @season = data[:season] + @type = data[:type] + @date_time = data[:date_time] + @away_team_id = data[:away_team_id] + @home_team_id = data[:home_team_id] + @away_goals = data[:away_goals] + @home_goals = data[:home_goals] + @venue = data[:venue] + end +end \ No newline at end of file diff --git a/spec/game_spec.rb b/spec/game_spec.rb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a93d2421bf..c2313bc0a2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,6 @@ require 'simplecov' SimpleCov.start ### Require your class files below here vvv ### + + +require './lib/game' From 6bc3405fc1da47b803306787add56624a075f15f Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Tue, 30 Jul 2024 16:48:49 -0400 Subject: [PATCH 07/97] refactor- add dummy csvs --- data/game_teams_dummy.csv | 15 +++++++++++++++ data/games_dummy.csv | 15 +++++++++++++++ data/teams_dummy.csv | 15 +++++++++++++++ lib/stat_tracker.rb | 7 +++++-- runner.rb | 6 +++--- 5 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 data/game_teams_dummy.csv create mode 100644 data/games_dummy.csv create mode 100644 data/teams_dummy.csv diff --git a/data/game_teams_dummy.csv b/data/game_teams_dummy.csv new file mode 100644 index 0000000000..bd2b2db6e2 --- /dev/null +++ b/data/game_teams_dummy.csv @@ -0,0 +1,15 @@ +game_id,team_id,HoA,result,settled_in,head_coach,goals,shots,tackles,pim,powerPlayOpportunities,powerPlayGoals,faceOffWinPercentage,giveaways,takeaways +2012030221,3,away,LOSS,OT,John Tortorella,2,8,44,8,3,0,44.8,17,7 +2012030221,6,home,WIN,OT,Claude Julien,3,12,51,6,4,1,55.2,4,5 +2012030222,3,away,LOSS,REG,John Tortorella,2,9,33,11,5,0,51.7,1,4 +2012030222,6,home,WIN,REG,Claude Julien,3,8,36,19,1,0,48.3,16,6 +2012030223,6,away,WIN,REG,Claude Julien,2,8,28,6,0,0,61.8,10,7 +2012030223,3,home,LOSS,REG,John Tortorella,1,6,37,2,2,0,38.2,7,9 +2012030224,6,away,WIN,OT,Claude Julien,3,10,24,8,4,2,53.7,8,6 +2012030224,3,home,LOSS,OT,John Tortorella,2,8,40,8,4,1,46.3,9,7 +2012030225,3,away,LOSS,REG,John Tortorella,1,7,25,13,2,1,50.9,5,3 +2012030225,6,home,WIN,REG,Claude Julien,3,8,35,11,3,1,49.1,12,9 +2012030311,6,away,WIN,REG,Claude Julien,3,7,19,17,4,0,66.7,1,5 +2012030311,5,home,LOSS,REG,Dan Bylsma,0,7,34,28,4,0,33.3,8,9 +2012030312,6,away,WIN,REG,Claude Julien,4,7,19,6,1,0,50.9,2,5 +2012030312,5,home,LOSS,REG,Dan Bylsma,1,6,37,4,2,0,49.1,12,5 \ No newline at end of file diff --git a/data/games_dummy.csv b/data/games_dummy.csv new file mode 100644 index 0000000000..f6797b1578 --- /dev/null +++ b/data/games_dummy.csv @@ -0,0 +1,15 @@ +game_id,season,type,date_time,away_team_id,home_team_id,away_goals,home_goals,venue,venue_link +2012030221,20122013,Postseason,5/16/13,3,6,2,3,Toyota Stadium,/api/v1/venues/null +2012030222,20122013,Postseason,5/19/13,3,6,2,3,Toyota Stadium,/api/v1/venues/null +2012030223,20122013,Postseason,5/21/13,6,3,2,1,BBVA Stadium,/api/v1/venues/null +2012030224,20122013,Postseason,5/23/13,6,3,3,2,BBVA Stadium,/api/v1/venues/null +2012030225,20122013,Postseason,5/25/13,3,6,1,3,Toyota Stadium,/api/v1/venues/null +2012030311,20122013,Postseason,6/2/13,6,5,3,0,Children's Mercy Park,/api/v1/venues/null +2012030312,20122013,Postseason,6/4/13,6,5,4,1,Children's Mercy Park,/api/v1/venues/null +2012030313,20122013,Postseason,6/6/13,5,6,1,2,Toyota Stadium,/api/v1/venues/null +2012030314,20122013,Postseason,6/8/13,5,6,0,1,Toyota Stadium,/api/v1/venues/null +2012030231,20122013,Postseason,5/16/13,17,16,1,2,Gillette Stadium,/api/v1/venues/null +2012030232,20122013,Postseason,5/18/13,17,16,2,1,Gillette Stadium,/api/v1/venues/null +2012030233,20122013,Postseason,5/20/13,16,17,1,3,Dignity Health Sports Park,/api/v1/venues/null +2012030234,20122013,Postseason,5/24/13,16,17,0,2,Dignity Health Sports Park,/api/v1/venues/null +2012030235,20122013,Postseason,5/26/13,17,16,1,2,Gillette Stadium,/api/v1/venues/null \ No newline at end of file diff --git a/data/teams_dummy.csv b/data/teams_dummy.csv new file mode 100644 index 0000000000..9c52de40f5 --- /dev/null +++ b/data/teams_dummy.csv @@ -0,0 +1,15 @@ +team_id,franchiseId,teamName,abbreviation,Stadium,link +1,23,Atlanta United,ATL,Mercedes-Benz Stadium,/api/v1/teams/1 +4,16,Chicago Fire,CHI,SeatGeek Stadium,/api/v1/teams/4 +26,14,FC Cincinnati,CIN,Nippert Stadium,/api/v1/teams/26 +14,31,DC United,DC,Audi Field,/api/v1/teams/14 +6,6,FC Dallas,DAL,Toyota Stadium,/api/v1/teams/6 +3,10,Houston Dynamo,HOU,BBVA Stadium,/api/v1/teams/3 +5,17,Sporting Kansas City,SKC,Children's Mercy Park,/api/v1/teams/5 +17,12,LA Galaxy,LA,Dignity Health Sports Park,/api/v1/teams/17 +28,29,Los Angeles FC,LFC,Banc of California Stadium,/api/v1/teams/28 +18,34,Minnesota United FC,MIN,Allianz Field,/api/v1/teams/18 +23,20,Montreal Impact,MTL,Saputo Stadium,/api/v1/teams/23 +16,11,New England Revolution,NE,Gillette Stadium,/api/v1/teams/16 +9,30,New York City FC,NYC,Yankee Stadium,/api/v1/teams/9 +8,1,New York Red Bulls,NY,Red Bull Arena,/api/v1/teams/8 \ No newline at end of file diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index f223e74784..5226cf1e98 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -8,8 +8,11 @@ def self.from_csv(season_data) games_and_teams_reader(season_data[:game_teams]) end - def self.game_reader - + def self.game_reader(csv_data) + games = Hash.new(0) + CSV.foreach(csv_data, headers: true, header_converters: :symbol) do |row| + games[row[:game_id]] = Game.new(row) + end end def self.teams_reader diff --git a/runner.rb b/runner.rb index 274fe39598..4f1717ccff 100644 --- a/runner.rb +++ b/runner.rb @@ -1,8 +1,8 @@ require './lib/stat_tracker' -game_path = './data/games.csv' -team_path = './data/teams.csv' -game_teams_path = './data/game_teams.csv' +game_path = './data/games_dummy.csv' +team_path = './data/teams_dummy.csv' +game_teams_path = './data/game_teams_dummy.csv' season_data = { games: game_path, From 87e6879ed4c36b83af05584ed84d43516feec9c3 Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Tue, 30 Jul 2024 17:37:27 -0400 Subject: [PATCH 08/97] feat complete game IO set up --- lib/game.rb | 25 ++++++++++++++++--------- lib/stat_tracker.rb | 5 ++++- runner.rb | 1 + spec/spec_helper.rb | 1 + 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/game.rb b/lib/game.rb index 06dce8287b..1dfb511f7a 100644 --- a/lib/game.rb +++ b/lib/game.rb @@ -1,16 +1,23 @@ class Game - attr_reader + attr_reader :game_id, + :season, + :type, + :date_time, + :away_team_id, + :home_team_id, + :away_goals, + :home_goals, + :venue def initialize(data) - data.default = 0 - @game_id = data[:game_id] - @season = data[:season] + @game_id = data[:game_id].to_i + @season = data[:season].to_i @type = data[:type] - @date_time = data[:date_time] - @away_team_id = data[:away_team_id] - @home_team_id = data[:home_team_id] - @away_goals = data[:away_goals] - @home_goals = data[:home_goals] + @date_time = data[:date_time] #NEED TO CONVERT TO DATE OBJECT + @away_team_id = data[:away_team_id].to_i + @home_team_id = data[:home_team_id].to_i + @away_goals = data[:away_goals].to_i + @home_goals = data[:home_goals].to_i @venue = data[:venue] end end \ No newline at end of file diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 5226cf1e98..717d3276b1 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -1,4 +1,5 @@ require 'csv' +require './lib/game' class StatTracker @@ -11,8 +12,10 @@ def self.from_csv(season_data) def self.game_reader(csv_data) games = Hash.new(0) CSV.foreach(csv_data, headers: true, header_converters: :symbol) do |row| - games[row[:game_id]] = Game.new(row) + games[row[:game_id].to_i] = Game.new(row) end + require'pry';binding.pry + games end def self.teams_reader diff --git a/runner.rb b/runner.rb index 4f1717ccff..be70f20b88 100644 --- a/runner.rb +++ b/runner.rb @@ -1,5 +1,6 @@ require './lib/stat_tracker' + game_path = './data/games_dummy.csv' team_path = './data/teams_dummy.csv' game_teams_path = './data/game_teams_dummy.csv' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c2313bc0a2..cbbf472ae6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,5 +2,6 @@ SimpleCov.start ### Require your class files below here vvv ### +require 'pry' require './lib/game' From e05c64f95c62052bf8c9d3fe94f1e5c7352ac52e Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Tue, 30 Jul 2024 16:35:15 -0600 Subject: [PATCH 09/97] feat: team class --- lib/stat_tracker.rb | 11 ++++++++--- lib/team.rb | 15 +++++++++++++++ spec/spec_helper.rb | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 lib/team.rb diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 717d3276b1..8c65ab960d 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -1,5 +1,6 @@ require 'csv' require './lib/game' +require './lib/team' class StatTracker @@ -14,12 +15,16 @@ def self.game_reader(csv_data) CSV.foreach(csv_data, headers: true, header_converters: :symbol) do |row| games[row[:game_id].to_i] = Game.new(row) end - require'pry';binding.pry games end - def self.teams_reader - + def self.teams_reader(csv_data) + teams = Hash.new(0) + CSV.foreach(csv_data, headers: true, header_converters: :symbol) do |row| + teams[row[:team_id].to_i] = Team.new(row) + end + require'pry';binding.pry + teams end def self.game_teams_reader diff --git a/lib/team.rb b/lib/team.rb new file mode 100644 index 0000000000..58a7584537 --- /dev/null +++ b/lib/team.rb @@ -0,0 +1,15 @@ +class Team + attr_reader :team_id, + :franchise_id, + :team_name, + :abbreviation, + :stadium + + def initialize(data) + @team_id = data[:team_id].to_i + @franchise_id = data[:franchiseid].to_i + @team_name = data[:teamname] + @abbreviation = data[:abbreviation] + @stadium = data[:stadium] + end +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cbbf472ae6..78193906d3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,3 +5,4 @@ require 'pry' require './lib/game' +require './lib/team' From 7b05ab48524b60f45da3dc20d2d4101ae7481a89 Mon Sep 17 00:00:00 2001 From: Shawn Thompson Date: Tue, 30 Jul 2024 18:17:05 -0500 Subject: [PATCH 10/97] Feat: season class set up --- lib/season.rb | 37 +++++++++++++++++++++++++++++++++++++ lib/stat_tracker.rb | 12 +++++++++--- spec/season_spec.rb | 0 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 lib/season.rb create mode 100644 spec/season_spec.rb diff --git a/lib/season.rb b/lib/season.rb new file mode 100644 index 0000000000..955315203c --- /dev/null +++ b/lib/season.rb @@ -0,0 +1,37 @@ +class Season + + attr_reader :game_id, + :team_id, + :hoa, + :result, + :settle_in, + :head_coach, + :goals, + :shots, + :tackles, + :pim, + :powerplayopportunities, + :powerplaygoals, + :faceoffwinpercentage, + :giveaways, + :takeaways + + def initialize(data) + @game_id = data[:game_id].to_i + @team_id = data[:team_id].to_i + @hoa = data[:hoa] + @result = data[:result] + @settle_in = data[:settle_in] + @head_coach = data[:head_coach] + @goals = data[:goals].to_i + @shots = data[:shots].to_i + @tackles = data[:tackles].to_i + @pim = data[:pim].to_i + @powerplayopportunities = data[:powerplayopportunities].to_i + @powerplaygoals = data[:powerplaygoals].to_i + @faceoffwinpercentage = data[:faceoffwinpercentage].to_i + @giveaways = data[:giveaways].to_i + @takeaways = data[:takeaways].to_i + + end +end diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 8c65ab960d..21c2428bf4 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -1,13 +1,14 @@ require 'csv' require './lib/game' require './lib/team' +require './lib/season' class StatTracker def self.from_csv(season_data) game_reader(season_data[:games]) teams_reader(season_data[:teams]) - games_and_teams_reader(season_data[:game_teams]) + game_teams_reader(season_data[:game_teams]) end def self.game_reader(csv_data) @@ -23,11 +24,16 @@ def self.teams_reader(csv_data) CSV.foreach(csv_data, headers: true, header_converters: :symbol) do |row| teams[row[:team_id].to_i] = Team.new(row) end - require'pry';binding.pry teams end - def self.game_teams_reader + def self.game_teams_reader(csv_data) + seasons = Hash.new(0) + CSV.foreach(csv_data, headers: true, header_converters: :symbol) do |row| + seasons[row[:game_id].to_i] = Season.new(row) + end + require'pry';binding.pry + seasons end end \ No newline at end of file diff --git a/spec/season_spec.rb b/spec/season_spec.rb new file mode 100644 index 0000000000..e69de29bb2 From 263bcf8de243d6f874479917150235cd5f12b470 Mon Sep 17 00:00:00 2001 From: John Hill Date: Tue, 30 Jul 2024 17:33:17 -0600 Subject: [PATCH 11/97] Feat: added GameStatistics class --- lib/game_statistics.rb | 7 +++++++ lib/stat_tracker.rb | 8 ++++---- runner.rb | 2 +- spec/spec_helper.rb | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 lib/game_statistics.rb diff --git a/lib/game_statistics.rb b/lib/game_statistics.rb new file mode 100644 index 0000000000..c984659c22 --- /dev/null +++ b/lib/game_statistics.rb @@ -0,0 +1,7 @@ +class GameStatistics + + def initialize(game_stats) + @game_stats_data = game_stats # hashes of game objects + end + +end \ No newline at end of file diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 21c2428bf4..0a99b8752b 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -6,9 +6,10 @@ class StatTracker def self.from_csv(season_data) - game_reader(season_data[:games]) - teams_reader(season_data[:teams]) - game_teams_reader(season_data[:game_teams]) + games = game_reader(season_data[:games]) + teams = teams_reader(season_data[:teams]) + seasons = game_teams_reader(season_data[:game_teams]) + game_stats = GameStatistics.new(games), end def self.game_reader(csv_data) @@ -34,6 +35,5 @@ def self.game_teams_reader(csv_data) end require'pry';binding.pry seasons - end end \ No newline at end of file diff --git a/runner.rb b/runner.rb index be70f20b88..485df58862 100644 --- a/runner.rb +++ b/runner.rb @@ -11,4 +11,4 @@ game_teams: game_teams_path } -stat_tracker = StatTracker.from_csv(season_data) \ No newline at end of file +stat_tracker = StatTracker.from_csv(season_data) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 78193906d3..50c531c59a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,3 +6,4 @@ require './lib/game' require './lib/team' +require './lib/season' From a2c88e5df45346055844fd1ea8d6ebd3e5aae313 Mon Sep 17 00:00:00 2001 From: John Hill Date: Tue, 30 Jul 2024 18:15:34 -0600 Subject: [PATCH 12/97] test: add init tests --- lib/stat_tracker.rb | 3 +++ spec/game_spec.rb | 53 +++++++++++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 1 + 3 files changed, 57 insertions(+) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 0a99b8752b..cbb4826f37 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -9,7 +9,10 @@ def self.from_csv(season_data) games = game_reader(season_data[:games]) teams = teams_reader(season_data[:teams]) seasons = game_teams_reader(season_data[:game_teams]) + game_stats = GameStatistics.new(games), + #league_stats = LeagueStatistics.new(teams) + #seasons_stats = S end def self.game_reader(csv_data) diff --git a/spec/game_spec.rb b/spec/game_spec.rb index e69de29bb2..ebd971e8be 100644 --- a/spec/game_spec.rb +++ b/spec/game_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +RSpec.describe Game do + before(:each) do + CSV.foreach('./data/games_dummy.csv', headers: true, header_converters: :symbol) do |row| + @game_1= Game.new(row) + break + end + end + + describe 'Initialize' do + it 'exists' do + expect(@game_1).to be_an_instance_of(Game) + end + + it 'has game_id attribute' do + expect(@game_1.game_id).to eq(2012030221) + end + + it 'has season attribute' do + expect(@game_1.season).to eq(20122013) + end + + it 'has type attribute' do + expect(@game_1.type).to eq('Postseason') + end + + it 'has date_time attribute' do + expect(@game_1.date_time).to eq('5/16/13') + end + + it 'has away_team_id attribute' do + expect(@game_1.away_team_id).to eq(3) + end + + it 'has home_team_id attribute' do + expect(@game_1.home_team_id).to eq(6) + end + + it 'has away_goals attribute' do + expect(@game_1.away_goals).to eq(2) + end + + it 'has home_goals attribute' do + expect(@game_1.home_goals).to eq(3) + end + + it 'has venue attribute' do + expect(@game_1.venue).to eq('Toyota Stadium') + end + end + +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 50c531c59a..6ccb99a7a8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,3 +7,4 @@ require './lib/game' require './lib/team' require './lib/season' +require 'csv' From a3fa3e50be9d8f164b797b990ee88ac980c36f5d Mon Sep 17 00:00:00 2001 From: John Hill Date: Tue, 30 Jul 2024 18:33:28 -0600 Subject: [PATCH 13/97] test: add init test for Season & Team --- lib/season.rb | 16 ++++---- spec/game_spec.rb | 4 +- spec/season_spec.rb | 77 +++++++++++++++++++++++++++++++++++++++ spec/stat_tracker_spec.rb | 0 spec/team_spec.rb | 36 ++++++++++++++++++ 5 files changed, 123 insertions(+), 10 deletions(-) create mode 100644 spec/stat_tracker_spec.rb create mode 100644 spec/team_spec.rb diff --git a/lib/season.rb b/lib/season.rb index 955315203c..d9222433f8 100644 --- a/lib/season.rb +++ b/lib/season.rb @@ -4,15 +4,15 @@ class Season :team_id, :hoa, :result, - :settle_in, + :settled_in, :head_coach, :goals, :shots, :tackles, :pim, - :powerplayopportunities, - :powerplaygoals, - :faceoffwinpercentage, + :power_play_opportunities, + :power_play_goals, + :face_off_win_percentage, :giveaways, :takeaways @@ -21,15 +21,15 @@ def initialize(data) @team_id = data[:team_id].to_i @hoa = data[:hoa] @result = data[:result] - @settle_in = data[:settle_in] + @settled_in = data[:settled_in] @head_coach = data[:head_coach] @goals = data[:goals].to_i @shots = data[:shots].to_i @tackles = data[:tackles].to_i @pim = data[:pim].to_i - @powerplayopportunities = data[:powerplayopportunities].to_i - @powerplaygoals = data[:powerplaygoals].to_i - @faceoffwinpercentage = data[:faceoffwinpercentage].to_i + @power_play_opportunities = data[:powerplayopportunities].to_i + @power_play_goals = data[:powerplaygoals].to_i + @face_off_win_percentage = data[:faceoffwinpercentage].to_i @giveaways = data[:giveaways].to_i @takeaways = data[:takeaways].to_i diff --git a/spec/game_spec.rb b/spec/game_spec.rb index ebd971e8be..42bd66f079 100644 --- a/spec/game_spec.rb +++ b/spec/game_spec.rb @@ -6,9 +6,9 @@ @game_1= Game.new(row) break end - end + end - describe 'Initialize' do + describe 'Initialize' do it 'exists' do expect(@game_1).to be_an_instance_of(Game) end diff --git a/spec/season_spec.rb b/spec/season_spec.rb index e69de29bb2..0bb54af705 100644 --- a/spec/season_spec.rb +++ b/spec/season_spec.rb @@ -0,0 +1,77 @@ +require 'spec_helper' + + +RSpec.describe Season do + before(:each) do + CSV.foreach('./data/game_teams_dummy.csv', headers: true, header_converters: :symbol) do |row| + @season_1 = Season.new(row) + break + end + end + + describe 'Initialize' do + it 'exists' do + expect(@season_1).to be_an_instance_of(Season) + end + + it 'has game_id attribute' do + expect(@season_1.game_id).to eq(2012030221) + end + + it 'has team_id attribute' do + expect(@season_1.team_id).to eq(3) + end + + it 'has hoa attribute' do + expect(@season_1.hoa).to eq('away') + end + + it 'has result attribute' do + expect(@season_1.result).to eq('LOSS') + end + + it 'has settled_in attribute' do + expect(@season_1.settled_in).to eq('OT') + end + + it 'has head_coach attribute' do + expect(@season_1.head_coach).to eq('John Tortorella') + end + + it 'has goals attribute' do + expect(@season_1.goals).to eq(2) + end + + it 'has shots attribute' do + expect(@season_1.shots).to eq(8) + end + + it 'has tackles attribute' do + expect(@season_1.tackles).to eq(44) + end + + it 'has pim attribute' do + expect(@season_1.pim).to eq(8) + end + + it 'has power_play_opportunities attribute' do + expect(@season_1.power_play_opportunities).to eq(3) + end + + it 'has power_play_goals attribute' do + expect(@season_1.power_play_goals).to eq(0) + end + + it 'has face_off_win_percentage attribute' do + expect(@season_1.face_off_win_percentage).to eq(44) + end + + it 'has giveaways attribute' do + expect(@season_1.giveaways).to eq(17) + end + + it 'has takeaways attribute' do + expect(@season_1.takeaways).to eq(7) + end + end +end diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spec/team_spec.rb b/spec/team_spec.rb new file mode 100644 index 0000000000..6764a253cc --- /dev/null +++ b/spec/team_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +RSpec.describe Team do + before(:each) do + CSV.foreach('./data/teams_dummy.csv', headers: true, header_converters: :symbol) do |row| + @team_1 = Team.new(row) + break + end + end + + describe 'Initialize' do + it 'exists' do + expect(@team_1).to be_an_instance_of(Team) + end + + it 'has team_id attribute' do + expect(@team_1.team_id).to eq(1) + end + + it 'has franchise_id attribute' do + expect(@team_1.franchise_id).to eq(23) + end + + it 'has team_name attribute' do + expect(@team_1.team_name).to eq('Atlanta United') + end + + it 'has abbreviation attribute' do + expect(@team_1.abbreviation).to eq('ATL') + end + + it 'has stadium attribute' do + expect(@team_1.stadium).to eq('Mercedes-Benz Stadium') + end + end +end From 72312223886c93bb7b60a90501d25799556cdd06 Mon Sep 17 00:00:00 2001 From: John Hill Date: Wed, 31 Jul 2024 08:24:42 -0600 Subject: [PATCH 14/97] test: add stat_tracker tests --- lib/season.rb | 1 - lib/stat_tracker.rb | 12 ++--- spec/spec_helper.rb | 1 + spec/stat_tracker_spec.rb | 95 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 7 deletions(-) diff --git a/lib/season.rb b/lib/season.rb index d9222433f8..b3d7c3aa5f 100644 --- a/lib/season.rb +++ b/lib/season.rb @@ -32,6 +32,5 @@ def initialize(data) @face_off_win_percentage = data[:faceoffwinpercentage].to_i @giveaways = data[:giveaways].to_i @takeaways = data[:takeaways].to_i - end end diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index cbb4826f37..f325ce96f2 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -9,10 +9,8 @@ def self.from_csv(season_data) games = game_reader(season_data[:games]) teams = teams_reader(season_data[:teams]) seasons = game_teams_reader(season_data[:game_teams]) - - game_stats = GameStatistics.new(games), - #league_stats = LeagueStatistics.new(teams) - #seasons_stats = S + + game_stats = GameStatistics.new(games) end def self.game_reader(csv_data) @@ -33,10 +31,12 @@ def self.teams_reader(csv_data) def self.game_teams_reader(csv_data) seasons = Hash.new(0) + count = 1 CSV.foreach(csv_data, headers: true, header_converters: :symbol) do |row| - seasons[row[:game_id].to_i] = Season.new(row) + seasons[count] = Season.new(row) + count +=1 end - require'pry';binding.pry seasons end + end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6ccb99a7a8..6c5c40986e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,4 +7,5 @@ require './lib/game' require './lib/team' require './lib/season' +require './lib/stat_tracker' require 'csv' diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index e69de29bb2..99e7b638a1 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -0,0 +1,95 @@ +require 'spec_helper' + + +RSpec.describe StatTracker do + before(:each) do + game_path = './data/games_dummy.csv' + team_path = './data/teams_dummy.csv' + game_teams_path = './data/game_teams_dummy.csv' + + @locations = { + games: game_path, + teams: team_path, + game_teams: game_teams_path + } + end + + describe "game_reader" do + it "returns a hash with keys set to game_id, value is the relevant game object" do + games_data = StatTracker.game_reader(@locations[:games]) + + expect(games_data.class).to eq Hash + expect(games_data[2012030221]).to be_an_instance_of Game + end + + it "each game object it creates, all their attributes are truthy" do + games_data = StatTracker.game_reader(@locations[:games]) + + games_data.each do |game_id, game_object| + game_object.instance_variables.each do |instance_variable| + expect(game_object.instance_variable_get(instance_variable)).to be_truthy + end + end + end + + it "creates a game object for reach row" do + games_data = StatTracker.game_reader(@locations[:games]) + row_count = CSV.read(@locations[:games], headers: true).size + + expect(games_data.length).to eq(row_count) + end + end + + describe "teams_reader" do + it "returns a hash with keys set to team_id, value is the relevant team object" do + teams_data = StatTracker.teams_reader(@locations[:teams]) + + expect(teams_data.class).to eq Hash + expect(teams_data[1]).to be_an_instance_of Team + end + + it "each team object it creates, all their attributes are truthy" do + teams_data = StatTracker.teams_reader(@locations[:teams]) + + teams_data.each do |team_id, team_object| + team_object.instance_variables.each do |instance_variable| + expect(team_object.instance_variable_get(instance_variable)).to be_truthy + end + end + end + + it "creates a team object for each row" do + teams_data = StatTracker.teams_reader(@locations[:teams]) + row_count = CSV.read(@locations[:teams], headers: true).size + + expect(teams_data.length).to eq(row_count) + end + end + + describe "game_teams_reader" do + it "returns a hash with keys set to game_id, value is the relevant season object" do + seasons_data = StatTracker.game_teams_reader(@locations[:game_teams]) + + expect(seasons_data.class).to eq Hash + expect(seasons_data[1]).to be_an_instance_of Season + end + + it "each season object it creates, all their attributes are truthy" do + seasons_data = StatTracker.game_teams_reader(@locations[:game_teams]) + + seasons_data.each do |game_id, season_object| + season_object.instance_variables.each do |instance_variable| + expect(season_object.instance_variable_get(instance_variable)).to be_truthy + end + end + end + + it "creates a season object for each row" do + seasons_data = StatTracker.game_teams_reader(@locations[:game_teams]) + row_count = CSV.read(@locations[:game_teams], headers: true).size + + expect(seasons_data.length).to eq(row_count) + end + end + +end \ No newline at end of file From 250d1c2a98d47f6b4c2b53cde04a3b02c375f0a1 Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Wed, 31 Jul 2024 15:46:42 -0500 Subject: [PATCH 15/97] feat:completed highest_total_score and helper method. --- lib/game.rb | 4 ++++ lib/game_statistics.rb | 7 +++++++ lib/stat_tracker.rb | 1 + spec/game_spec.rb | 7 +++++++ spec/game_statistics_spec.rb | 20 ++++++++++++++++++++ spec/spec_helper.rb | 1 + 6 files changed, 40 insertions(+) create mode 100644 spec/game_statistics_spec.rb diff --git a/lib/game.rb b/lib/game.rb index 1dfb511f7a..00fb4f2df6 100644 --- a/lib/game.rb +++ b/lib/game.rb @@ -20,4 +20,8 @@ def initialize(data) @home_goals = data[:home_goals].to_i @venue = data[:venue] end + + def total_goals + @away_goals + @home_goals + end end \ No newline at end of file diff --git a/lib/game_statistics.rb b/lib/game_statistics.rb index c984659c22..d1db2b804b 100644 --- a/lib/game_statistics.rb +++ b/lib/game_statistics.rb @@ -4,4 +4,11 @@ def initialize(game_stats) @game_stats_data = game_stats # hashes of game objects end + def highest_total_score + highest_scoring_game = @game_stats_data.max_by do |game_id, game_object| + game_object.total_goals + end + highest_scoring_game[1].total_goals + end + end \ No newline at end of file diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index f325ce96f2..57f7de3053 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -2,6 +2,7 @@ require './lib/game' require './lib/team' require './lib/season' +require './lib/game_statistics' class StatTracker diff --git a/spec/game_spec.rb b/spec/game_spec.rb index 42bd66f079..5c0d79d256 100644 --- a/spec/game_spec.rb +++ b/spec/game_spec.rb @@ -49,5 +49,12 @@ expect(@game_1.venue).to eq('Toyota Stadium') end end + + describe 'total_goals' do + it 'returns sum of away_goals and home_goals' do + expected = @game_1.away_goals + @game_1.home_goals + expect(@game_1.total_goals).to eq(expected) + end + end end \ No newline at end of file diff --git a/spec/game_statistics_spec.rb b/spec/game_statistics_spec.rb new file mode 100644 index 0000000000..747d64d31b --- /dev/null +++ b/spec/game_statistics_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +RSpec.describe GameStatistics do + before(:each) do + game_path = './data/games_dummy.csv' + + @game_stats = GameStatistics.new(StatTracker.game_reader(game_path)) + end + describe 'Initialize' do + it 'exists' do + expect(@game_stats).to be_an_instance_of(GameStatistics) + end + end + + describe 'highest_total_score' do + it 'returns highest sum of the winning and losing teams scores' do + expect(@game_stats.highest_total_score).to eq(5) + end + end +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6c5c40986e..ec48052653 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,3 +9,4 @@ require './lib/season' require './lib/stat_tracker' require 'csv' +require './lib/game_statistics' From 0666d90f97238bed8bea5156a3ceaed38c9450fa Mon Sep 17 00:00:00 2001 From: John Hill Date: Wed, 31 Jul 2024 17:02:33 -0600 Subject: [PATCH 16/97] refactor: removed GameStatistics class, and incorporated into StatTracker --- lib/game_statistics.rb | 14 -------------- lib/stat_tracker.rb | 19 ++++++++++++++++--- runner.rb | 2 ++ spec/game_statistics_spec.rb | 20 -------------------- spec/spec_helper.rb | 2 +- spec/stat_tracker_spec.rb | 15 +++++++++++++++ 6 files changed, 34 insertions(+), 38 deletions(-) delete mode 100644 lib/game_statistics.rb delete mode 100644 spec/game_statistics_spec.rb diff --git a/lib/game_statistics.rb b/lib/game_statistics.rb deleted file mode 100644 index d1db2b804b..0000000000 --- a/lib/game_statistics.rb +++ /dev/null @@ -1,14 +0,0 @@ -class GameStatistics - - def initialize(game_stats) - @game_stats_data = game_stats # hashes of game objects - end - - def highest_total_score - highest_scoring_game = @game_stats_data.max_by do |game_id, game_object| - game_object.total_goals - end - highest_scoring_game[1].total_goals - end - -end \ No newline at end of file diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 57f7de3053..51883d30aa 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -2,16 +2,29 @@ require './lib/game' require './lib/team' require './lib/season' -require './lib/game_statistics' -class StatTracker +class StatTracker + def self.from_csv(season_data) games = game_reader(season_data[:games]) teams = teams_reader(season_data[:teams]) seasons = game_teams_reader(season_data[:game_teams]) - game_stats = GameStatistics.new(games) + new(games, teams, seasons) + end + + def initialize(games, teams, seasons) + @game_stats_data = games + @teams_stats_data = teams + @seasons_stats_data = seasons + end + + def highest_total_score + highest_scoring_game = @game_stats_data.max_by do |game_id, game_object| + game_object.total_goals + end + highest_scoring_game[1].total_goals end def self.game_reader(csv_data) diff --git a/runner.rb b/runner.rb index 485df58862..8a810f35f6 100644 --- a/runner.rb +++ b/runner.rb @@ -12,3 +12,5 @@ } stat_tracker = StatTracker.from_csv(season_data) +puts stat_tracker.highest_total_score +puts stat_tracker.class diff --git a/spec/game_statistics_spec.rb b/spec/game_statistics_spec.rb deleted file mode 100644 index 747d64d31b..0000000000 --- a/spec/game_statistics_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'spec_helper' - -RSpec.describe GameStatistics do - before(:each) do - game_path = './data/games_dummy.csv' - - @game_stats = GameStatistics.new(StatTracker.game_reader(game_path)) - end - describe 'Initialize' do - it 'exists' do - expect(@game_stats).to be_an_instance_of(GameStatistics) - end - end - - describe 'highest_total_score' do - it 'returns highest sum of the winning and losing teams scores' do - expect(@game_stats.highest_total_score).to eq(5) - end - end -end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ec48052653..90a5fb778e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,4 +9,4 @@ require './lib/season' require './lib/stat_tracker' require 'csv' -require './lib/game_statistics' + diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 99e7b638a1..cddb13ecfd 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -12,6 +12,21 @@ teams: team_path, game_teams: game_teams_path } + + @stat_tracker = StatTracker.from_csv(@locations) + end + + describe "initialize" do + it 'exists' do + expect(@stat_tracker).to be_an_instance_of StatTracker + end + + end + + describe 'highest_total_score' do + it 'returns highest sum of the winning and losing teams scores' do + expect(@stat_tracker.highest_total_score).to eq(5) + end end describe "game_reader" do From c42f197a071cbed05705927d0ca7024b87d0d886 Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Wed, 31 Jul 2024 19:50:06 -0600 Subject: [PATCH 17/97] test: percentage home wins test suite --- spec/stat_tracker_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index cddb13ecfd..2d40126fd2 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -107,4 +107,10 @@ end end + describe 'percentage_home_wins' do + it 'returns percentage of games that a home team has won' do + expect(@stat_tracker.percentage_home_wins).to eq(57.14) + end + end + end \ No newline at end of file From c3cb8bc881856a5888a535757417f28dde2b185d Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Wed, 31 Jul 2024 20:21:08 -0600 Subject: [PATCH 18/97] feat: percentage home wins method --- lib/stat_tracker.rb | 7 +++++++ spec/stat_tracker_spec.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 51883d30aa..95c4e0343f 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -27,6 +27,13 @@ def highest_total_score highest_scoring_game[1].total_goals end + def percentage_home_wins + win_count = @game_stats_data.count do |game_id, game| + game.home_goals > game.away_goals + end + ((win_count.to_f / @game_stats_data.length) * 100).truncate(2) + end + def self.game_reader(csv_data) games = Hash.new(0) CSV.foreach(csv_data, headers: true, header_converters: :symbol) do |row| diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 2d40126fd2..d30f66fdd8 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -109,7 +109,7 @@ describe 'percentage_home_wins' do it 'returns percentage of games that a home team has won' do - expect(@stat_tracker.percentage_home_wins).to eq(57.14) + expect(@stat_tracker.percentage_home_wins).to eq(64.28) end end From 51138178bde0d632c21b87a14f458431fa1c9c83 Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Wed, 31 Jul 2024 20:33:33 -0600 Subject: [PATCH 19/97] refactor: relocated methods after data readers --- spec/stat_tracker_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index d30f66fdd8..2bcc88b983 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -23,12 +23,6 @@ end - describe 'highest_total_score' do - it 'returns highest sum of the winning and losing teams scores' do - expect(@stat_tracker.highest_total_score).to eq(5) - end - end - describe "game_reader" do it "returns a hash with keys set to game_id, value is the relevant game object" do games_data = StatTracker.game_reader(@locations[:games]) @@ -107,6 +101,12 @@ end end + describe 'highest_total_score' do + it 'returns highest sum of the winning and losing teams scores' do + expect(@stat_tracker.highest_total_score).to eq(5) + end + end + describe 'percentage_home_wins' do it 'returns percentage of games that a home team has won' do expect(@stat_tracker.percentage_home_wins).to eq(64.28) From 6b89feb7500ecbdca6d2c2137003a9b8186cfbe2 Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Wed, 31 Jul 2024 20:50:19 -0600 Subject: [PATCH 20/97] test: best offense test suite --- spec/stat_tracker_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index d30f66fdd8..2d9fd760f9 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -113,4 +113,9 @@ end end + describe 'best_offense' do + it 'returns team yielding highest goals scored per game over all seasons' do + expect(@stat_tracker.best_offense).to eq("FC Dallas") + end + end end \ No newline at end of file From 361334ed75f077f79ffd6a1268d565e3fed73a78 Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Thu, 1 Aug 2024 08:53:01 -0400 Subject: [PATCH 21/97] refactor: move highest total score test --- spec/stat_tracker_spec.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index cddb13ecfd..f126b92e8b 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -23,12 +23,6 @@ end - describe 'highest_total_score' do - it 'returns highest sum of the winning and losing teams scores' do - expect(@stat_tracker.highest_total_score).to eq(5) - end - end - describe "game_reader" do it "returns a hash with keys set to game_id, value is the relevant game object" do games_data = StatTracker.game_reader(@locations[:games]) @@ -107,4 +101,9 @@ end end + describe 'highest_total_score' do + it 'returns highest sum of the winning and losing teams scores' do + expect(@stat_tracker.highest_total_score).to eq(5) + end + end end \ No newline at end of file From f4ef2b8ee7218bb66ebf2d111ff982a4f6c4d8d3 Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Thu, 1 Aug 2024 11:43:15 -0600 Subject: [PATCH 22/97] feat: psudocoding --- lib/stat_tracker.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 95c4e0343f..c08d797286 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -34,6 +34,24 @@ def percentage_home_wins ((win_count.to_f / @game_stats_data.length) * 100).truncate(2) end + def best_offense + score_tracker = Hash.new(0) + + @game_stats_data.each do |game_id, game| + score_tracker[game.away_team_id] = game.away_goals + score_tracker[game.home_team_id] = game.home_goals + require 'pry'; binding.pry + end + # iterate through the data + # make an accumulator to track goals/game for each team id + # counter = [], counter += game.goals + # counter / games played = avg goals per game + # find team that is associated with the highest avg goals per game + # + # lastly make method to associate team id in game with team id in teams + # and return teams_dummy.teamname.to_s + end + def self.game_reader(csv_data) games = Hash.new(0) CSV.foreach(csv_data, headers: true, header_converters: :symbol) do |row| From 3ed97971bdd696c93c54700f7b1a1920c01dca2f Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Thu, 1 Aug 2024 13:49:01 -0400 Subject: [PATCH 23/97] feat-add test for percentage_ties --- spec/stat_tracker_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 2bcc88b983..25df4c9090 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -113,4 +113,21 @@ end end + describe 'percentage_ties' do + it 'returns percentage of games that has resulted in a tie (rounded to the nearest 100th)' do + expect(@stat_tracker.percentage_ties).to eq(0.00) # NO TIES CURRENTLY LISTED + + hash_of_games = @stat_tracker.instance_variable_get(@game_stats_data) + + hash_of_games[2012030221].instance_variable_set(:@away_goals, 15) + hash_of_games[2012030221].instance_variable_set(:@home_goals, 15) + + expect(@stat_tracker.percentage_ties).to eq(0.07) + + hash_of_games[2012030222].instance_variable_set(:@away_goals, 15) + hash_of_games[2012030222].instance_variable_set(:@home_goals, 15) + + expect(@stat_tracker.percentage_ties).to eq(0.12) + end + end end \ No newline at end of file From 22fb2be57e15043b0336ecd749bd89fe035f58bc Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Thu, 1 Aug 2024 14:55:51 -0400 Subject: [PATCH 24/97] feat-pass test for percentage_ties --- lib/stat_tracker.rb | 86 ++++++++++++++++++++++++++++++++------- spec/spec_helper.rb | 8 +++- spec/stat_tracker_spec.rb | 73 +++++++++++++++++++++++++++++++-- 3 files changed, 148 insertions(+), 19 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 95c4e0343f..093ab673e9 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -20,20 +20,6 @@ def initialize(games, teams, seasons) @seasons_stats_data = seasons end - def highest_total_score - highest_scoring_game = @game_stats_data.max_by do |game_id, game_object| - game_object.total_goals - end - highest_scoring_game[1].total_goals - end - - def percentage_home_wins - win_count = @game_stats_data.count do |game_id, game| - game.home_goals > game.away_goals - end - ((win_count.to_f / @game_stats_data.length) * 100).truncate(2) - end - def self.game_reader(csv_data) games = Hash.new(0) CSV.foreach(csv_data, headers: true, header_converters: :symbol) do |row| @@ -60,4 +46,76 @@ def self.game_teams_reader(csv_data) seasons end + def highest_total_score + highest_scoring_game = @game_stats_data.max_by do |game_id, game_object| + game_object.total_goals + end + highest_scoring_game[1].total_goals + end + + def percentage_home_wins + win_count = @game_stats_data.count do |game_id, game| + game.home_goals > game.away_goals + end + ((win_count.to_f / @game_stats_data.length) * 100).truncate(2) + end + + def percentage_ties + tie_count = @game_stats_data.count do |game_id, game| + game.home_goals == game.away_goals + end + ((tie_count.to_f/ @game_stats_data.length).truncate(2)) + end + + # def count_of_teams + + # end + + # def best_offense + + # end + + # def worst_offense + + # end + + # def highest_scoring_visitor + + # end + + # def highest_scoring_home_team + + # end + + # def lowest_scoring_visitor + + # end + + # def lowest_scoring_home_team + + # end + + # def winningest_coach + + # end + + # def worst_coach + + # end + + # def most_accurate_team + + # end + + # def least_accurate_team + + # end + + # def most_tackles + + # end + + # def fewest_tackles + + # end end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 90a5fb778e..6efe80e6c1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,12 +1,16 @@ require 'simplecov' SimpleCov.start ### Require your class files below here vvv ### - +RSpec.configure do |config| + config.formatter = :documentation +end require 'pry' +require 'csv' require './lib/game' require './lib/team' require './lib/season' require './lib/stat_tracker' -require 'csv' + + diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 25df4c9090..bb869bdbb5 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -114,10 +114,10 @@ end describe 'percentage_ties' do - it 'returns percentage of games that has resulted in a tie (rounded to the nearest 100th)' do + it 'returns percentage of games that has resulted in a tie (rounded to the nearest 100th)' do expect(@stat_tracker.percentage_ties).to eq(0.00) # NO TIES CURRENTLY LISTED - hash_of_games = @stat_tracker.instance_variable_get(@game_stats_data) + hash_of_games = @stat_tracker.instance_variable_get(:@game_stats_data) hash_of_games[2012030221].instance_variable_set(:@away_goals, 15) hash_of_games[2012030221].instance_variable_set(:@home_goals, 15) @@ -126,8 +126,75 @@ hash_of_games[2012030222].instance_variable_set(:@away_goals, 15) hash_of_games[2012030222].instance_variable_set(:@home_goals, 15) + + hash_of_games[2012030223].instance_variable_set(:@away_goals, 15) + hash_of_games[2012030223].instance_variable_set(:@home_goals, 15) + + hash_of_games[2012030224].instance_variable_set(:@away_goals, 15) + hash_of_games[2012030224].instance_variable_set(:@home_goals, 15) + + hash_of_games[2012030225].instance_variable_set(:@away_goals, 15) + hash_of_games[2012030225].instance_variable_set(:@home_goals, 15) + + hash_of_games[2012030311].instance_variable_set(:@away_goals, 15) + hash_of_games[2012030311].instance_variable_set(:@home_goals, 15) - expect(@stat_tracker.percentage_ties).to eq(0.12) + hash_of_games[2012030312].instance_variable_set(:@away_goals, 15) + hash_of_games[2012030312].instance_variable_set(:@home_goals, 15) + + expect(@stat_tracker.percentage_ties).to eq(0.50) end end + + # describe 'count_of_teams' do + + # end + + # describe 'best_offense' do + + # end + + # describe 'worst_offense' do + + # end + + # describe 'highest_scoring_visitor' do + + # end + + # describe 'highest_scoring_home_team' do + + # end + + # describe 'lowest_scoring_visitor' do + + # end + + # describe 'lowest_scoring_home_team' do + + # end + + # describe 'winningest_coach' do + + # end + + # describe 'worst_coach' do + + # end + + # describe 'most_accurate_team' do + + # end + + # describe 'least_accurate_team' do + + # end + + # describe 'most_tackles' do + + # end + + # describe 'fewest_tackles' do + + # end end \ No newline at end of file From ddabfce1ba1743d9e840ec80eb0560e1c80e1886 Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Thu, 1 Aug 2024 15:16:43 -0400 Subject: [PATCH 25/97] feat- add test for average_goals_per_game --- spec/stat_tracker_spec.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index bb869bdbb5..5b3f29920f 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -140,12 +140,18 @@ hash_of_games[2012030311].instance_variable_set(:@home_goals, 15) hash_of_games[2012030312].instance_variable_set(:@away_goals, 15) - hash_of_games[2012030312].instance_variable_set(:@home_goals, 15) + hash_of_games[2012030312].instance_variable_set(:@home_goals, 15) # UPDATE DATA SO TIES AND WINS ARE 50/50 expect(@stat_tracker.percentage_ties).to eq(0.50) end end + describe 'average_goals_per_game' do + it 'can find the average amount of goals per game for entire season' do + expect(@stat_tracker.average_goals_per_game).to eq(1.75) + end + end + # describe 'count_of_teams' do # end From c03b8345c75a7a34f08640b28fcc39181319ac87 Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Thu, 1 Aug 2024 15:20:44 -0500 Subject: [PATCH 26/97] feat:completed lowest_total_score method --- lib/stat_tracker.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 95c4e0343f..ed12cbfe54 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -27,6 +27,13 @@ def highest_total_score highest_scoring_game[1].total_goals end + def lowest_total_score + lowest_scoring_game = @game_stats_data.min_by do |game_id, game_object| + game_object.away_goals + game_object.home_goals + end + lowest_scoring_game[1].away_goals + lowest_scoring_game[1].home_goals + end + def percentage_home_wins win_count = @game_stats_data.count do |game_id, game| game.home_goals > game.away_goals From 5abca3db221717d263c07d9a192f1cbeded46cf4 Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Thu, 1 Aug 2024 15:22:21 -0500 Subject: [PATCH 27/97] test:lowest_total_score rspec test added --- spec/stat_tracker_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 2bcc88b983..8f1f75cb91 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -107,6 +107,12 @@ end end + describe 'lowest_total_score' do + it 'returns lowest sum of the winning and losing teams scores' do + expect(@stat_tracker.lowest_total_score).to eq(1) + end + end + describe 'percentage_home_wins' do it 'returns percentage of games that a home team has won' do expect(@stat_tracker.percentage_home_wins).to eq(64.28) From 3626c3f5ec674991a4903e928027d27b0438a20f Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Thu, 1 Aug 2024 15:43:39 -0500 Subject: [PATCH 28/97] refactor:reused helper method in lowest_total_score --- lib/stat_tracker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index ed12cbfe54..9f278eb7e4 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -31,7 +31,7 @@ def lowest_total_score lowest_scoring_game = @game_stats_data.min_by do |game_id, game_object| game_object.away_goals + game_object.home_goals end - lowest_scoring_game[1].away_goals + lowest_scoring_game[1].home_goals + lowest_scoring_game[1].total_goals end def percentage_home_wins From 1890b52df556285acf26d605892a8ce2dde7fbb3 Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Thu, 1 Aug 2024 14:49:25 -0600 Subject: [PATCH 29/97] refactor: more psudocode --- lib/stat_tracker.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index c08d797286..412cc55333 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -38,9 +38,10 @@ def best_offense score_tracker = Hash.new(0) @game_stats_data.each do |game_id, game| - score_tracker[game.away_team_id] = game.away_goals - score_tracker[game.home_team_id] = game.home_goals - require 'pry'; binding.pry + goal_count = [] + score_tracker[game.away_team_id] = goal_count << game.away_goals + score_tracker[game.home_team_id] = goal_count << game.home_goals + # require 'pry'; binding.pry end # iterate through the data # make an accumulator to track goals/game for each team id @@ -50,6 +51,15 @@ def best_offense # # lastly make method to associate team id in game with team id in teams # and return teams_dummy.teamname.to_s + # id_to_name(return value of best offense) + end + + def id_to_name(id) + @teams_stats_data.each do |team_id, team| + if team_id == id + team.teamName.to_s + end + end end def self.game_reader(csv_data) From 9a86425470995159196655a8416105621d256e61 Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Thu, 1 Aug 2024 16:04:04 -0500 Subject: [PATCH 30/97] feat:Created lowest_total_score method. --- lib/stat_tracker.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 093ab673e9..963fc627ca 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -53,6 +53,13 @@ def highest_total_score highest_scoring_game[1].total_goals end + def lowest_total_score + lowest_scoring_game = @game_stats_data.min_by do |game_id, game_object| + game_object.away_goals + game_object.home_goals + end + lowest_scoring_game[1].total_goals + end + def percentage_home_wins win_count = @game_stats_data.count do |game_id, game| game.home_goals > game.away_goals From 4b1895b345bf5365de5a6ab50853b1aa77e1e8b9 Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Thu, 1 Aug 2024 17:18:10 -0400 Subject: [PATCH 31/97] feat-pass test for average_goals_per_game --- lib/stat_tracker.rb | 19 ++++++++++++++----- spec/stat_tracker_spec.rb | 9 ++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 093ab673e9..36da77a193 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -54,17 +54,26 @@ def highest_total_score end def percentage_home_wins - win_count = @game_stats_data.count do |game_id, game| - game.home_goals > game.away_goals + win_count = @game_stats_data.count do |game_id, game_object| + game_object.home_goals > game_object.away_goals end ((win_count.to_f / @game_stats_data.length) * 100).truncate(2) end def percentage_ties - tie_count = @game_stats_data.count do |game_id, game| - game.home_goals == game.away_goals + tie_count = @game_stats_data.count do |game_id, game_object| + game_object.home_goals == game_object.away_goals end - ((tie_count.to_f/ @game_stats_data.length).truncate(2)) + ((tie_count.to_f / @game_stats_data.length).truncate(2)) + end + + def average_goals_per_game + total_goals_per_game = [] + @game_stats_data.each do |game_id, game_object| + total_goals_per_game << game_object.total_goals + end + + (total_goals_per_game.sum / total_goals_per_game.length.to_f).round(2) end # def count_of_teams diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 5b3f29920f..f63f0769bc 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -148,8 +148,15 @@ describe 'average_goals_per_game' do it 'can find the average amount of goals per game for entire season' do - expect(@stat_tracker.average_goals_per_game).to eq(1.75) + expect(@stat_tracker.average_goals_per_game).to eq(3.5) + + hash_of_games = @stat_tracker.instance_variable_get(:@game_stats_data) + + hash_of_games[2012030222].instance_variable_set(:@away_goals, 329) + + expect(@stat_tracker.average_goals_per_game).to eq(26.86) end + end # describe 'count_of_teams' do From 6fd337a8933b829325654146df014ec2bcc367e6 Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Thu, 1 Aug 2024 18:55:56 -0400 Subject: [PATCH 32/97] feat: add prelim test for highest_scoring_visitor --- lib/stat_tracker.rb | 2 +- spec/stat_tracker_spec.rb | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index fb2461c4d1..657cd7d5bc 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -96,7 +96,7 @@ def average_goals_per_game # end # def highest_scoring_visitor - + # end # def highest_scoring_home_team diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 76d0f021b3..b5d154935c 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -177,9 +177,15 @@ # end - # describe 'highest_scoring_visitor' do + describe 'highest_scoring_visitor' do + it 'returns name of the team with the highest average score per game across all seasons when they are away.' do + hash_of_games = @stat_tracker.instance_variable_get(:@game_stats_data) - # end + hash_of_games[2012030221].instance_variable_set(:@away_goals, 50000) + + expect(@stat_tracker.highest_scoring_visitor).to eq("Houston Dynamo") + end + end # describe 'highest_scoring_home_team' do From 8fcb5d3f6b1d5d72fce40da627c11e24e277c73b Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Thu, 1 Aug 2024 20:02:12 -0400 Subject: [PATCH 33/97] feat: pass prelim test for highest_scoring_visitor --- lib/stat_tracker.rb | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 657cd7d5bc..6c5b5a07d5 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -95,9 +95,26 @@ def average_goals_per_game # end - # def highest_scoring_visitor - - # end + def highest_scoring_visitor + visitor_team_scores = Hash.new + @game_stats_data.each do |game_id, game_object| + if !(visitor_team_scores.keys.include?(game_object.away_team_id)) + visitor_team_scores[game_object.away_team_id] = [] + visitor_team_scores[game_object.away_team_id].push(game_object.away_goals) + else + visitor_team_scores[game_object.away_team_id].push(game_object.away_goals) + end + end + winning_team = visitor_team_scores.max_by do |team, scores| + scores.sum / scores.length + end + + @teams_stats_data.each do |team_id, team_object| + if winning_team[0] == team_id + return team_object.team_name + end + end + end # def highest_scoring_home_team From 73628f65216af24c114e5f50fc40fc34d9b10bcf Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Thu, 1 Aug 2024 20:03:34 -0400 Subject: [PATCH 34/97] feat: complete test and imp for highest_scoring_visitor --- spec/stat_tracker_spec.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index b5d154935c..0456c863be 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -179,11 +179,7 @@ describe 'highest_scoring_visitor' do it 'returns name of the team with the highest average score per game across all seasons when they are away.' do - hash_of_games = @stat_tracker.instance_variable_get(:@game_stats_data) - - hash_of_games[2012030221].instance_variable_set(:@away_goals, 50000) - - expect(@stat_tracker.highest_scoring_visitor).to eq("Houston Dynamo") + expect(@stat_tracker.highest_scoring_visitor).to eq("FC Dallas") end end From 70dda995816327bc2e74c260f993117baf0fa250 Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Thu, 1 Aug 2024 20:16:56 -0400 Subject: [PATCH 35/97] fix- fixes rounding error which occurs in full dataset --- lib/stat_tracker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 6c5b5a07d5..0c7cf94921 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -106,7 +106,7 @@ def highest_scoring_visitor end end winning_team = visitor_team_scores.max_by do |team, scores| - scores.sum / scores.length + (scores.sum / scores.length.to_f).round(2) end @teams_stats_data.each do |team_id, team_object| From cd79e9a6ced8e41d5fdfc77426f9bb84f53bc040 Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Thu, 1 Aug 2024 18:18:03 -0600 Subject: [PATCH 36/97] fix: building out #best_offense --- lib/stat_tracker.rb | 24 ++++++++++++++++++------ spec/stat_tracker_spec.rb | 5 ----- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index fcbafe34d8..d3c8418390 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -72,14 +72,26 @@ def percentage_ties # end def best_offense - score_tracker = Hash.new(0) - @game_stats_data.each do |game_id, game| - goal_count = [] - score_tracker[game.away_team_id] = goal_count << game.away_goals - score_tracker[game.home_team_id] = goal_count << game.home_goals - # require 'pry'; binding.pry + teams_goals = Hash.new(0) + games_played = Hash.new(0) + + @seasons_stats_data.each do |game_id, season| + teams_goals[season.team_id] += season.goals + games_played[season.team_id] += 1 + require 'pry'; binding.pry + end + + best_offense_teamid = teams_goals.max_by do |team_id, goals| + goals / end + + # @game_stats_data.each do |game_id, game| + # goal_count = [] + # score_tracker[game.away_team_id] = goal_count << game.away_goals + # score_tracker[game.home_team_id] = goal_count << game.home_goals + # # require 'pry'; binding.pry + # end # iterate through the data # make an accumulator to track goals/game for each team id # counter = [], counter += game.goals diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 31b880f965..8347456abb 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -199,9 +199,4 @@ # describe 'fewest_tackles' do # end - describe 'best_offense' do - it 'returns team yielding highest goals scored per game over all seasons' do - expect(@stat_tracker.best_offense).to eq("FC Dallas") - end - end end \ No newline at end of file From 2b04bd35796ae1368018407174e917098673dcb6 Mon Sep 17 00:00:00 2001 From: Shawn Thompson Date: Thu, 1 Aug 2024 19:56:05 -0500 Subject: [PATCH 37/97] feat: count_of_games_season --- lib/stat_tracker.rb | 10 ++++++++++ spec/stat_tracker_spec.rb | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index fb2461c4d1..8ddc5e982d 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -74,6 +74,16 @@ def percentage_ties ((tie_count.to_f / @game_stats_data.length).truncate(2)) end + def count_of_games_by_season + season_game_count = Hash.new(0) + @game_stats_data.each do |game_id, game_object| + season = game_object.season + season_game_count[season] += 1 + end + + season_game_count + end + def average_goals_per_game total_goals_per_game = [] @game_stats_data.each do |game_id, game_object| diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 76d0f021b3..8e4a76ffe3 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -165,6 +165,37 @@ end + describe 'count_of_games_by_season' do + it 'returns sum of games per season on dummy file' do + expect(@stat_tracker.count_of_games_by_season).to eq(20122013 => 14) + end + + it 'returns sum of games per season on mocks' do + hash = @stat_tracker.instance_variable_get(:@game_stats_data) + + object_1 = hash[2012030221] + object_2 = hash[2012030222] + object_3 = hash[2012030223] + object_4 = hash[2012030224] + object_5 = hash[2012030225] + object_6 = hash[2012030312] + object_7 = hash[2012030233] + + + object_1.instance_variable_set(:@season, (20122013 + 1)) + object_2.instance_variable_set(:@season, (20122013 + 2)) + object_3.instance_variable_set(:@season, (20122013 + 2)) + object_4.instance_variable_set(:@season, (20122013 + 4)) + object_5.instance_variable_set(:@season, (20122013 + 4)) + object_6.instance_variable_set(:@season, (20122013 + 4)) + object_7.instance_variable_set(:@season, (20122013 + 4)) + + expected = {20122014=>1, 20122015=>2, 20122017=>4, 20122013=>7} + + expect(@stat_tracker.count_of_games_by_season).to eq(expected) + end + + end # describe 'count_of_teams' do # end From fbeaa3e622c5aef49d2ceac2af568a348f35e385 Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Thu, 1 Aug 2024 21:24:10 -0400 Subject: [PATCH 38/97] feat- add prelim test for least_accurate_team --- spec/stat_tracker_spec.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 0456c863be..4693574f76 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -207,9 +207,16 @@ # end - # describe 'least_accurate_team' do + describe 'least_accurate_team' do + it 'returns name of the Team with the worst ratio of shots to goals for the season.' do + hash_of_games = @stat_tracker.instance_variable_get(:@seasons_stats_data) - # end + hash_of_games[1].instance_variable_set(:@goals, 100) + hash_of_games[1].instance_variable_set(:@shots, 0) + + expect(@stat_tracker.least_accurate_team).to eq('Houston Dynamo') + end + end # describe 'most_tackles' do From f18953449ddbcb4ac0f006dac78710f3a25684ba Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Thu, 1 Aug 2024 20:53:33 -0600 Subject: [PATCH 39/97] feat: best offense and id to name methods --- lib/stat_tracker.rb | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index d3c8418390..4ba7ed0f7d 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -79,35 +79,21 @@ def best_offense @seasons_stats_data.each do |game_id, season| teams_goals[season.team_id] += season.goals games_played[season.team_id] += 1 - require 'pry'; binding.pry end - best_offense_teamid = teams_goals.max_by do |team_id, goals| - goals / + best_offense_team = teams_goals.max_by do |team_id, goals| + goals.to_f / games_played[team_id].to_f end - # @game_stats_data.each do |game_id, game| - # goal_count = [] - # score_tracker[game.away_team_id] = goal_count << game.away_goals - # score_tracker[game.home_team_id] = goal_count << game.home_goals - # # require 'pry'; binding.pry - # end - # iterate through the data - # make an accumulator to track goals/game for each team id - # counter = [], counter += game.goals - # counter / games played = avg goals per game - # find team that is associated with the highest avg goals per game - # - # lastly make method to associate team id in game with team id in teams - # and return teams_dummy.teamname.to_s - # id_to_name(return value of best offense) + best_offense_team_id = best_offense_team[0] + + id_to_name(best_offense_team_id) + end def id_to_name(id) @teams_stats_data.each do |team_id, team| - if team_id == id - team.teamName.to_s - end + return team.team_name.to_s if team_id == id end end From 82c9399410959e4428eaa3ab6f630c224142a5a8 Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Thu, 1 Aug 2024 21:32:02 -0600 Subject: [PATCH 40/97] test: id to name helper method --- lib/stat_tracker.rb | 1 - spec/stat_tracker_spec.rb | 11 ++++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 4ba7ed0f7d..156ad357f0 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -88,7 +88,6 @@ def best_offense best_offense_team_id = best_offense_team[0] id_to_name(best_offense_team_id) - end def id_to_name(id) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 8347456abb..b0d350c1ff 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -155,7 +155,16 @@ expect(@stat_tracker.best_offense).to eq("FC Dallas") end end - + + describe 'id_to_name' do + it 'returns name from id' do + @teams_stats_data = StatTracker.teams_reader(@locations[:teams]) + @teams_stats_data.each do |team_id, team_object| + expect(@stat_tracker.id_to_name(team_id)).to eq(team_object.team_name) + end + end + end + # describe 'worst_offense' do # end From 9d7f5f2a66036bdb01d385f41001b58101dae54e Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Thu, 1 Aug 2024 21:51:37 -0600 Subject: [PATCH 41/97] test: test suite for lowest scoring visitor --- lib/stat_tracker.rb | 4 ++-- spec/stat_tracker_spec.rb | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 156ad357f0..7fa955ea28 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -108,9 +108,9 @@ def id_to_name(id) # end - # def lowest_scoring_visitor + def lowest_scoring_visitor - # end + end # def lowest_scoring_home_team diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index b0d350c1ff..3a984bb402 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -152,7 +152,7 @@ describe 'best_offense' do it 'returns team yielding highest goals scored per game over all seasons' do - expect(@stat_tracker.best_offense).to eq("FC Dallas") + expect(@stat_tracker.best_offense).to eq('FC Dallas') end end @@ -177,9 +177,11 @@ # end - # describe 'lowest_scoring_visitor' do - - # end + describe 'lowest_scoring_visitor' do + it 'returns lowest average scoring team when they are a visitor.' do + expect(@stat_tracker.lowest_scoring_visitor).to eq('LA Galaxy') + end + end # describe 'lowest_scoring_home_team' do From 95cb89ff43dc7d5648358b7bb97c1a4e8bc9697c Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Thu, 1 Aug 2024 22:16:15 -0600 Subject: [PATCH 42/97] feat: lowest scoring visitor --- lib/stat_tracker.rb | 13 +++++++++++++ spec/stat_tracker_spec.rb | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 7fa955ea28..08709af5c3 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -109,7 +109,20 @@ def id_to_name(id) # end def lowest_scoring_visitor + teams_goals = Hash.new(0) + games_played = Hash.new(0) + + @game_stats_data.each do |game_id, game| + teams_goals[game.away_team_id] += game.away_goals + games_played[game.away_team_id] += 1 + end + + worst_visitors = teams_goals.min_by do |team_id, away_goals| + away_goals.to_f / games_played[team_id].to_f + end + worst_visitor_id = worst_visitors[0] + id_to_name(worst_visitor_id) end # def lowest_scoring_home_team diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 3a984bb402..c6237e3232 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -179,7 +179,7 @@ describe 'lowest_scoring_visitor' do it 'returns lowest average scoring team when they are a visitor.' do - expect(@stat_tracker.lowest_scoring_visitor).to eq('LA Galaxy') + expect(@stat_tracker.lowest_scoring_visitor).to eq('Sporting Kansas City') end end From fa71cbbff6f8ec1c35142efa9ec4544c5621eedc Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Thu, 1 Aug 2024 22:21:51 -0600 Subject: [PATCH 43/97] test: worst coach test suite, assertion line draft 1 --- spec/stat_tracker_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index c6237e3232..5fad7c6bc1 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -191,9 +191,11 @@ # end - # describe 'worst_coach' do - - # end + describe 'worst_coach' do + it 'returns coach with worst win percentage for the season' do + expect(@stat_tracker.worst_coach).to eq('ur mom') + end + end # describe 'most_accurate_team' do From 22d7e6ac5e43f44bc3b9f62d3339408bf411aa2b Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Fri, 2 Aug 2024 09:33:19 -0400 Subject: [PATCH 44/97] pass test for least_accurate_team --- lib/stat_tracker.rb | 41 ++++++++++++++++++++++++++++++++++++--- spec/stat_tracker_spec.rb | 9 +++------ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 0c7cf94921..5d686de7c7 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -96,7 +96,7 @@ def average_goals_per_game # end def highest_scoring_visitor - visitor_team_scores = Hash.new + visitor_team_scores = {} @game_stats_data.each do |game_id, game_object| if !(visitor_team_scores.keys.include?(game_object.away_team_id)) visitor_team_scores[game_object.away_team_id] = [] @@ -140,9 +140,44 @@ def highest_scoring_visitor # end - # def least_accurate_team + def least_accurate_team(specific_season) + specific_season_integer = specific_season.to_i + games_in_season = {specific_season => []} + @game_stats_data.each do |game_id, game_object| + games_in_season[specific_season].push(game_id) if game_object.season == specific_season_integer + end - # end + teams_goal_ratio = {} + + @seasons_stats_data.each do |game_key, game_object| + if games_in_season[specific_season].include?(game_object.game_id) + if !(teams_goal_ratio.keys.include?(game_object.team_id)) + if game_object.shots > 0 + teams_goal_ratio[game_object.team_id] = [] + teams_goal_ratio[game_object.team_id].push((game_object.goals / game_object.shots.to_f).truncate(2)) + else + teams_goal_ratio[game_object.team_id].push(0.00) + end + else + if game_object.shots > 0 + teams_goal_ratio[game_object.team_id].push((game_object.goals / game_object.shots.to_f).truncate(2)) + else + teams_goal_ratio[game_object.team_id].push(0.00) + end + end + end + end + + lowest_accuracy_team = teams_goal_ratio.min_by do |team, accuracy_per_game| + accuracy_per_game.sum / accuracy_per_game.length + end + + @teams_stats_data.each do |team_id, team_object| + if lowest_accuracy_team[0] == team_id + return team_object.team_name + end + end + end # def most_tackles diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 4693574f76..14d799664b 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -209,12 +209,9 @@ describe 'least_accurate_team' do it 'returns name of the Team with the worst ratio of shots to goals for the season.' do - hash_of_games = @stat_tracker.instance_variable_get(:@seasons_stats_data) - - hash_of_games[1].instance_variable_set(:@goals, 100) - hash_of_games[1].instance_variable_set(:@shots, 0) - - expect(@stat_tracker.least_accurate_team).to eq('Houston Dynamo') + expect(@stat_tracker.least_accurate_team("20122013")).to eq('Sporting Kansas City') + #expect(@stat_tracker.least_accurate_team(20132014)).to eq "New York City FC" + #expect(@stat_tracker.least_accurate_team(20142015)).to eq "Columbus Crew SC" end end From d9829d3d99840875aa402dad8de2a3d51a0a16e3 Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Fri, 2 Aug 2024 09:00:24 -0600 Subject: [PATCH 45/97] refactor: merged helper method into best offense test suite --- lib/stat_tracker.rb | 10 ++++++++-- spec/stat_tracker_spec.rb | 12 +++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 08709af5c3..81dd356403 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -133,9 +133,15 @@ def lowest_scoring_visitor # end - # def worst_coach + def worst_coach + # use game_teams. + # similar test structure as BO / LSV + # compare team id to winn vs loss + #make helper method to take team 1d and return coach + #helper method test should iterate over game_teams + # - # end + end # def most_accurate_team diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 5fad7c6bc1..500e136d8c 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -151,18 +151,16 @@ # end describe 'best_offense' do - it 'returns team yielding highest goals scored per game over all seasons' do - expect(@stat_tracker.best_offense).to eq('FC Dallas') - end - end - - describe 'id_to_name' do it 'returns name from id' do @teams_stats_data = StatTracker.teams_reader(@locations[:teams]) @teams_stats_data.each do |team_id, team_object| expect(@stat_tracker.id_to_name(team_id)).to eq(team_object.team_name) end end + + it 'returns team yielding highest goals scored per game over all seasons' do + expect(@stat_tracker.best_offense).to eq('FC Dallas') + end end # describe 'worst_offense' do @@ -191,7 +189,7 @@ # end - describe 'worst_coach' do + xdescribe 'worst_coach' do it 'returns coach with worst win percentage for the season' do expect(@stat_tracker.worst_coach).to eq('ur mom') end From 35f3137de7d4a0b2b5d43d0ce3df40a3ee3cd65e Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Fri, 2 Aug 2024 16:11:43 -0500 Subject: [PATCH 46/97] feat: count_of_teams method created --- lib/stat_tracker.rb | 6 +++--- spec/stat_tracker_spec.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 963fc627ca..0b19a6e45d 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -74,9 +74,9 @@ def percentage_ties ((tie_count.to_f/ @game_stats_data.length).truncate(2)) end - # def count_of_teams - - # end + def count_of_teams + @teams_stats_data.size + end # def best_offense diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 3dfe89d2d8..b796bf8060 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -152,9 +152,9 @@ end end - # describe 'count_of_teams' do - - # end + describe 'count_of_teams' do + + end # describe 'best_offense' do From 01f97a9602be1ec87c7c27993138964059298f1e Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Fri, 2 Aug 2024 16:12:44 -0500 Subject: [PATCH 47/97] test:count_of_teams rspec test created --- spec/stat_tracker_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index b796bf8060..b65c1b39f0 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -153,7 +153,9 @@ end describe 'count_of_teams' do - + it 'returns the total number of teams' do + expect(@stat_tracker.count_of_teams).to eq(14) + end end # describe 'best_offense' do From 866fd924ef65dabad468a6d0a4faedf8e963ff86 Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Fri, 2 Aug 2024 15:13:36 -0600 Subject: [PATCH 48/97] docs: readme includes retro meeting points --- README.md | 91 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 3f67a6f9e4..a024e62bda 100644 --- a/README.md +++ b/README.md @@ -2,49 +2,74 @@ ## Deliverables - **Outline of Check-ins** - * We are planning on having a standup meeting 30 minutes before class, as well as a daily post class check in. - * We plan on a larger meeting to redefine DTR on friday(tentatively). +**Outline of Check-ins** - **Plan Organization** - * We are utilizing Github Project as our primary organization source. - * [Link to Github Project](https://github.com/users/kylomite/projects/3/views/1) - * Using Google Docs to organize more qualitative team building points. - * [Link to Google Doc](https://docs.google.com/document/d/15GMwPuLY4e56yfuwuGLphfTAbCh9uTJGeSz-cAkhpqg/edit) - * Frequent communication via Slack will be the standard. +* We are planning on having a standup meeting 30 minutes before class, as well as a daily post class check in. +* We plan on a larger meeting to redefine DTR on friday(tentatively). - **Project Organizer Discussion** - * When discussing the project organization tool, we considered Mirrorboard and Github Projects, but ultimately chose Github Projects due to its utility and seamless integration with our repository. - * We all agreed Github Project is most likely the industry standard and it would behoove us to familiarize ourselves with the application. +**Plan Organization** +* We are utilizing Github Project as our primary organization source. + * [Link to Github Project](https://github.com/users/kylomite/projects/3/views/1) +* Using Google Docs to organize more qualitative team building points. + * [Link to Google Doc](https://docs.google.com/document/d/15GMwPuLY4e56yfuwuGLphfTAbCh9uTJGeSz-cAkhpqg/edit) +* Frequent communication via Slack will be the standard. - **Code Design** - * Expand upon this. - * We have implemented a style guide to adhere to for consistency. - * [Link to Style Guide](https://docs.google.com/document/d/1AS3GIR84IMyoNUbN8eiSnuM3o6o9fscvlKvjhJSxokc/edit) +**Project Organizer Discussion** +* When discussing the project organization tool, we considered Mirrorboard and Github Projects, but ultimately chose Github Projects due to its utility and seamless integration with our repository. +* We all agreed Github Project is most likely the industry standard and it would behoove us to familiarize ourselves with the application. - **DTRs** - * [First DTR 7/29/24](https://docs.google.com/document/d/1HEdpmbyhJbeJtJJ8pkOvZ5zeb07FeqkCZlBai6aSP0s/edit) +**Code Design** +* Expand upon this. +* We have implemented a style guide to adhere to for consistency. + * [Link to Style Guide](https://docs.google.com/document/d/1AS3GIR84IMyoNUbN8eiSnuM3o6o9fscvlKvjhJSxokc/edit) + +**DTRs** + +* [First DTR 7/29/24](https://docs.google.com/document/d/1HEdpmbyhJbeJtJJ8pkOvZ5zeb07FeqkCZlBai6aSP0s/edit) + +## Project Retro + +**Retro** + +* [Link](https://docs.google.com/document/d/1HEdpmbyhJbeJtJJ8pkOvZ5zeb07FeqkCZlBai6aSP0s/edit) to project retro. + +* How to run a [retro](https://www.atlassian.com/team-playbook/plays/retrospective) + +**What Went Well** + +* Details in retro, but in summary: + + 1. Communication + 1. Code Design + 1. Group Dynamic + +**Future Improvements** + +* Details in retro, but in summary: + 1. Code Spikes + 1. Refactoring + 1. Detail Orientation ## Contributors - * **Chirchirillo, Joe** - * [Github](https://github.com/jchirch) - * [LinkedIn](https://www.linkedin.com/in/joe-chirchirillo-a73b09318/) +* **Chirchirillo, Joe** + * [Github](https://github.com/jchirch) + * [LinkedIn](https://www.linkedin.com/in/joe-chirchirillo-a73b09318/) - * **Delaney, Kyle** - * [Github](https://github.com/kylomite) - * [LinkedIn](https://www.linkedin.com/in/kyle-delaney-115164172/edit/forms/next-action/after-connect-add-position/) +* **Delaney, Kyle** + * [Github](https://github.com/kylomite) + * [LinkedIn](https://www.linkedin.com/in/kyle-delaney-115164172/edit/forms/next-action/after-connect-add-position/) - * **Hill, John** - * [Github](https://github.com/jphill19) - * [LinkedIn](https://www.linkedin.com/in/john-hill-309715245/) +* **Hill, John** + * [Github](https://github.com/jphill19) + * [LinkedIn](https://www.linkedin.com/in/john-hill-309715245/) - * **Thompson, Shawn** - * [Github](https://github.com/SThompson05) - * [LinkedIn](https://www.linkedin.com/in/shawn-thompson-16956267/) +* **Thompson, Shawn** + * [Github](https://github.com/SThompson05) + * [LinkedIn](https://www.linkedin.com/in/shawn-thompson-16956267/) - * **Willett, Bryan** - * [Github](https://github.com/bwillett2003) - * [LinkedIn](https://www.youtube.com/watch?v=ub82Xb1C8os&ab_channel=JuiceboxHero) +* **Willett, Bryan** + * [Github](https://github.com/bwillett2003) + * [LinkedIn](https://www.youtube.com/watch?v=ub82Xb1C8os&ab_channel=JuiceboxHero) From 5a3a4b0d9750e4893dba17066c337cd0098a2bf9 Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Fri, 2 Aug 2024 15:22:50 -0600 Subject: [PATCH 49/97] refactor: method returns correct format for percentages --- lib/stat_tracker.rb | 2 +- spec/stat_tracker_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 08709af5c3..dcea15cd4e 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -57,7 +57,7 @@ def percentage_home_wins win_count = @game_stats_data.count do |game_id, game| game.home_goals > game.away_goals end - ((win_count.to_f / @game_stats_data.length) * 100).truncate(2) + ((win_count.to_f / @game_stats_data.length)).round(2) end def percentage_ties diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 5fad7c6bc1..717459f6ec 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -109,7 +109,7 @@ describe 'percentage_home_wins' do it 'returns percentage of games that a home team has won' do - expect(@stat_tracker.percentage_home_wins).to eq(64.28) + expect(@stat_tracker.percentage_home_wins).to eq(0.64) end end From 5b00bdd0641668d38cc78549d58636f5c8f25684 Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Fri, 2 Aug 2024 18:54:34 -0400 Subject: [PATCH 50/97] add prelim test for fewest_tackles --- spec/stat_tracker_spec.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 971075cf22..76f25bdc73 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -224,7 +224,7 @@ describe 'least_accurate_team' do it 'returns name of the Team with the worst ratio of shots to goals for the season.' do - expect(@stat_tracker.least_accurate_team("20122013")).to eq('Sporting Kansas City') + expect(@stat_tracker.least_accurate_team('20122013')).to eq('Sporting Kansas City') #expect(@stat_tracker.least_accurate_team(20132014)).to eq "New York City FC" #expect(@stat_tracker.least_accurate_team(20142015)).to eq "Columbus Crew SC" end @@ -234,7 +234,9 @@ # end - # describe 'fewest_tackles' do - - # end + describe 'fewest_tackles' do + it 'returns name of the Team with the fewest tackles in the season' do + expect(@stat_tracker.fewest_tackles('20122013')).to eq("Houston Dynamo") + end + end end \ No newline at end of file From 8f30ecb78e85a9e2fc126296e8694e5077f6f1e2 Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Fri, 2 Aug 2024 19:15:07 -0400 Subject: [PATCH 51/97] pass test for fewest_tackles --- lib/stat_tracker.rb | 46 ++++++++++++++++++++++++++++++--------- spec/stat_tracker_spec.rb | 2 +- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 0026c587c8..1b89fd1fc6 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -187,28 +187,28 @@ def least_accurate_team(specific_season) games_in_season[specific_season].push(game_id) if game_object.season == specific_season_integer end - teams_goal_ratio = {} + team_goal_ratio = {} @seasons_stats_data.each do |game_key, game_object| if games_in_season[specific_season].include?(game_object.game_id) - if !(teams_goal_ratio.keys.include?(game_object.team_id)) + if !(team_goal_ratio.keys.include?(game_object.team_id)) if game_object.shots > 0 - teams_goal_ratio[game_object.team_id] = [] - teams_goal_ratio[game_object.team_id].push((game_object.goals / game_object.shots.to_f).truncate(2)) + team_goal_ratio[game_object.team_id] = [] + team_goal_ratio[game_object.team_id].push((game_object.goals / game_object.shots.to_f).truncate(2)) else - teams_goal_ratio[game_object.team_id].push(0.00) + team_goal_ratio[game_object.team_id].push(0.00) end else if game_object.shots > 0 - teams_goal_ratio[game_object.team_id].push((game_object.goals / game_object.shots.to_f).truncate(2)) + team_goal_ratio[game_object.team_id].push((game_object.goals / game_object.shots.to_f).truncate(2)) else - teams_goal_ratio[game_object.team_id].push(0.00) + team_goal_ratio[game_object.team_id].push(0.00) end end end end - lowest_accuracy_team = teams_goal_ratio.min_by do |team, accuracy_per_game| + lowest_accuracy_team = team_goal_ratio.min_by do |team, accuracy_per_game| accuracy_per_game.sum / accuracy_per_game.length end @@ -223,7 +223,33 @@ def least_accurate_team(specific_season) # end - # def fewest_tackles + def fewest_tackles(specific_season) + specific_season_integer = specific_season.to_i + games_in_season = {specific_season => []} + @game_stats_data.each do |game_id, game_object| + games_in_season[specific_season].push(game_id) if game_object.season == specific_season_integer + end - # end + team_total_tackles = {} + + @seasons_stats_data.each do |game_key, game_object| + if games_in_season[specific_season].include?(game_object.game_id) + if !(team_total_tackles.keys.include?(game_object.team_id)) + team_total_tackles[game_object.team_id] = 0 + team_total_tackles[game_object.team_id] += game_object.tackles + else + team_total_tackles[game_object.team_id] += game_object.tackles + end + end + end + lowest_tackling_team = team_total_tackles.min_by do |team_id, tackles| + tackles + end + + @teams_stats_data.each do |team_id, team_object| + if lowest_tackling_team[0] == team_id + return team_object.team_name + end + end + end end \ No newline at end of file diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 76f25bdc73..546c41f800 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -236,7 +236,7 @@ describe 'fewest_tackles' do it 'returns name of the Team with the fewest tackles in the season' do - expect(@stat_tracker.fewest_tackles('20122013')).to eq("Houston Dynamo") + expect(@stat_tracker.fewest_tackles('20122013')).to eq("Sporting Kansas City") end end end \ No newline at end of file From 0c7b44329b297cf5c46e7eeec9d97cb10f2a773c Mon Sep 17 00:00:00 2001 From: Shawn Thompson Date: Fri, 2 Aug 2024 18:30:52 -0500 Subject: [PATCH 52/97] test: updated test language --- spec/stat_tracker_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 8e4a76ffe3..2a38458aa4 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -166,7 +166,7 @@ end describe 'count_of_games_by_season' do - it 'returns sum of games per season on dummy file' do + it 'returns sum of games per season' do expect(@stat_tracker.count_of_games_by_season).to eq(20122013 => 14) end @@ -180,7 +180,6 @@ object_5 = hash[2012030225] object_6 = hash[2012030312] object_7 = hash[2012030233] - object_1.instance_variable_set(:@season, (20122013 + 1)) object_2.instance_variable_set(:@season, (20122013 + 2)) From 7cc658445d6bdcd39f36e1e801549901c4d57335 Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Fri, 2 Aug 2024 19:42:30 -0600 Subject: [PATCH 53/97] feat: worst coach method and id to coach helper method --- lib/stat_tracker.rb | 49 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 08709af5c3..812f6fe85c 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -57,7 +57,7 @@ def percentage_home_wins win_count = @game_stats_data.count do |game_id, game| game.home_goals > game.away_goals end - ((win_count.to_f / @game_stats_data.length) * 100).truncate(2) + ((win_count.to_f / @game_stats_data.length)).round(2) end def percentage_ties @@ -133,10 +133,51 @@ def lowest_scoring_visitor # end - # def worst_coach + def worst_coach(specific_season) + specific_season_integer = specific_season.to_i - # end - + games_in_season = {specific_season => []} + @game_stats_data.each do |game_id, game_object| + games_in_season[specific_season].push(game_id) if game_object.season == specific_season_integer + end + + teams_total_results = {} + @seasons_stats_data.each do |game_id, game_object| + if games_in_season[specific_season].include?(game_object.game_id) + if !(teams_total_results.keys.include?(game_object.team_id)) + teams_total_results[game_object.team_id] = [] + teams_total_results[game_object.team_id].push(game_object.result) + else + teams_total_results[game_object.team_id].push(game_object.result) + end + end + end + + team_win_ratio = {} + teams_total_results.map do |team_id, total_results| + + win_counter = 0 + total_results.each do |result| + if result == "WIN" + win_counter += 1 + end + end + team_win_ratio[team_id] = (win_counter.to_f / total_results.length).truncate(2) + end + + worst_team = team_win_ratio.min_by do |team_id, win_ratio| + win_ratio + end + id_to_coach(worst_team[0]) + end + + def id_to_coach(id) + @seasons_stats_data.each do |game_id, game_object| + return game_object.head_coach if game_object.team_id == id + end + end + + # def most_accurate_team # end From f11ce6c4c1dc8a778c3b1ed9cfa2b7e50de05d33 Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Fri, 2 Aug 2024 19:43:14 -0600 Subject: [PATCH 54/97] test: id to coach helper method works across csv --- spec/stat_tracker_spec.rb | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 5fad7c6bc1..dddee6d14a 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -109,7 +109,7 @@ describe 'percentage_home_wins' do it 'returns percentage of games that a home team has won' do - expect(@stat_tracker.percentage_home_wins).to eq(64.28) + expect(@stat_tracker.percentage_home_wins).to eq(0.64) end end @@ -151,20 +151,19 @@ # end describe 'best_offense' do - it 'returns team yielding highest goals scored per game over all seasons' do - expect(@stat_tracker.best_offense).to eq('FC Dallas') - end - end - - describe 'id_to_name' do it 'returns name from id' do @teams_stats_data = StatTracker.teams_reader(@locations[:teams]) @teams_stats_data.each do |team_id, team_object| expect(@stat_tracker.id_to_name(team_id)).to eq(team_object.team_name) end end + + it 'returns team yielding highest goals scored per game over all seasons' do + expect(@stat_tracker.best_offense).to eq('FC Dallas') + end end + # describe 'worst_offense' do # end @@ -192,8 +191,16 @@ # end describe 'worst_coach' do + it 'returns coach from id' do + @seasons_stats_data = StatTracker.game_teams_reader(@locations[:game_teams]) + @seasons_stats_data.each do |game_id, game_object| + expect(@stat_tracker.id_to_coach(game_object.team_id)).to eq(game_object.head_coach) + end + end it 'returns coach with worst win percentage for the season' do - expect(@stat_tracker.worst_coach).to eq('ur mom') + hash_of_games = @stat_tracker.instance_variable_get(:@seasons_stats_data) + hash_of_games[1].instance_variable_set(:@result, "WIN") + expect(@stat_tracker.worst_coach('20122013')).to eq('Dan Bylsma') end end From efc55841bad8e7caf5489ec004ead896390e0f0f Mon Sep 17 00:00:00 2001 From: Shawn Thompson Date: Fri, 2 Aug 2024 23:23:13 -0500 Subject: [PATCH 55/97] feat: average_goals_by_season --- lib/stat_tracker.rb | 12 ++++++++++++ spec/stat_tracker_spec.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 13ac6a37ff..9b1b22bd9c 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -84,6 +84,18 @@ def count_of_games_by_season season_game_count end + def average_goals_by_season + season_game_count = Hash.new(0) + total_season_goals = Hash.new(0) + @game_stats_data.each do |game_id, game_object| + season = game_object.season + goals = game_object.total_goals + season_game_count[season] += 1 + total_season_goals[season] += goals + end + total_season_goals.merge!(season_game_count) {|season, goals, games| (goals / games.to_f).round(2)} + end + def average_goals_per_game total_goals_per_game = [] @game_stats_data.each do |game_id, game_object| diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 576d5287d7..1466333b88 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -195,6 +195,36 @@ end end + + describe 'average_goals_by_season' do + it 'returns the average of goals by season' do + expect(@stat_tracker.average_goals_by_season).to eq(20122013 => 3.5) + end + + it 'returns sum of games per season on mocks' do + hash = @stat_tracker.instance_variable_get(:@game_stats_data) + + object_1 = hash[2012030221] + object_2 = hash[2012030222] + object_3 = hash[2012030223] + object_4 = hash[2012030224] + object_5 = hash[2012030225] + object_6 = hash[2012030312] + object_7 = hash[2012030233] + + object_1.instance_variable_set(:@season, (20122013 + 1)) + object_2.instance_variable_set(:@season, (20122013 + 2)) + object_3.instance_variable_set(:@season, (20122013 + 2)) + object_4.instance_variable_set(:@season, (20122013 + 4)) + object_5.instance_variable_set(:@season, (20122013 + 4)) + object_6.instance_variable_set(:@season, (20122013 + 4)) + object_7.instance_variable_set(:@season, (20122013 + 4)) + + expected = {20122014=>5, 20122015=>4, 20122017=>4.5, 20122013=>2.57} + + expect(@stat_tracker.average_goals_by_season).to eq(expected) + end + end # describe 'count_of_teams' do # end From ca02120e0a4dc8a7e955d47656ae43fdd2063e08 Mon Sep 17 00:00:00 2001 From: Shawn Thompson Date: Fri, 2 Aug 2024 23:29:39 -0500 Subject: [PATCH 56/97] refactor: average_goals_by_season --- lib/stat_tracker.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 9b1b22bd9c..af80c2e45c 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -93,7 +93,10 @@ def average_goals_by_season season_game_count[season] += 1 total_season_goals[season] += goals end - total_season_goals.merge!(season_game_count) {|season, goals, games| (goals / games.to_f).round(2)} + average = total_season_goals.merge!(season_game_count) do |season, goals, games| + (goals / games.to_f).round(2) + end + average end def average_goals_per_game From 6f7db2b2bb63b0caa153ba995a6d217bbc53b6c9 Mon Sep 17 00:00:00 2001 From: Shawn Thompson Date: Fri, 2 Aug 2024 23:43:01 -0500 Subject: [PATCH 57/97] feat: average_goals_by_season --- lib/stat_tracker.rb | 165 ++++++++++++++++++++++++++++++++++---- spec/stat_tracker_spec.rb | 96 +++++++++++++++++----- 2 files changed, 227 insertions(+), 34 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 8ddc5e982d..af80c2e45c 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -64,7 +64,7 @@ def percentage_home_wins win_count = @game_stats_data.count do |game_id, game_object| game_object.home_goals > game_object.away_goals end - ((win_count.to_f / @game_stats_data.length) * 100).truncate(2) + ((win_count.to_f / @game_stats_data.length)).round(2) end def percentage_ties @@ -84,6 +84,21 @@ def count_of_games_by_season season_game_count end + def average_goals_by_season + season_game_count = Hash.new(0) + total_season_goals = Hash.new(0) + @game_stats_data.each do |game_id, game_object| + season = game_object.season + goals = game_object.total_goals + season_game_count[season] += 1 + total_season_goals[season] += goals + end + average = total_season_goals.merge!(season_game_count) do |season, goals, games| + (goals / games.to_f).round(2) + end + average + end + def average_goals_per_game total_goals_per_game = [] @game_stats_data.each do |game_id, game_object| @@ -93,29 +108,80 @@ def average_goals_per_game (total_goals_per_game.sum / total_goals_per_game.length.to_f).round(2) end - # def count_of_teams - - # end + def count_of_teams + @teams_stats_data.size + end - # def best_offense + def best_offense - # end + teams_goals = Hash.new(0) + games_played = Hash.new(0) + + @seasons_stats_data.each do |game_id, season| + teams_goals[season.team_id] += season.goals + games_played[season.team_id] += 1 + end + + best_offense_team = teams_goals.max_by do |team_id, goals| + goals.to_f / games_played[team_id].to_f + end + + best_offense_team_id = best_offense_team[0] + + id_to_name(best_offense_team_id) + end + + def id_to_name(id) + @teams_stats_data.each do |team_id, team| + return team.team_name.to_s if team_id == id + end + end # def worst_offense # end - # def highest_scoring_visitor + def highest_scoring_visitor + visitor_team_scores = {} + @game_stats_data.each do |game_id, game_object| + if !(visitor_team_scores.keys.include?(game_object.away_team_id)) + visitor_team_scores[game_object.away_team_id] = [] + visitor_team_scores[game_object.away_team_id].push(game_object.away_goals) + else + visitor_team_scores[game_object.away_team_id].push(game_object.away_goals) + end + end + winning_team = visitor_team_scores.max_by do |team, scores| + (scores.sum / scores.length.to_f).round(2) + end - # end + @teams_stats_data.each do |team_id, team_object| + if winning_team[0] == team_id + return team_object.team_name + end + end + end # def highest_scoring_home_team # end - # def lowest_scoring_visitor + def lowest_scoring_visitor + teams_goals = Hash.new(0) + games_played = Hash.new(0) - # end + @game_stats_data.each do |game_id, game| + teams_goals[game.away_team_id] += game.away_goals + games_played[game.away_team_id] += 1 + end + + worst_visitors = teams_goals.min_by do |team_id, away_goals| + away_goals.to_f / games_played[team_id].to_f + end + + worst_visitor_id = worst_visitors[0] + id_to_name(worst_visitor_id) + end # def lowest_scoring_home_team @@ -125,23 +191,90 @@ def average_goals_per_game # end - # def worst_coach + def worst_coach + # use game_teams. + # similar test structure as BO / LSV + # compare team id to winn vs loss + #make helper method to take team 1d and return coach + #helper method test should iterate over game_teams + # - # end + end # def most_accurate_team # end - # def least_accurate_team + def least_accurate_team(specific_season) + specific_season_integer = specific_season.to_i + games_in_season = {specific_season => []} + @game_stats_data.each do |game_id, game_object| + games_in_season[specific_season].push(game_id) if game_object.season == specific_season_integer + end - # end + team_goal_ratio = {} + + @seasons_stats_data.each do |game_key, game_object| + if games_in_season[specific_season].include?(game_object.game_id) + if !(team_goal_ratio.keys.include?(game_object.team_id)) + if game_object.shots > 0 + team_goal_ratio[game_object.team_id] = [] + team_goal_ratio[game_object.team_id].push((game_object.goals / game_object.shots.to_f).truncate(2)) + else + team_goal_ratio[game_object.team_id].push(0.00) + end + else + if game_object.shots > 0 + team_goal_ratio[game_object.team_id].push((game_object.goals / game_object.shots.to_f).truncate(2)) + else + team_goal_ratio[game_object.team_id].push(0.00) + end + end + end + end + + lowest_accuracy_team = team_goal_ratio.min_by do |team, accuracy_per_game| + accuracy_per_game.sum / accuracy_per_game.length + end + + @teams_stats_data.each do |team_id, team_object| + if lowest_accuracy_team[0] == team_id + return team_object.team_name + end + end + end # def most_tackles # end - # def fewest_tackles + def fewest_tackles(specific_season) + specific_season_integer = specific_season.to_i + games_in_season = {specific_season => []} + @game_stats_data.each do |game_id, game_object| + games_in_season[specific_season].push(game_id) if game_object.season == specific_season_integer + end - # end + team_total_tackles = {} + + @seasons_stats_data.each do |game_key, game_object| + if games_in_season[specific_season].include?(game_object.game_id) + if !(team_total_tackles.keys.include?(game_object.team_id)) + team_total_tackles[game_object.team_id] = 0 + team_total_tackles[game_object.team_id] += game_object.tackles + else + team_total_tackles[game_object.team_id] += game_object.tackles + end + end + end + lowest_tackling_team = team_total_tackles.min_by do |team_id, tackles| + tackles + end + + @teams_stats_data.each do |team_id, team_object| + if lowest_tackling_team[0] == team_id + return team_object.team_name + end + end + end end \ No newline at end of file diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 8e4a76ffe3..1466333b88 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -115,7 +115,7 @@ describe 'percentage_home_wins' do it 'returns percentage of games that a home team has won' do - expect(@stat_tracker.percentage_home_wins).to eq(64.28) + expect(@stat_tracker.percentage_home_wins).to eq(0.64) end end @@ -166,7 +166,7 @@ end describe 'count_of_games_by_season' do - it 'returns sum of games per season on dummy file' do + it 'returns sum of games per season' do expect(@stat_tracker.count_of_games_by_season).to eq(20122013 => 14) end @@ -180,7 +180,6 @@ object_5 = hash[2012030225] object_6 = hash[2012030312] object_7 = hash[2012030233] - object_1.instance_variable_set(:@season, (20122013 + 1)) object_2.instance_variable_set(:@season, (20122013 + 2)) @@ -196,6 +195,36 @@ end end + + describe 'average_goals_by_season' do + it 'returns the average of goals by season' do + expect(@stat_tracker.average_goals_by_season).to eq(20122013 => 3.5) + end + + it 'returns sum of games per season on mocks' do + hash = @stat_tracker.instance_variable_get(:@game_stats_data) + + object_1 = hash[2012030221] + object_2 = hash[2012030222] + object_3 = hash[2012030223] + object_4 = hash[2012030224] + object_5 = hash[2012030225] + object_6 = hash[2012030312] + object_7 = hash[2012030233] + + object_1.instance_variable_set(:@season, (20122013 + 1)) + object_2.instance_variable_set(:@season, (20122013 + 2)) + object_3.instance_variable_set(:@season, (20122013 + 2)) + object_4.instance_variable_set(:@season, (20122013 + 4)) + object_5.instance_variable_set(:@season, (20122013 + 4)) + object_6.instance_variable_set(:@season, (20122013 + 4)) + object_7.instance_variable_set(:@season, (20122013 + 4)) + + expected = {20122014=>5, 20122015=>4, 20122017=>4.5, 20122013=>2.57} + + expect(@stat_tracker.average_goals_by_season).to eq(expected) + end + end # describe 'count_of_teams' do # end @@ -204,21 +233,44 @@ # end + describe 'count_of_teams' do + it 'returns the total number of teams' do + expect(@stat_tracker.count_of_teams).to eq(14) + end + end + + describe 'best_offense' do + it 'returns name from id' do + @teams_stats_data = StatTracker.teams_reader(@locations[:teams]) + @teams_stats_data.each do |team_id, team_object| + expect(@stat_tracker.id_to_name(team_id)).to eq(team_object.team_name) + end + end + + it 'returns team yielding highest goals scored per game over all seasons' do + expect(@stat_tracker.best_offense).to eq('FC Dallas') + end + end + # describe 'worst_offense' do # end - # describe 'highest_scoring_visitor' do - - # end + describe 'highest_scoring_visitor' do + it 'returns name of the team with the highest average score per game across all seasons when they are away.' do + expect(@stat_tracker.highest_scoring_visitor).to eq("FC Dallas") + end + end # describe 'highest_scoring_home_team' do # end - # describe 'lowest_scoring_visitor' do - - # end + describe 'lowest_scoring_visitor' do + it 'returns lowest average scoring team when they are a visitor.' do + expect(@stat_tracker.lowest_scoring_visitor).to eq('Sporting Kansas City') + end + end # describe 'lowest_scoring_home_team' do @@ -228,23 +280,31 @@ # end - # describe 'worst_coach' do - - # end + xdescribe 'worst_coach' do + it 'returns coach with worst win percentage for the season' do + expect(@stat_tracker.worst_coach).to eq('ur mom') + end + end # describe 'most_accurate_team' do # end - # describe 'least_accurate_team' do - - # end + describe 'least_accurate_team' do + it 'returns name of the Team with the worst ratio of shots to goals for the season.' do + expect(@stat_tracker.least_accurate_team('20122013')).to eq('Sporting Kansas City') + #expect(@stat_tracker.least_accurate_team(20132014)).to eq "New York City FC" + #expect(@stat_tracker.least_accurate_team(20142015)).to eq "Columbus Crew SC" + end + end # describe 'most_tackles' do # end - # describe 'fewest_tackles' do - - # end + describe 'fewest_tackles' do + it 'returns name of the Team with the fewest tackles in the season' do + expect(@stat_tracker.fewest_tackles('20122013')).to eq("Sporting Kansas City") + end + end end \ No newline at end of file From 39293319df06f17fd9e09f9e13b579b73c256c69 Mon Sep 17 00:00:00 2001 From: John Hill Date: Sat, 3 Aug 2024 10:55:33 -0600 Subject: [PATCH 58/97] feat: add percentage_visitor_wins method & test --- lib/stat_tracker.rb | 7 +++++++ runner.rb | 3 +++ spec/stat_tracker_spec.rb | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 1b89fd1fc6..0d7a8a108c 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -67,6 +67,13 @@ def percentage_home_wins ((win_count.to_f / @game_stats_data.length)).round(2) end + def percentage_visitor_wins + visitor_win_count = @game_stats_data.count do |game_id, game_object| + game_object.away_goals > game_object.home_goals + end + (visitor_win_count.to_f / @game_stats_data.length).round(2) + end + def percentage_ties tie_count = @game_stats_data.count do |game_id, game_object| game_object.home_goals == game_object.away_goals diff --git a/runner.rb b/runner.rb index 8a810f35f6..f56d0dbf66 100644 --- a/runner.rb +++ b/runner.rb @@ -14,3 +14,6 @@ stat_tracker = StatTracker.from_csv(season_data) puts stat_tracker.highest_total_score puts stat_tracker.class + +puts Object.superclass +puts BasicObject.superclass \ No newline at end of file diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 546c41f800..ac4a6f5140 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -119,6 +119,12 @@ end end + describe 'percentage_visitor_wins' do + it 'Percentage of games that a visitor has won (rounded to the nearest 100th)' do + expect(@stat_tracker.percentage_visitor_wins).to eq(0.36) + end + end + describe 'percentage_ties' do it 'returns percentage of games that has resulted in a tie (rounded to the nearest 100th)' do expect(@stat_tracker.percentage_ties).to eq(0.00) # NO TIES CURRENTLY LISTED From 2d62a2da62c7f15656d9b7a0ada68f5ee28884e5 Mon Sep 17 00:00:00 2001 From: Shawn Thompson Date: Sat, 3 Aug 2024 12:15:54 -0500 Subject: [PATCH 59/97] feat: started set up of highest_scoring_team --- lib/stat_tracker.rb | 36 ++++++++++++++++++++++++++++++++++-- spec/stat_tracker_spec.rb | 9 ++++++--- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index af80c2e45c..3b0600d4e3 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -162,8 +162,40 @@ def highest_scoring_visitor end end - # def highest_scoring_home_team - + def highest_scoring_home_team + home_goals = Hash.new(0) + game_count = 0 + @game_stats_data.each do |game_id, game_object| + home_team = game_object.home_team_id + goals = game_object.home_goals + home_goals[home_team] += goals + game_count += 1 + + end + average = home_goals.each do |team, goals| + (goals / game_count.to_f).round(2) + # require 'pry'; binding.pry + end + average + end + # home_team_scores = {} + # @game_stats_data.each do |game_id, game_object| + # if !(home_team_scores.keys.include?(game_object.home_team_id)) + # home_team_scores[game_object.home_team_id] = [] + # home_team_scores[game_object.home_team_id].push(game_object.home_goals) + # else + # home_team_scores[game_object.home_team_id].push(game_object.home_goals) + # end + # end + # winning_team = home_team_scores.max_by do |team, scores| + # (scores.sum / scores.length.to_f).round(2) + # end + + # @teams_stats_data.each do |team_id, team_object| + # if winning_team[0] == team_id + # return team_object.team_name + # end + # end # end def lowest_scoring_visitor diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 1466333b88..f6a9e0500d 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -225,6 +225,7 @@ expect(@stat_tracker.average_goals_by_season).to eq(expected) end end + # describe 'count_of_teams' do # end @@ -262,9 +263,11 @@ end end - # describe 'highest_scoring_home_team' do - - # end + describe 'highest_scoring_home_team' do + it ' returns name of the team with the highest average score per game across all seasons when they are home' do + expect(@stat_tracker.highest_scoring_home_team).to eq("FC Dallas") + end + end describe 'lowest_scoring_visitor' do it 'returns lowest average scoring team when they are a visitor.' do From cf56fb32ab96f3363779fc94e00908a4030456af Mon Sep 17 00:00:00 2001 From: John Hill Date: Sat, 3 Aug 2024 11:17:44 -0600 Subject: [PATCH 60/97] Feat: added team_scoring_helper method --- lib/stat_tracker.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 1b89fd1fc6..0967ef5a3f 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -87,15 +87,18 @@ def count_of_teams @teams_stats_data.size end - def best_offense - - teams_goals = Hash.new(0) - games_played = Hash.new(0) + def team_scoring + teams_data = Hash.new { |hash, key| hash[key] = { goals: 0, games_played: 0 } } @seasons_stats_data.each do |game_id, season| - teams_goals[season.team_id] += season.goals - games_played[season.team_id] += 1 + teams_data[season.team_id][:goals] += season.goals + teams_data[season.team_id][:games_played] += 1 end + teams_data + end + + def best_offense + teams_data best_offense_team = teams_goals.max_by do |team_id, goals| goals.to_f / games_played[team_id].to_f @@ -112,9 +115,11 @@ def id_to_name(id) end end - # def worst_offense + def - # end + def worst_offense + + end def highest_scoring_visitor visitor_team_scores = {} From 2a8b653025d4fee89bbbcd9e31b210d0dfe23c47 Mon Sep 17 00:00:00 2001 From: John Hill Date: Sat, 3 Aug 2024 11:27:12 -0600 Subject: [PATCH 61/97] Test: added team_seasons_goal test --- lib/stat_tracker.rb | 8 ++++---- spec/stat_tracker_spec.rb | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 0967ef5a3f..a1a1657be4 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -87,7 +87,7 @@ def count_of_teams @teams_stats_data.size end - def team_scoring + def team_seasons_goals teams_data = Hash.new { |hash, key| hash[key] = { goals: 0, games_played: 0 } } @seasons_stats_data.each do |game_id, season| @@ -98,10 +98,10 @@ def team_scoring end def best_offense - teams_data + teams_goals_data = team_seasons_goals - best_offense_team = teams_goals.max_by do |team_id, goals| - goals.to_f / games_played[team_id].to_f + best_offense_team = teams_goals_data.max_by do |team_id, teams_data| + teams_data[:goals].to_f / teams_data[:games_played].to_f end best_offense_team_id = best_offense_team[0] diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 546c41f800..499b8acb9b 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -171,6 +171,12 @@ end end + describe 'team_seasons_goals' do + it "returns a hash with each team as the key, and the value a hash with :goals & :games_played as keys, and their respective values" do + expect(@stat_tracker.team_seasons_goals).to eq ({3=>{:goals=>8, :games_played=>5}, 6=>{:goals=>21, :games_played=>7}, 5=>{:goals=>1, :games_played=>2}}) + end + end + describe 'best_offense' do it 'returns name from id' do @teams_stats_data = StatTracker.teams_reader(@locations[:teams]) From 969e991348ad0de0bd00bd6d55bc01fcafe1ea9e Mon Sep 17 00:00:00 2001 From: Shawn Thompson Date: Sat, 3 Aug 2024 12:30:50 -0500 Subject: [PATCH 62/97] refactor: count_of_games_by_season to comply with spec harness --- lib/stat_tracker.rb | 5 ++--- spec/stat_tracker_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index af80c2e45c..64b801f4b4 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -77,10 +77,9 @@ def percentage_ties def count_of_games_by_season season_game_count = Hash.new(0) @game_stats_data.each do |game_id, game_object| - season = game_object.season - season_game_count[season] += 1 + season = game_object.season.to_s + season_game_count[season.to_s] += 1 end - season_game_count end diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 1466333b88..e4e23160ba 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -167,7 +167,7 @@ describe 'count_of_games_by_season' do it 'returns sum of games per season' do - expect(@stat_tracker.count_of_games_by_season).to eq(20122013 => 14) + expect(@stat_tracker.count_of_games_by_season).to eq("20122013" => 14) end it 'returns sum of games per season on mocks' do @@ -189,7 +189,7 @@ object_6.instance_variable_set(:@season, (20122013 + 4)) object_7.instance_variable_set(:@season, (20122013 + 4)) - expected = {20122014=>1, 20122015=>2, 20122017=>4, 20122013=>7} + expected = {"20122014"=>1, "20122015"=>2, "20122017"=>4, "20122013"=>7} expect(@stat_tracker.count_of_games_by_season).to eq(expected) end From c8e42a58abbc2b98bb5f759d09869a6464cec13c Mon Sep 17 00:00:00 2001 From: John Hill Date: Sat, 3 Aug 2024 11:32:12 -0600 Subject: [PATCH 63/97] Feat: added worst_offense method & test --- lib/stat_tracker.rb | 12 ++++++++++++ spec/stat_tracker_spec.rb | 8 +++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index a1a1657be4..4697abdfac 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -109,6 +109,18 @@ def best_offense id_to_name(best_offense_team_id) end + def worst_offense + teams_goals_data = team_seasons_goals + + worst_offense_team = teams_goals_data.min_by do |team_id, teams_data| + teams_data[:goals].to_f / teams_data[:games_played].to_f + end + + worst_offense_team_id = worst_offense_team[0] + + id_to_name(worst_offense_team_id) + end + def id_to_name(id) @teams_stats_data.each do |team_id, team| return team.team_name.to_s if team_id == id diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 499b8acb9b..1d40882b9a 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -190,9 +190,11 @@ end end - # describe 'worst_offense' do - - # end + describe 'worst_offense' do + it 'returns team yielding lowest goals scored per game over all seaons' do + expect(@stat_tracker.worst_offense).to eq('Sporting Kansas City') + end + end describe 'highest_scoring_visitor' do it 'returns name of the team with the highest average score per game across all seasons when they are away.' do From a5493cbad4738a4e597de2959b47f1e3d8240786 Mon Sep 17 00:00:00 2001 From: John Hill Date: Sat, 3 Aug 2024 12:00:54 -0600 Subject: [PATCH 64/97] Refactor: added parameter to team_seasons_goals --- lib/stat_tracker.rb | 13 ++++++++----- spec/stat_tracker_spec.rb | 6 +++++- tester.rb | 8 ++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 tester.rb diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 4697abdfac..699275fd9a 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -87,18 +87,21 @@ def count_of_teams @teams_stats_data.size end - def team_seasons_goals + def team_seasons_goals(location) + teams_data = Hash.new { |hash, key| hash[key] = { goals: 0, games_played: 0 } } @seasons_stats_data.each do |game_id, season| - teams_data[season.team_id][:goals] += season.goals - teams_data[season.team_id][:games_played] += 1 + if location.include?(season.hoa) + teams_data[season.team_id][:goals] += season.goals + teams_data[season.team_id][:games_played] += 1 + end end teams_data end def best_offense - teams_goals_data = team_seasons_goals + teams_goals_data = team_seasons_goals(['home','away']) best_offense_team = teams_goals_data.max_by do |team_id, teams_data| teams_data[:goals].to_f / teams_data[:games_played].to_f @@ -110,7 +113,7 @@ def best_offense end def worst_offense - teams_goals_data = team_seasons_goals + teams_goals_data = team_seasons_goals(['home','away']) worst_offense_team = teams_goals_data.min_by do |team_id, teams_data| teams_data[:goals].to_f / teams_data[:games_played].to_f diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 1d40882b9a..b43ee7b428 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -173,7 +173,11 @@ describe 'team_seasons_goals' do it "returns a hash with each team as the key, and the value a hash with :goals & :games_played as keys, and their respective values" do - expect(@stat_tracker.team_seasons_goals).to eq ({3=>{:goals=>8, :games_played=>5}, 6=>{:goals=>21, :games_played=>7}, 5=>{:goals=>1, :games_played=>2}}) + expect(@stat_tracker.team_seasons_goals(['away','home'])).to eq ({3=>{:goals=>8, :games_played=>5}, 6=>{:goals=>21, :games_played=>7}, 5=>{:goals=>1, :games_played=>2}}) + end + + it 'returns returns values for only home teams' do + end end diff --git a/tester.rb b/tester.rb new file mode 100644 index 0000000000..329d8a7376 --- /dev/null +++ b/tester.rb @@ -0,0 +1,8 @@ +location = ['away','home'] + +jose = 'away' + + +if location.include?(jose) + puts "yes" +end \ No newline at end of file From 060793202257d663fd58ac13435cb65b8cb1a874 Mon Sep 17 00:00:00 2001 From: John Hill Date: Sat, 3 Aug 2024 12:04:28 -0600 Subject: [PATCH 65/97] Test: added team_seasons_goals parameter tests --- spec/stat_tracker_spec.rb | 6 +++++- tester.rb | 8 -------- 2 files changed, 5 insertions(+), 9 deletions(-) delete mode 100644 tester.rb diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index b43ee7b428..587c5e1f1d 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -176,8 +176,12 @@ expect(@stat_tracker.team_seasons_goals(['away','home'])).to eq ({3=>{:goals=>8, :games_played=>5}, 6=>{:goals=>21, :games_played=>7}, 5=>{:goals=>1, :games_played=>2}}) end - it 'returns returns values for only home teams' do + it 'returns values for only home teams' do + expect(@stat_tracker.team_seasons_goals('away')).to eq ({3=>{:goals=>5, :games_played=>3}, 6=>{:goals=>12, :games_played=>4}}) + end + it 'returns values for only away teams' do + expect(@stat_tracker.team_seasons_goals('home')).to eq ({6=>{:goals=>9, :games_played=>3}, 3=>{:goals=>3, :games_played=>2}, 5=>{:goals=>1, :games_played=>2}}) end end diff --git a/tester.rb b/tester.rb deleted file mode 100644 index 329d8a7376..0000000000 --- a/tester.rb +++ /dev/null @@ -1,8 +0,0 @@ -location = ['away','home'] - -jose = 'away' - - -if location.include?(jose) - puts "yes" -end \ No newline at end of file From bc7cf860395ce419202431f1072a51542b17431b Mon Sep 17 00:00:00 2001 From: Shawn Thompson Date: Sat, 3 Aug 2024 13:41:46 -0500 Subject: [PATCH 66/97] refactor: average_goals_by_season to comply with spec harness & implemented helper method --- lib/game.rb | 1 + lib/stat_tracker.rb | 10 ++++------ spec/stat_tracker_spec.rb | 8 ++++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/game.rb b/lib/game.rb index 00fb4f2df6..78a2283795 100644 --- a/lib/game.rb +++ b/lib/game.rb @@ -24,4 +24,5 @@ def initialize(data) def total_goals @away_goals + @home_goals end + end \ No newline at end of file diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index af80c2e45c..69932ea278 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -77,23 +77,21 @@ def percentage_ties def count_of_games_by_season season_game_count = Hash.new(0) @game_stats_data.each do |game_id, game_object| - season = game_object.season + season = game_object.season.to_s season_game_count[season] += 1 end - season_game_count end def average_goals_by_season - season_game_count = Hash.new(0) + count_of_games_by_season total_season_goals = Hash.new(0) @game_stats_data.each do |game_id, game_object| - season = game_object.season + season = game_object.season.to_s goals = game_object.total_goals - season_game_count[season] += 1 total_season_goals[season] += goals end - average = total_season_goals.merge!(season_game_count) do |season, goals, games| + average = total_season_goals.merge!(count_of_games_by_season) do |season, goals, games| (goals / games.to_f).round(2) end average diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 1466333b88..303c41aed6 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -167,7 +167,7 @@ describe 'count_of_games_by_season' do it 'returns sum of games per season' do - expect(@stat_tracker.count_of_games_by_season).to eq(20122013 => 14) + expect(@stat_tracker.count_of_games_by_season).to eq("20122013" => 14) end it 'returns sum of games per season on mocks' do @@ -189,7 +189,7 @@ object_6.instance_variable_set(:@season, (20122013 + 4)) object_7.instance_variable_set(:@season, (20122013 + 4)) - expected = {20122014=>1, 20122015=>2, 20122017=>4, 20122013=>7} + expected = {"20122014"=>1, "20122015"=>2, "20122017"=>4, "20122013"=>7} expect(@stat_tracker.count_of_games_by_season).to eq(expected) end @@ -198,7 +198,7 @@ describe 'average_goals_by_season' do it 'returns the average of goals by season' do - expect(@stat_tracker.average_goals_by_season).to eq(20122013 => 3.5) + expect(@stat_tracker.average_goals_by_season).to eq("20122013" => 3.5) end it 'returns sum of games per season on mocks' do @@ -220,7 +220,7 @@ object_6.instance_variable_set(:@season, (20122013 + 4)) object_7.instance_variable_set(:@season, (20122013 + 4)) - expected = {20122014=>5, 20122015=>4, 20122017=>4.5, 20122013=>2.57} + expected = {"20122014"=>5, "20122015"=>4, "20122017"=>4.5, "20122013"=>2.57} expect(@stat_tracker.average_goals_by_season).to eq(expected) end From 75e26cd621b40a85177d83d8f50dc7c2f279adfd Mon Sep 17 00:00:00 2001 From: John Hill Date: Sat, 3 Aug 2024 12:41:48 -0600 Subject: [PATCH 67/97] Refactored lowest_scoring_vistior, worst_offense, best_offense, Add lowest_scoring_away_team --- lib/stat_tracker.rb | 60 +++++++++++++++++++-------------------- spec/stat_tracker_spec.rb | 14 ++++++--- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 699275fd9a..f6450bfae3 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -100,28 +100,24 @@ def team_seasons_goals(location) teams_data end - def best_offense - teams_goals_data = team_seasons_goals(['home','away']) - - best_offense_team = teams_goals_data.max_by do |team_id, teams_data| - teams_data[:goals].to_f / teams_data[:games_played].to_f + def teams_scores_min_by(teams_data) + lowest_scoring_team = teams_data.min_by do |team_id, team_data| + team_data[:goals].to_f / team_data[:games_played].to_f end - - best_offense_team_id = best_offense_team[0] - - id_to_name(best_offense_team_id) end - def worst_offense - teams_goals_data = team_seasons_goals(['home','away']) - - worst_offense_team = teams_goals_data.min_by do |team_id, teams_data| - teams_data[:goals].to_f / teams_data[:games_played].to_f + def teams_scores_max_by(teams_data) + highest_scoring_team = teams_data.max_by do |team_id, team_data| + team_data[:goals].to_f / team_data[:games_played].to_f end + end - worst_offense_team_id = worst_offense_team[0] + def best_offense + teams_goals_data = team_seasons_goals(['home','away']) + best_offense_team = teams_scores_max_by(teams_goals_data) - id_to_name(worst_offense_team_id) + best_offense_team_id = best_offense_team[0] + id_to_name(best_offense_team_id) end def id_to_name(id) @@ -129,12 +125,17 @@ def id_to_name(id) return team.team_name.to_s if team_id == id end end - - def + + def worst_offense + teams_goals_data = team_seasons_goals(['home','away']) + worst_offense_team = teams_scores_min_by(teams_goals_data) + worst_offense_team_id = worst_offense_team[0] + id_to_name(worst_offense_team_id) end + def highest_scoring_visitor visitor_team_scores = {} @@ -162,25 +163,22 @@ def highest_scoring_visitor # end def lowest_scoring_visitor - teams_goals = Hash.new(0) - games_played = Hash.new(0) - - @game_stats_data.each do |game_id, game| - teams_goals[game.away_team_id] += game.away_goals - games_played[game.away_team_id] += 1 - end + away_teams_goals_data = team_seasons_goals('away') - worst_visitors = teams_goals.min_by do |team_id, away_goals| - away_goals.to_f / games_played[team_id].to_f - end + lowest_scoring_team = teams_scores_min_by(away_teams_goals_data) - worst_visitor_id = worst_visitors[0] + worst_visitor_id = lowest_scoring_team[0] id_to_name(worst_visitor_id) end - # def lowest_scoring_home_team + def lowest_scoring_home_team + home_teams_goals_data = team_seasons_goals('home') - # end + lowest_scoring_team = teams_scores_min_by(home_teams_goals_data) + + lowest_scoring_team_id = lowest_scoring_team[0] + id_to_name(lowest_scoring_team_id) + end # def winningest_coach diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 587c5e1f1d..98e6ad23d6 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -171,6 +171,10 @@ end end + describe 'teams_scores_max_by' do + + end + describe 'team_seasons_goals' do it "returns a hash with each team as the key, and the value a hash with :goals & :games_played as keys, and their respective values" do expect(@stat_tracker.team_seasons_goals(['away','home'])).to eq ({3=>{:goals=>8, :games_played=>5}, 6=>{:goals=>21, :games_played=>7}, 5=>{:goals=>1, :games_played=>2}}) @@ -216,13 +220,15 @@ describe 'lowest_scoring_visitor' do it 'returns lowest average scoring team when they are a visitor.' do - expect(@stat_tracker.lowest_scoring_visitor).to eq('Sporting Kansas City') + expect(@stat_tracker.lowest_scoring_visitor).to eq('Houston Dynamo') end end - # describe 'lowest_scoring_home_team' do - - # end + describe 'lowest_scoring_home_team' do + it 'returns lowest average scoring team when they are a visitor.' do + expect(@stat_tracker.lowest_scoring_home_team).to eq('Sporting Kansas City') + end + end # describe 'winningest_coach' do From b4f19f7c8883024020ac5c93caafa963837712f9 Mon Sep 17 00:00:00 2001 From: John Hill Date: Sat, 3 Aug 2024 12:43:29 -0600 Subject: [PATCH 68/97] Feat: add teams_scores_average_min_by & teams_scores_average_max_by --- lib/stat_tracker.rb | 12 ++++++------ spec/stat_tracker_spec.rb | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index f6450bfae3..05fbb3fe5d 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -100,13 +100,13 @@ def team_seasons_goals(location) teams_data end - def teams_scores_min_by(teams_data) + def teams_scores_average_min_by(teams_data) lowest_scoring_team = teams_data.min_by do |team_id, team_data| team_data[:goals].to_f / team_data[:games_played].to_f end end - def teams_scores_max_by(teams_data) + def teams_scores_average_max_by(teams_data) highest_scoring_team = teams_data.max_by do |team_id, team_data| team_data[:goals].to_f / team_data[:games_played].to_f end @@ -114,7 +114,7 @@ def teams_scores_max_by(teams_data) def best_offense teams_goals_data = team_seasons_goals(['home','away']) - best_offense_team = teams_scores_max_by(teams_goals_data) + best_offense_team = teams_scores_average_max_by(teams_goals_data) best_offense_team_id = best_offense_team[0] id_to_name(best_offense_team_id) @@ -130,7 +130,7 @@ def id_to_name(id) def worst_offense teams_goals_data = team_seasons_goals(['home','away']) - worst_offense_team = teams_scores_min_by(teams_goals_data) + worst_offense_team = teams_scores_average_min_by(teams_goals_data) worst_offense_team_id = worst_offense_team[0] id_to_name(worst_offense_team_id) @@ -165,7 +165,7 @@ def highest_scoring_visitor def lowest_scoring_visitor away_teams_goals_data = team_seasons_goals('away') - lowest_scoring_team = teams_scores_min_by(away_teams_goals_data) + lowest_scoring_team = teams_scores_average_min_by(away_teams_goals_data) worst_visitor_id = lowest_scoring_team[0] id_to_name(worst_visitor_id) @@ -174,7 +174,7 @@ def lowest_scoring_visitor def lowest_scoring_home_team home_teams_goals_data = team_seasons_goals('home') - lowest_scoring_team = teams_scores_min_by(home_teams_goals_data) + lowest_scoring_team = teams_scores_average_min_by(home_teams_goals_data) lowest_scoring_team_id = lowest_scoring_team[0] id_to_name(lowest_scoring_team_id) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 98e6ad23d6..6d6a258429 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -172,7 +172,7 @@ end describe 'teams_scores_max_by' do - + it 'returns the team with the max' end describe 'team_seasons_goals' do From 15534cbb4bd7b95435ec443dc2add63ea32afff6 Mon Sep 17 00:00:00 2001 From: John Hill Date: Sat, 3 Aug 2024 12:47:45 -0600 Subject: [PATCH 69/97] Test: add test for lowest_scoring_home_team, teams_scores_average_min_by, teams_scores_average_max_by --- spec/stat_tracker_spec.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 6d6a258429..c292f1c4c8 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -171,8 +171,18 @@ end end - describe 'teams_scores_max_by' do - it 'returns the team with the max' + describe 'teams_scores_average_max_by' do + it 'returns the team with key value pair, of the team with the highest score average' do + data= {3=>{:goals=>5, :games_played=>3}, 6=>{:goals=>12, :games_played=>4}} + expect(@stat_tracker.teams_scores_average_max_by(data)).to eq([6, {:goals=>12, :games_played=>4}]) + end + end + + describe 'teams_scores_average_min_by' do + it 'returns the team with key value pair, of the team with the lowest score average' do + data= {3=>{:goals=>5, :games_played=>3}, 6=>{:goals=>12, :games_played=>4}} + expect(@stat_tracker.teams_scores_average_min_by(data)).to eq([3, {:goals=>5, :games_played=>3}]) + end end describe 'team_seasons_goals' do From 457049200afbc6cdb9dd0d0d860a05713ad77c2b Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Sat, 3 Aug 2024 14:34:39 -0600 Subject: [PATCH 70/97] refactor: worst coach --- lib/stat_tracker.rb | 67 +++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 812f6fe85c..a92711b6e7 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -135,40 +135,41 @@ def lowest_scoring_visitor def worst_coach(specific_season) specific_season_integer = specific_season.to_i - - games_in_season = {specific_season => []} - @game_stats_data.each do |game_id, game_object| - games_in_season[specific_season].push(game_id) if game_object.season == specific_season_integer - end - - teams_total_results = {} - @seasons_stats_data.each do |game_id, game_object| - if games_in_season[specific_season].include?(game_object.game_id) - if !(teams_total_results.keys.include?(game_object.team_id)) - teams_total_results[game_object.team_id] = [] - teams_total_results[game_object.team_id].push(game_object.result) - else - teams_total_results[game_object.team_id].push(game_object.result) - end - end - end - - team_win_ratio = {} - teams_total_results.map do |team_id, total_results| + team_win_loss_ratio = {} + + # games_in_season = {specific_season => []} + # @game_stats_data.each do |game_id, game_object| + # games_in_season[specific_season].push(game_id) if game_object.season == specific_season_integer + # end + + # teams_total_results = {} + # @seasons_stats_data.each do |game_id, game_object| + # if games_in_season[specific_season].include?(game_object.game_id) + # if !(teams_total_results.keys.include?(game_object.team_id)) + # teams_total_results[game_object.team_id] = [] + # teams_total_results[game_object.team_id].push(game_object.result) + # else + # teams_total_results[game_object.team_id].push(game_object.result) + # end + # end + # end + + # team_win_ratio = {} + # teams_total_results.map do |team_id, total_results| - win_counter = 0 - total_results.each do |result| - if result == "WIN" - win_counter += 1 - end - end - team_win_ratio[team_id] = (win_counter.to_f / total_results.length).truncate(2) - end - - worst_team = team_win_ratio.min_by do |team_id, win_ratio| - win_ratio - end - id_to_coach(worst_team[0]) + # win_counter = 0 + # total_results.each do |result| + # if result == "WIN" + # win_counter += 1 + # end + # end + # team_win_ratio[team_id] = (win_counter.to_f / total_results.length).truncate(2) + # end + + # worst_team = team_win_ratio.min_by do |team_id, win_ratio| + # win_ratio + # end + # id_to_coach(worst_team[0]) end def id_to_coach(id) From 07761d75ee0156b32975148c49b291bdf62371e6 Mon Sep 17 00:00:00 2001 From: Shawn Thompson Date: Sat, 3 Aug 2024 16:43:21 -0500 Subject: [PATCH 71/97] feat: highest_scoring_team w/ test and mocks --- lib/stat_tracker.rb | 40 ++++++++++----------------------------- spec/stat_tracker_spec.rb | 31 +++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 713ab5f249..19e61bc01f 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -185,40 +185,20 @@ def highest_scoring_visitor end def highest_scoring_home_team - home_goals = Hash.new(0) - game_count = 0 + team_home_goals = Hash.new(0) + home_games_played = Hash.new(0) @game_stats_data.each do |game_id, game_object| - home_team = game_object.home_team_id - goals = game_object.home_goals - home_goals[home_team] += goals - game_count += 1 - + team_home_goals[game_object.home_team_id] += game_object.home_goals + home_games_played[game_object.home_team_id] += 1 end - average = home_goals.each do |team, goals| - (goals / game_count.to_f).round(2) - # require 'pry'; binding.pry + + highest_home_team = team_home_goals.max_by do |team, goals| + goals.to_f / home_games_played[team].to_f end - average + + best_home_team_id = highest_home_team[0] + id_to_name(best_home_team_id) end - # home_team_scores = {} - # @game_stats_data.each do |game_id, game_object| - # if !(home_team_scores.keys.include?(game_object.home_team_id)) - # home_team_scores[game_object.home_team_id] = [] - # home_team_scores[game_object.home_team_id].push(game_object.home_goals) - # else - # home_team_scores[game_object.home_team_id].push(game_object.home_goals) - # end - # end - # winning_team = home_team_scores.max_by do |team, scores| - # (scores.sum / scores.length.to_f).round(2) - # end - - # @teams_stats_data.each do |team_id, team_object| - # if winning_team[0] == team_id - # return team_object.team_name - # end - # end - # end def lowest_scoring_visitor teams_goals = Hash.new(0) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index e02186a7a9..56d974d8d3 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -279,7 +279,36 @@ describe 'highest_scoring_home_team' do it ' returns name of the team with the highest average score per game across all seasons when they are home' do - expect(@stat_tracker.highest_scoring_home_team).to eq("FC Dallas") + expect(@stat_tracker.highest_scoring_home_team).to eq("LA Galaxy") + end + + it 'returns sum of games per season on mocks' do + hash = @stat_tracker.instance_variable_get(:@game_stats_data) + + object_1 = hash[2012030221] + + object_1.instance_variable_set(:@home_goals, (20122013)) + + expected = ("FC Dallas") + + expect(@stat_tracker.highest_scoring_home_team).to eq(expected) + end + + it 'returns sum of games per season on mocks' do + hash = @stat_tracker.instance_variable_get(:@game_stats_data) + + object_1 = hash[2012030221] + object_2 = hash[2012030222] + object_3 = hash[2012030223] + object_4 = hash[2012030224] + object_5 = hash[2012030225] + object_6 = hash[2012030312] + + object_6.instance_variable_set(:@home_goals, (20120122013)) + + expected = ("Sporting Kansas City") + + expect(@stat_tracker.highest_scoring_home_team).to eq(expected) end end From 1a72cacb372ccc3d7da11087a1127880372c85a0 Mon Sep 17 00:00:00 2001 From: Shawn Thompson Date: Sun, 4 Aug 2024 11:12:13 -0500 Subject: [PATCH 72/97] Refactor: highest_scoring_home_team and updated tests --- lib/stat_tracker.rb | 16 ++++------------ spec/stat_tracker_spec.rb | 23 +++++++++-------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index e05830229d..2eefb00fce 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -189,19 +189,11 @@ def highest_scoring_visitor end def highest_scoring_home_team - team_home_goals = Hash.new(0) - home_games_played = Hash.new(0) - @game_stats_data.each do |game_id, game_object| - team_home_goals[game_object.home_team_id] += game_object.home_goals - home_games_played[game_object.home_team_id] += 1 - end + teams_home_goals = team_seasons_goals(['home']) + best_home_team = teams_scores_average_max_by(teams_home_goals) - highest_home_team = team_home_goals.max_by do |team, goals| - goals.to_f / home_games_played[team].to_f - end - - best_home_team_id = highest_home_team[0] - id_to_name(best_home_team_id) + best_home_team_id = best_home_team[0] + id_to_name(best_home_team_id) end def lowest_scoring_visitor diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 7f71f561d4..69e8690776 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -301,34 +301,29 @@ describe 'highest_scoring_home_team' do it ' returns name of the team with the highest average score per game across all seasons when they are home' do - expect(@stat_tracker.highest_scoring_home_team).to eq("LA Galaxy") + expect(@stat_tracker.highest_scoring_home_team).to eq("FC Dallas") end it 'returns sum of games per season on mocks' do - hash = @stat_tracker.instance_variable_get(:@game_stats_data) + hash = @stat_tracker.instance_variable_get(:@seasons_stats_data) - object_1 = hash[2012030221] + object_1 = hash[14] - object_1.instance_variable_set(:@home_goals, (20122013)) + object_1.instance_variable_set(:@goals, (20120122013)) - expected = ("FC Dallas") + expected = ("Sporting Kansas City") expect(@stat_tracker.highest_scoring_home_team).to eq(expected) end it 'returns sum of games per season on mocks' do - hash = @stat_tracker.instance_variable_get(:@game_stats_data) + hash = @stat_tracker.instance_variable_get(:@seasons_stats_data) - object_1 = hash[2012030221] - object_2 = hash[2012030222] - object_3 = hash[2012030223] - object_4 = hash[2012030224] - object_5 = hash[2012030225] - object_6 = hash[2012030312] + object_1 = hash[8] - object_6.instance_variable_set(:@home_goals, (20120122013)) + object_1.instance_variable_set(:@goals, (20120122013)) - expected = ("Sporting Kansas City") + expected = ("Houston Dynamo") expect(@stat_tracker.highest_scoring_home_team).to eq(expected) end From 72b1adbbe7d804bebc714c7ffe06c99fde1d9e68 Mon Sep 17 00:00:00 2001 From: John Hill Date: Sun, 4 Aug 2024 11:19:50 -0600 Subject: [PATCH 73/97] Feat: added most_accurate_team & respective helper methods --- lib/stat_tracker.rb | 36 +++++++++++++++++++++++++++--- runner.rb | 5 +---- spec/stat_tracker_spec.rb | 47 +++++++++++++++++++++++++++++++-------- 3 files changed, 72 insertions(+), 16 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index df99c256ab..75d346ab1f 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -223,10 +223,40 @@ def worst_coach # end - - # def most_accurate_team - # end + def all_games_ids_in_specified_season(specific_season) + + games_in_seasons = @game_stats_data.find_all { |game_id, game_object| game_object.season == specific_season.to_i} + game_ids_in_season = games_in_seasons.map { |game_id, game_object| game_id } + + end + + def teams_shots_and_goals(game_ids) + teams_data = Hash.new { |hash, key| hash[key] = { goals: 0, shots: 0 } } + + @seasons_stats_data.each do |counter, season_object| + + next unless game_ids.include?(season_object.game_id) + + teams_data[season_object.team_id][:goals] += season_object.goals + teams_data[season_object.team_id][:shots] += season_object.shots + end + + teams_data + end + + + def most_accurate_team(specific_season) + teams_data = teams_shots_and_goals(all_games_ids_in_specified_season(specific_season)) + + most_accurate = teams_data.max_by do |team_id, team_data| + next if team_data[:goals] == 0 + next if team_data[:shots] == 0 + team_data[:goals].to_f / team_data[:shots] + end + + id_to_name(most_accurate[0]) + end def least_accurate_team(specific_season) specific_season_integer = specific_season.to_i diff --git a/runner.rb b/runner.rb index f56d0dbf66..7726f08aa2 100644 --- a/runner.rb +++ b/runner.rb @@ -12,8 +12,5 @@ } stat_tracker = StatTracker.from_csv(season_data) -puts stat_tracker.highest_total_score -puts stat_tracker.class -puts Object.superclass -puts BasicObject.superclass \ No newline at end of file +stat_tracker.most_accurate_team(20122013) \ No newline at end of file diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index c0f27726f8..a25fccd2ee 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -3,17 +3,31 @@ RSpec.describe StatTracker do before(:each) do - game_path = './data/games_dummy.csv' - team_path = './data/teams_dummy.csv' - game_teams_path = './data/game_teams_dummy.csv' + # # Test Data + game_path_dummy = './data/games_dummy.csv' + team_path_dummy = './data/teams_dummy.csv' + game_teams_path_dummy = './data/game_teams_dummy.csv' @locations = { - games: game_path, - teams: team_path, - game_teams: game_teams_path - } + games: game_path_dummy, + teams: team_path_dummy, + game_teams: game_teams_path_dummy + } @stat_tracker = StatTracker.from_csv(@locations) + + # #Actual Data + # game_path = './data/games.csv' + # team_path = './data/teams.csv' + # game_teams_path = './data/game_teams.csv' + + # @locations_actual_data = { + # games: game_path, + # teams: team_path, + # game_teams: game_teams_path + # } + + # @stat_tracker_large_data = StatTracker.from_csv(@locations_actual_data) end describe "initialize" do @@ -323,10 +337,25 @@ expect(@stat_tracker.worst_coach).to eq('ur mom') end end + + describe 'all_games_ids_in_specified_season' do + it 'returns all game_ids in the specified season' do + expect(@stat_tracker.all_games_ids_in_specified_season(20122013)).to eq [2012030221, 2012030222, 2012030223, 2012030224, 2012030225, 2012030311, 2012030312, 2012030313, 2012030314, 2012030231, 2012030232, 2012030233, 2012030234, 2012030235] + + hash_of_games = @stat_tracker.instance_variable_get(:@game_stats_data) + + hash_of_games[2012030221].instance_variable_set(:@season, 20122014) + hash_of_games[2012030222].instance_variable_set(:@season, 20122014) + + expect(@stat_tracker.all_games_ids_in_specified_season(20122014)).to eq [2012030221, 2012030222] + end + end + + describe "" - # describe 'most_accurate_team' do + describe 'most_accurate_team' do - # end + end describe 'least_accurate_team' do it 'returns name of the Team with the worst ratio of shots to goals for the season.' do From 1555d77f6bd528498c236976312c31d7cc665484 Mon Sep 17 00:00:00 2001 From: John Hill Date: Sun, 4 Aug 2024 11:27:35 -0600 Subject: [PATCH 74/97] Test: added teams_shots_and_goals test --- spec/stat_tracker_spec.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index a25fccd2ee..9959ad7af4 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -351,10 +351,19 @@ end end - describe "" + describe "teams_shots_and_goals" do + it "returns a hash of all teams with shots and goals" do + data = [2012030221, 2012030222] + require 'pry', binding.pry + expect(@stat_tracker.teams_shots_and_goals(data)).to eq {3=>{:goals=>4, :shots=>17}, 6=>{:goals=>6, :shots=>20}} + end + end describe 'most_accurate_team' do + it "returns the most accurate team" do + + end end describe 'least_accurate_team' do From 60ab6f924dc38bc5ead2a990067547b0bafe8a9b Mon Sep 17 00:00:00 2001 From: John Hill Date: Sun, 4 Aug 2024 11:42:41 -0600 Subject: [PATCH 75/97] Test: added most_accurate_team & teams_shots_and_goals tests --- lib/stat_tracker.rb | 7 ++----- spec/stat_tracker_spec.rb | 12 ++++++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 75d346ab1f..10be1cbe21 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -249,11 +249,8 @@ def teams_shots_and_goals(game_ids) def most_accurate_team(specific_season) teams_data = teams_shots_and_goals(all_games_ids_in_specified_season(specific_season)) - most_accurate = teams_data.max_by do |team_id, team_data| - next if team_data[:goals] == 0 - next if team_data[:shots] == 0 - team_data[:goals].to_f / team_data[:shots] - end + most_accurate = teams_data.reject { |_, team_data| team_data[:shots] == 0 || team_data[:goals] == 0 } + .max_by { |_, team_data| team_data[:goals].to_f / team_data[:shots] } id_to_name(most_accurate[0]) end diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 9959ad7af4..5e81c6c0bc 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -354,15 +354,23 @@ describe "teams_shots_and_goals" do it "returns a hash of all teams with shots and goals" do data = [2012030221, 2012030222] - require 'pry', binding.pry - expect(@stat_tracker.teams_shots_and_goals(data)).to eq {3=>{:goals=>4, :shots=>17}, 6=>{:goals=>6, :shots=>20}} + + expect(@stat_tracker.teams_shots_and_goals(data)).to eq ({3=>{:goals=>4, :shots=>17}, 6=>{:goals=>6, :shots=>20}}) end end describe 'most_accurate_team' do it "returns the most accurate team" do + allow(@stat_tracker).to receive(:all_games_ids_in_specified_season).and_return([2012030221, 2012030222]) + + expect(@stat_tracker.most_accurate_team(20122014)).to eq("FC Dallas") + end + it "handles edge cases where a team has 0 goals or 0 shots (division by zero)" do + allow(@stat_tracker).to receive(:all_games_ids_in_specified_season).and_return([2012030221, 2012030222]) + allow(@stat_tracker).to receive(:teams_shots_and_goals).and_return({3=>{:goals=>4, :shots=>17}, 6=>{:goals=>0, :shots=>20}}) + expect(@stat_tracker.most_accurate_team(20122014)).to eq("Houston Dynamo") end end From 633e470d8e7e699ae277e015fccfb1a9c2502c7f Mon Sep 17 00:00:00 2001 From: Shawn Thompson Date: Sun, 4 Aug 2024 16:58:31 -0500 Subject: [PATCH 76/97] feat: most_tackles work in progress --- lib/stat_tracker.rb | 40 ++++++++++++++++++++++++++++++++++----- spec/stat_tracker_spec.rb | 30 +++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 7 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index e05830229d..becbdc55ae 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -226,7 +226,7 @@ def lowest_scoring_home_team # end - def worst_coach + # def worst_coach # use game_teams. # similar test structure as BO / LSV # compare team id to winn vs loss @@ -234,7 +234,7 @@ def worst_coach #helper method test should iterate over game_teams # - end + # end # def most_accurate_team @@ -279,9 +279,39 @@ def least_accurate_team(specific_season) end end - # def most_tackles - - # end + def most_tackles(specific_season) + specific_season_integer = specific_season.to_i + season_tackles_count = Hash.new(0) + @game_stats_data.each do |game_id, game_object| + season_tackles_count[specific_season_integer] = game_object.game_id + end + + season_tackles_count + require 'pry'; binding.pry + # season_game_count + # team_tackles = Hash.new(0) + # @seasons_stats_data.each do |game_id, game_object| + # team_tackles[game_object.team_id] += game_object.tackles + # end + + # most_team_tackles = team_tackles.max_by do |team, tackles| + # tackles + # end + + # best_tackle_team_id = most_team_tackles[0] + # id_to_name(best_tackle_team_id) + + # count_of_games_by_season + # total_season_goals = Hash.new(0) + # @game_stats_data.each do |game_id, game_object| + # goals = game_object.total_goals + # total_season_goals[game_object.season] += goals + # end + # average = total_season_goals.merge!(count_of_games_by_season) do |season, goals, games| + # (goals / games.to_f).round(2) + # end + # average + end def fewest_tackles(specific_season) specific_season_integer = specific_season.to_i diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 7f71f561d4..1e4081850b 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -368,9 +368,35 @@ end end - # describe 'most_tackles' do + describe 'most_tackles' do + it 'name of the Team with the most tackles in the season' do + expect(@stat_tracker.most_tackles(20122013)).to eq("FC Dallas") + end - # end + xit 'returns sum of games per season on mocks' do + hash = @stat_tracker.instance_variable_get(:@seasons_stats_data) + + object_1 = hash[1] + + object_1.instance_variable_set(:@tackles, (20122013)) + + expected = ("Houston Dynamo") + + expect(@stat_tracker.most_tackles).to eq(expected) + end + + xit 'returns sum of games per season on mocks' do + hash = @stat_tracker.instance_variable_get(:@seasons_stats_data) + + object_1 = hash[14] + + object_1.instance_variable_set(:@tackles, (20122013)) + + expected = ("Sporting Kansas City") + + expect(@stat_tracker.most_tackles).to eq(expected) + end + end describe 'fewest_tackles' do it 'returns name of the Team with the fewest tackles in the season' do From 3949a18326e6ca2fd179cb08010a2cff4ba04413 Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Sun, 4 Aug 2024 16:31:33 -0600 Subject: [PATCH 77/97] refactor: worst coach helper methods --- README.md | 2 +- lib/stat_tracker.rb | 43 +++++++-------------------------------- spec/stat_tracker_spec.rb | 9 +++++--- 3 files changed, 14 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index a024e62bda..e853f9ed6c 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,6 @@ * **Willett, Bryan** * [Github](https://github.com/bwillett2003) - * [LinkedIn](https://www.youtube.com/watch?v=ub82Xb1C8os&ab_channel=JuiceboxHero) + * [LinkedIn](https://www.linkedin.com/in/bryan-willett-063060321/) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 7394933793..ef39938f1b 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -219,8 +219,8 @@ def game_id_to_coach(game_id, team_id) end matching_season[1].head_coach end - - def worst_coach(specific_season) + + def win_loss_ratio(specific_season) specific_season_integer = specific_season.to_i team_win_loss_ratio = Hash.new { |hash, key| hash[key] = { win_count: 0, games_played: 0, tied_games: 0 } } @@ -238,46 +238,17 @@ def worst_coach(specific_season) team_win_loss_ratio[game_id_to_coach(game_id, game_object.home_team_id)][:tied_games] += 1 end end + return team_win_loss_ratio + end + + def worst_coach(specific_season) + team_win_loss_ratio = win_loss_ratio(specific_season) worst_team = team_win_loss_ratio.min_by do |coach_name, result_stats| result_stats[:win_count].to_f / result_stats[:games_played] end return worst_team[0] - - # games_in_season = {specific_season => []} - # @game_stats_data.each do |game_id, game_object| - # games_in_season[specific_season].push(game_id) if game_object.season == specific_season_integer - # end - - # teams_total_results = {} - # @seasons_stats_data.each do |game_id, game_object| - # if games_in_season[specific_season].include?(game_object.game_id) - # if !(teams_total_results.keys.include?(game_object.team_id)) - # teams_total_results[game_object.team_id] = [] - # teams_total_results[game_object.team_id].push(game_object.result) - # else - # teams_total_results[game_object.team_id].push(game_object.result) - # end - # end - # end - - # team_win_ratio = {} - # teams_total_results.map do |team_id, total_results| - - # win_counter = 0 - # total_results.each do |result| - # if result == "WIN" - # win_counter += 1 - # end - # end - # team_win_ratio[team_id] = (win_counter.to_f / total_results.length).truncate(2) - # end - - # worst_team = team_win_ratio.min_by do |team_id, win_ratio| - # win_ratio - # end - # id_to_coach(worst_team[0]) end def id_to_coach(id) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index d5cf6228be..f42b6260c4 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -318,12 +318,15 @@ # end + describe 'worst_coach' do - it 'returns coach with worst win percentage for the season' do - #make test that tests against actual data + hash_of_games = @stat_tracker.instance_variable_get(:@game_stats_data) + + hash_of_games[2012030221].instance_variable_set(:@season, 20122014) + hash_of_games[2012030223].instance_variable_set(:@season, 20122014) - expect(@stat_tracker.worst_coach('20122013')).to eq('Dan Bylsma') + expect(@stat_tracker.worst_coach('20122014')).to eq('John Tortorella') end end From a18226bdbfcb7dda7fc3aa0b23acb29237c87561 Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Sun, 4 Aug 2024 16:43:40 -0600 Subject: [PATCH 78/97] test: win loss ratio test suite --- spec/stat_tracker_spec.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index f42b6260c4..c8a7d0685c 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -317,7 +317,19 @@ # describe 'winningest_coach' do # end - + describe 'win_loss_ratio' do + it 'returns teams win loss ratio' do + hash_of_games = @stat_tracker.instance_variable_get(:@game_stats_data) + + hash_of_games[2012030221].instance_variable_set(:@season, 20122014) + hash_of_games[2012030223].instance_variable_set(:@season, 20122014) + + expected = {"John Tortorella"=>{:win_count=>0, :games_played=>2, :tied_games=>0}, + "Claude Julien"=>{:win_count=>2, :games_played=>2, :tied_games=>0}} + + expect(@stat_tracker.win_loss_ratio("20122014")).to eq(expected) + end + end describe 'worst_coach' do it 'returns coach with worst win percentage for the season' do From 9862baf208e3c824cc15f773de362a2216c3152e Mon Sep 17 00:00:00 2001 From: John Hill Date: Sun, 4 Aug 2024 16:44:13 -0600 Subject: [PATCH 79/97] Refactor: Refactored fewest tackles and added helper methods --- lib/stat_tracker.rb | 68 +++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 9e976f55b7..14ee3edfff 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -302,33 +302,53 @@ def least_accurate_team(specific_season) # end - def fewest_tackles(specific_season) - specific_season_integer = specific_season.to_i - games_in_season = {specific_season => []} - @game_stats_data.each do |game_id, game_object| - games_in_season[specific_season].push(game_id) if game_object.season == specific_season_integer - end + # def fewest_tackles(specific_season) + # specific_season_integer = specific_season.to_i + # games_in_season = {specific_season => []} + # @game_stats_data.each do |game_id, game_object| + # games_in_season[specific_season].push(game_id) if game_object.season == specific_season_integer + # end + + # team_total_tackles = {} + + # @seasons_stats_data.each do |game_key, game_object| + # if games_in_season[specific_season].include?(game_object.game_id) + # if !(team_total_tackles.keys.include?(game_object.team_id)) + # team_total_tackles[game_object.team_id] = 0 + # team_total_tackles[game_object.team_id] += game_object.tackles + # else + # team_total_tackles[game_object.team_id] += game_object.tackles + # end + # end + # end + # lowest_tackling_team = team_total_tackles.min_by do |team_id, tackles| + # tackles + # end + + # @teams_stats_data.each do |team_id, team_object| + # if lowest_tackling_team[0] == team_id + # return team_object.team_name + # end + # end + # end - team_total_tackles = {} + def team_tackles_in_games(game_ids) + team_total_tackles = Hash.new(0) - @seasons_stats_data.each do |game_key, game_object| - if games_in_season[specific_season].include?(game_object.game_id) - if !(team_total_tackles.keys.include?(game_object.team_id)) - team_total_tackles[game_object.team_id] = 0 - team_total_tackles[game_object.team_id] += game_object.tackles - else - team_total_tackles[game_object.team_id] += game_object.tackles - end - end - end - lowest_tackling_team = team_total_tackles.min_by do |team_id, tackles| - tackles + @seasons_stats_data.each do |key, season_object| + next unless game_ids.include?(season_object.game_id) + team_total_tackles[season_object.team_id] += season_object.tackles end - @teams_stats_data.each do |team_id, team_object| - if lowest_tackling_team[0] == team_id - return team_object.team_name - end - end + team_total_tackles end + + def fewest_tackles(specific_season) + game_ids = all_games_ids_in_specified_season(specific_season) + team_total_tackles = team_tackles_in_games(game_ids) + + lowest_tackling_team = team_total_tackles.min_by { | team_id, tackles| tackles} + id_to_name(lowest_tackling_team[0]) + end + end \ No newline at end of file From 700dd1ba02ec831670c6e7e514c0aca9784faa64 Mon Sep 17 00:00:00 2001 From: John Hill Date: Sun, 4 Aug 2024 16:44:57 -0600 Subject: [PATCH 80/97] Refacot: removed commented code --- lib/stat_tracker.rb | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 14ee3edfff..331d6dd563 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -301,36 +301,6 @@ def least_accurate_team(specific_season) # def most_tackles # end - - # def fewest_tackles(specific_season) - # specific_season_integer = specific_season.to_i - # games_in_season = {specific_season => []} - # @game_stats_data.each do |game_id, game_object| - # games_in_season[specific_season].push(game_id) if game_object.season == specific_season_integer - # end - - # team_total_tackles = {} - - # @seasons_stats_data.each do |game_key, game_object| - # if games_in_season[specific_season].include?(game_object.game_id) - # if !(team_total_tackles.keys.include?(game_object.team_id)) - # team_total_tackles[game_object.team_id] = 0 - # team_total_tackles[game_object.team_id] += game_object.tackles - # else - # team_total_tackles[game_object.team_id] += game_object.tackles - # end - # end - # end - # lowest_tackling_team = team_total_tackles.min_by do |team_id, tackles| - # tackles - # end - - # @teams_stats_data.each do |team_id, team_object| - # if lowest_tackling_team[0] == team_id - # return team_object.team_name - # end - # end - # end def team_tackles_in_games(game_ids) team_total_tackles = Hash.new(0) From 7e27b0dd8a7e8d98d0b0db8321f03db1b9d6af47 Mon Sep 17 00:00:00 2001 From: John Hill Date: Sun, 4 Aug 2024 16:51:30 -0600 Subject: [PATCH 81/97] Test: added team_tackles_in_games test --- spec/stat_tracker_spec.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index da22ea13fc..84299834e0 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -367,7 +367,7 @@ describe 'all_games_ids_in_specified_season' do it 'returns all game_ids in the specified season' do - expect(@stat_tracker.all_games_ids_in_specified_season(20122013)).to eq [2012030221, 2012030222, 2012030223, 2012030224, 2012030225, 2012030311, 2012030312, 2012030313, 2012030314, 2012030231, 2012030232, 2012030233, 2012030234, 2012030235] + expect(@stat_tracker.all_games_ids_in_specified_season(20122013)).to eq ([2012030221, 2012030222, 2012030223, 2012030224, 2012030225, 2012030311, 2012030312, 2012030313, 2012030314, 2012030231, 2012030232, 2012030233, 2012030234, 2012030235]) hash_of_games = @stat_tracker.instance_variable_get(:@game_stats_data) @@ -413,6 +413,14 @@ # end + describe "team_tackles_in_games" do + it "returns a hash with team_ids as the key, with the teams_tackles as the value" do + data = [2012030221, 2012030222, 2012030223, 2012030224] + + expect(@stat_tracker.team_tackles_in_games(data)).to eq({3=>154, 6=>139}) + end + end + describe 'fewest_tackles' do it 'returns name of the Team with the fewest tackles in the season' do expect(@stat_tracker.fewest_tackles('20122013')).to eq("Sporting Kansas City") From c710da3126a94293ee0602a0e1b7f7120f1aa8e1 Mon Sep 17 00:00:00 2001 From: Joe Chirchirillo Date: Sun, 4 Aug 2024 16:53:05 -0600 Subject: [PATCH 82/97] test: id to coach test suite --- lib/stat_tracker.rb | 2 +- spec/stat_tracker_spec.rb | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index ef39938f1b..95de8d4715 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -213,6 +213,7 @@ def lowest_scoring_home_team # def winningest_coach # end + def game_id_to_coach(game_id, team_id) matching_season = @seasons_stats_data.find do |key, seasons_object| seasons_object.team_id == team_id && seasons_object.game_id == game_id @@ -256,7 +257,6 @@ def id_to_coach(id) return game_object.head_coach if game_object.team_id == id end end - # def most_accurate_team diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index c8a7d0685c..19e2c4803b 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -313,10 +313,7 @@ expect(@stat_tracker.lowest_scoring_home_team).to eq('Sporting Kansas City') end end - - # describe 'winningest_coach' do - - # end + describe 'win_loss_ratio' do it 'returns teams win loss ratio' do hash_of_games = @stat_tracker.instance_variable_get(:@game_stats_data) @@ -330,6 +327,20 @@ expect(@stat_tracker.win_loss_ratio("20122014")).to eq(expected) end end + + describe 'id to coach' do + it 'returns head coach from id' do + @seasons_data = StatTracker.game_teams_reader(@locations[:game_teams]) + @seasons_data.each do |game_id, game_object| + expect(@stat_tracker.id_to_coach(game_object.team_id)).to eq(game_object.head_coach) + end + end + end + + # describe 'winningest_coach' do + + # end + describe 'worst_coach' do it 'returns coach with worst win percentage for the season' do From c2276fe1a4f16e3538bdecea01006910e8fe40b2 Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Sun, 4 Aug 2024 19:42:12 -0500 Subject: [PATCH 83/97] refactor: Removed commented code for rspec test that already exists. --- lib/stat_tracker.rb | 21 +++++++++++---------- spec/stat_tracker_spec.rb | 5 +---- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 7c96a05b61..e47d52c0b0 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -214,9 +214,6 @@ def lowest_scoring_home_team id_to_name(lowest_scoring_team_id) end - # def winningest_coach - - # end def game_id_to_coach(game_id, team_id) matching_season = @seasons_stats_data.find do |key, seasons_object| @@ -224,16 +221,16 @@ def game_id_to_coach(game_id, team_id) end matching_season[1].head_coach end - + def win_loss_ratio(specific_season) specific_season_integer = specific_season.to_i team_win_loss_ratio = Hash.new { |hash, key| hash[key] = { win_count: 0, games_played: 0, tied_games: 0 } } - + @game_stats_data.each do |game_id, game_object| - next unless game_object.season == specific_season_integer - team_win_loss_ratio[game_id_to_coach(game_id, game_object.away_team_id)][:games_played] += 1 - team_win_loss_ratio[game_id_to_coach(game_id, game_object.home_team_id)][:games_played] += 1 - + next unless game_object.season == specific_season_integer + team_win_loss_ratio[game_id_to_coach(game_id, game_object.away_team_id)][:games_played] += 1 + team_win_loss_ratio[game_id_to_coach(game_id, game_object.home_team_id)][:games_played] += 1 + if game_object.home_goals > game_object.away_goals team_win_loss_ratio[game_id_to_coach(game_id, game_object.home_team_id)][:win_count] += 1 elsif game_object.home_goals < game_object.away_goals @@ -246,9 +243,13 @@ def win_loss_ratio(specific_season) return team_win_loss_ratio end + # def winningest_coach + + # end + def worst_coach(specific_season) team_win_loss_ratio = win_loss_ratio(specific_season) - + worst_team = team_win_loss_ratio.min_by do |coach_name, result_stats| result_stats[:win_count].to_f / result_stats[:games_played] end diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 5ace9406c8..f5108b5069 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -246,10 +246,7 @@ end end - # describe 'count_of_teams' do - - # end - + # describe 'best_offense' do # end From 36b99ab9952942c8a1f0240556b22711cd20db92 Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Sun, 4 Aug 2024 19:43:17 -0500 Subject: [PATCH 84/97] refactor: Removed more commented code for rspec that already exists. --- spec/stat_tracker_spec.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index f5108b5069..14cdce9b29 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -245,11 +245,6 @@ expect(@stat_tracker.average_goals_by_season).to eq(expected) end end - - - # describe 'best_offense' do - - # end describe 'count_of_teams' do it 'returns the total number of teams' do From d2a4863bafacad79d15c63050fc5bc21e5556999 Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Sun, 4 Aug 2024 19:44:56 -0500 Subject: [PATCH 85/97] refactor: Relocated winninest_coach method to be in line with worst_coach --- lib/stat_tracker.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index e47d52c0b0..a6a4c4f8da 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -243,9 +243,9 @@ def win_loss_ratio(specific_season) return team_win_loss_ratio end - # def winningest_coach + def winningest_coach - # end + end def worst_coach(specific_season) team_win_loss_ratio = win_loss_ratio(specific_season) From 175fd2424253058664da2ee88b626bf563db7e87 Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Sun, 4 Aug 2024 20:50:41 -0400 Subject: [PATCH 86/97] refactor: least_accurate_team to use helper methods --- lib/stat_tracker.rb | 40 +++++---------------------------------- spec/stat_tracker_spec.rb | 2 -- 2 files changed, 5 insertions(+), 37 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 7c96a05b61..f57ad05c1f 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -298,42 +298,12 @@ def most_accurate_team(specific_season) end def least_accurate_team(specific_season) - specific_season_integer = specific_season.to_i - games_in_season = {specific_season => []} - @game_stats_data.each do |game_id, game_object| - games_in_season[specific_season].push(game_id) if game_object.season == specific_season_integer - end - - team_goal_ratio = {} - - @seasons_stats_data.each do |game_key, game_object| - if games_in_season[specific_season].include?(game_object.game_id) - if !(team_goal_ratio.keys.include?(game_object.team_id)) - if game_object.shots > 0 - team_goal_ratio[game_object.team_id] = [] - team_goal_ratio[game_object.team_id].push((game_object.goals / game_object.shots.to_f).truncate(2)) - else - team_goal_ratio[game_object.team_id].push(0.00) - end - else - if game_object.shots > 0 - team_goal_ratio[game_object.team_id].push((game_object.goals / game_object.shots.to_f).truncate(2)) - else - team_goal_ratio[game_object.team_id].push(0.00) - end - end - end - end - - lowest_accuracy_team = team_goal_ratio.min_by do |team, accuracy_per_game| - accuracy_per_game.sum / accuracy_per_game.length - end + teams_data = teams_shots_and_goals(all_games_ids_in_specified_season(specific_season)) - @teams_stats_data.each do |team_id, team_object| - if lowest_accuracy_team[0] == team_id - return team_object.team_name - end - end + most_accurate = teams_data.reject { |_, team_data| team_data[:shots] == 0 || team_data[:goals] == 0 } + .min_by { |_, team_data| team_data[:goals].to_f / team_data[:shots] } + + id_to_name(most_accurate[0]) end # def most_tackles diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 5ace9406c8..ae7a63daaf 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -433,8 +433,6 @@ describe 'least_accurate_team' do it 'returns name of the Team with the worst ratio of shots to goals for the season.' do expect(@stat_tracker.least_accurate_team('20122013')).to eq('Sporting Kansas City') - #expect(@stat_tracker.least_accurate_team(20132014)).to eq "New York City FC" - #expect(@stat_tracker.least_accurate_team(20142015)).to eq "Columbus Crew SC" end end From 0b9be1df2f1ef3c1dca016b18cb5744c1006a4de Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Sun, 4 Aug 2024 19:51:33 -0500 Subject: [PATCH 87/97] feat: winningest_coach method created using worst_coach helper methods. --- lib/stat_tracker.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index a6a4c4f8da..b0f3013816 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -243,8 +243,14 @@ def win_loss_ratio(specific_season) return team_win_loss_ratio end - def winningest_coach + def winningest_coach(specific_season) + team_win_loss_ratio = win_loss_ratio(specific_season) + best_team = team_win_loss_ratio.max_by do |coach_name, result_stats| + result_stats[:win_count].to_f / result_stats[:games_played] + end + + return best_team[0] end def worst_coach(specific_season) From bae75efa4d0e1bfee0e6cd3660f6a913d711ad69 Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Sun, 4 Aug 2024 20:55:10 -0400 Subject: [PATCH 88/97] refactor: highest_scoring_visitor to use helper methods --- lib/stat_tracker.rb | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 7c96a05b61..389c5c476f 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -168,24 +168,12 @@ def worst_offense def highest_scoring_visitor - visitor_team_scores = {} - @game_stats_data.each do |game_id, game_object| - if !(visitor_team_scores.keys.include?(game_object.away_team_id)) - visitor_team_scores[game_object.away_team_id] = [] - visitor_team_scores[game_object.away_team_id].push(game_object.away_goals) - else - visitor_team_scores[game_object.away_team_id].push(game_object.away_goals) - end - end - winning_team = visitor_team_scores.max_by do |team, scores| - (scores.sum / scores.length.to_f).round(2) - end - - @teams_stats_data.each do |team_id, team_object| - if winning_team[0] == team_id - return team_object.team_name - end - end + away_teams_goals_data = team_seasons_goals('away') + + lowest_scoring_team = teams_scores_average_max_by(away_teams_goals_data) + + worst_visitor_id = lowest_scoring_team[0] + id_to_name(worst_visitor_id) end def highest_scoring_home_team From ff1ea0f4ffd19e1f7a797d20bae723f2017af8ec Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Sun, 4 Aug 2024 19:58:14 -0500 Subject: [PATCH 89/97] test: winningest_coach rspec test. --- spec/stat_tracker_spec.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 14cdce9b29..8be4c602b4 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -370,11 +370,17 @@ end end - # describe 'winningest_coach' do + describe 'winningest_coach' do + it 'returns coach with best win percentage for the season' do + hash_of_games = @stat_tracker.instance_variable_get(:@game_stats_data) - # end + hash_of_games[2012030222].instance_variable_set(:@season, 20122014) + hash_of_games[2012030224].instance_variable_set(:@season, 20122014) + + expect(@stat_tracker.winningest_coach('20122014')).to eq('Claude Julien') + end + end - describe 'worst_coach' do it 'returns coach with worst win percentage for the season' do hash_of_games = @stat_tracker.instance_variable_get(:@game_stats_data) From fb3a4b6b1e92dad36f10dc804080c958ad5343f5 Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Sun, 4 Aug 2024 20:00:15 -0500 Subject: [PATCH 90/97] refactor: corrected indentation between id_to_name and worst_offense. --- lib/stat_tracker.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index b0f3013816..0c90fb1ab2 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -156,8 +156,6 @@ def id_to_name(id) end end - - def worst_offense teams_goals_data = team_seasons_goals(['home','away']) worst_offense_team = teams_scores_average_min_by(teams_goals_data) From 6eced626ca829e4065211d0dc6924b2025d6d588 Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Sun, 4 Aug 2024 20:01:03 -0500 Subject: [PATCH 91/97] refactor: corrected indentation worst_offense and highest_scoring_visitor. --- lib/stat_tracker.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 0c90fb1ab2..47e0677495 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -164,7 +164,6 @@ def worst_offense id_to_name(worst_offense_team_id) end - def highest_scoring_visitor visitor_team_scores = {} @game_stats_data.each do |game_id, game_object| From 1ed58140ddb976bf959786beea725d3817a58af1 Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Sun, 4 Aug 2024 20:02:03 -0500 Subject: [PATCH 92/97] corrected more indentation between methods. --- lib/stat_tracker.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/stat_tracker.rb b/lib/stat_tracker.rb index 47e0677495..8625576817 100644 --- a/lib/stat_tracker.rb +++ b/lib/stat_tracker.rb @@ -291,7 +291,6 @@ def teams_shots_and_goals(game_ids) teams_data end - def most_accurate_team(specific_season) teams_data = teams_shots_and_goals(all_games_ids_in_specified_season(specific_season)) @@ -362,5 +361,4 @@ def fewest_tackles(specific_season) lowest_tackling_team = team_total_tackles.min_by { | team_id, tackles| tackles} id_to_name(lowest_tackling_team[0]) end - end \ No newline at end of file From 5a47a45a184333a68183d66f6e438534dd4599e3 Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Mon, 5 Aug 2024 09:15:28 -0500 Subject: [PATCH 93/97] refactor: Removed commented code. --- spec/stat_tracker_spec.rb | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index db6912b2af..8528206503 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -3,7 +3,6 @@ RSpec.describe StatTracker do before(:each) do - # # Test Data game_path_dummy = './data/games_dummy.csv' team_path_dummy = './data/teams_dummy.csv' game_teams_path_dummy = './data/game_teams_dummy.csv' @@ -15,19 +14,6 @@ } @stat_tracker = StatTracker.from_csv(@locations) - - # #Actual Data - # game_path = './data/games.csv' - # team_path = './data/teams.csv' - # game_teams_path = './data/game_teams.csv' - - # @locations_actual_data = { - # games: game_path, - # teams: team_path, - # game_teams: game_teams_path - # } - - # @stat_tracker_large_data = StatTracker.from_csv(@locations_actual_data) end describe "initialize" do From cdeb1be33dfd5fd08fccb5d4396675888895fc70 Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Mon, 5 Aug 2024 09:16:36 -0500 Subject: [PATCH 94/97] refactor: Removed commented code and improved white space. --- spec/stat_tracker_spec.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/stat_tracker_spec.rb b/spec/stat_tracker_spec.rb index 8528206503..5ef13f6d82 100644 --- a/spec/stat_tracker_spec.rb +++ b/spec/stat_tracker_spec.rb @@ -127,7 +127,7 @@ describe 'percentage_ties' do it 'returns percentage of games that has resulted in a tie (rounded to the nearest 100th)' do - expect(@stat_tracker.percentage_ties).to eq(0.00) # NO TIES CURRENTLY LISTED + expect(@stat_tracker.percentage_ties).to eq(0.00) hash_of_games = @stat_tracker.instance_variable_get(:@game_stats_data) @@ -152,7 +152,7 @@ hash_of_games[2012030311].instance_variable_set(:@home_goals, 15) hash_of_games[2012030312].instance_variable_set(:@away_goals, 15) - hash_of_games[2012030312].instance_variable_set(:@home_goals, 15) # UPDATE DATA SO TIES AND WINS ARE 50/50 + hash_of_games[2012030312].instance_variable_set(:@home_goals, 15) expect(@stat_tracker.percentage_ties).to eq(0.50) end @@ -199,7 +199,6 @@ expect(@stat_tracker.count_of_games_by_season).to eq(expected) end - end describe 'average_goals_by_season' do From ed986516dbe4139d0bbe1a0b3bb572e2c92d16c2 Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Mon, 5 Aug 2024 09:25:40 -0500 Subject: [PATCH 95/97] refactor: updating README. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index e853f9ed6c..0654b9a102 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ # Futbol +## About + +* The StatTracker application provides detailed statistical analysis for a sports league, covering game, league, and season metrics. It includes methods to determine the highest and lowest game scores, percentages of home and visitor wins, average goals per game, and games by season. League statistics cover team performance, identifying the best and worst offenses, and the highest and lowest-scoring teams at home and away. Season-specific methods analyze coach performance, team accuracy, and tackle counts. StatTracker is a comprehensive for analyzing league performance and trends. + +## Built With + +* Ruby 3.2.2 & RSpec 3.13 + ## Deliverables **Outline of Check-ins** From 8fb792ea4f86bf2c44946184ea24d36b7d50525b Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Mon, 5 Aug 2024 09:28:03 -0500 Subject: [PATCH 96/97] refactor: Updated LinkedIn URL --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0654b9a102..e6a42bf141 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ * **Delaney, Kyle** * [Github](https://github.com/kylomite) - * [LinkedIn](https://www.linkedin.com/in/kyle-delaney-115164172/edit/forms/next-action/after-connect-add-position/) + * [LinkedIn](https://www.linkedin.com/in/kyle-delaney-115164172) * **Hill, John** * [Github](https://github.com/jphill19) From 9af995b38974c55aaef646799cfe76ad3e612fb5 Mon Sep 17 00:00:00 2001 From: Bryan Willett Date: Mon, 5 Aug 2024 09:57:28 -0500 Subject: [PATCH 97/97] docs: Completed README --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e6a42bf141..2e25d3cebc 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,18 @@ * We all agreed Github Project is most likely the industry standard and it would behoove us to familiarize ourselves with the application. **Code Design** -* Expand upon this. +* After assessing the project requirements, we decided to structure our code design around four primary classes: + + * `StatTracker`: This class will encapsulate the core logic and functionality, managing most of the codebase. + + * `Game`, `Team`, and `Season`: These classes will act as auxiliary components and data storage. + +Additionally, we created three simplified dummy CSV files with minimal data. This approach ensures our tests execute efficiently by avoiding the overhead of processing large datasets. + +To streamline our development process and prevent issues with method assignment, we established a clear code architecture from the outset. + +Given our asynchronous workflow and the fact that different team members were working on various methods concurrently, we anticipated potential misalignment between our to-do list and the evolving code structure. To mitigate this risk, we preemptively defined method names in both the library (lib) and specification (spec) files, adhering to the assignment order. + * We have implemented a style guide to adhere to for consistency. * [Link to Style Guide](https://docs.google.com/document/d/1AS3GIR84IMyoNUbN8eiSnuM3o6o9fscvlKvjhJSxokc/edit) @@ -35,6 +46,8 @@ * [First DTR 7/29/24](https://docs.google.com/document/d/1HEdpmbyhJbeJtJJ8pkOvZ5zeb07FeqkCZlBai6aSP0s/edit) +* Discussed second DTR 8/02/24 + ## Project Retro **Retro**