Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Percentages #1144

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
# Futbol
# Futbol Project - Team LPR

Repository for the Team LPR version of the [Turing School](https://turing.edu/) Futbol project.

Team LPR Members:
---------------------------------
Patrick Little

Logan Sauer

Rig Freyr

---------------------------------
- Check-Ins
----------------------------------
We are planning on having scheduled check-ins at 2:00 pm MST on Tuesday the 14th and Friday the 17th, as well as at 11:00 am on Monday the 20th. However, we also plan to check-in on a more continuous and less formal basis throughout the development of the project.

-----------------------------------
- Project Organization and Workflow
-----------------------------------
Our primary vehicle for collaboration will be through GitHub; specifically, developing parallel branches of the same project repository in tandem and merging them when necessary. All merges will be handled as a group; no group member will merge their own pull requests. All group efforts and responsibilites will be tracked through a Miro board (link:https://miro.com/app/board/uXjVLuMoXq0=/) and jointly updated throughout the development process. The main body of the project can be broken into Game, League, and Season statistics methods; the team will attempt to complete one of these three categories of instanced methods collaboratavely each day.

----------------------------------
- How we made a decision on Project Organization
-----------------------------------
We discussed learning the usage of GitHub Projects to coordinate our work in this project, but decided it was too steep of an additional learning curve to manage for our first group development effort. Miro seemed like an efficient and easy to use alternative that we could all learn to use asynchronously in a short amount of time.


----------------------------------
- Approach to Code Design
----------------------------------
In addition to the required StatTracker class, we will need Team, Game, and Season classes to handle manipulation and sorting of the underlying CSV data for us. We will start by divying up the required Game Statistics Methods between the three of us and working on them asynchronously, so that each team member only has two or three methods to complete each day. On the next day, we will repeat this process with the League Statistics methods, and then once more with the Season Statistics on the day after that.

-----------------------------------
Initial DTR Doc Link:
-----------------------------------
https://docs.google.com/document/d/1ooIWGVt1z2ep9oW6uYpbnLjC3UoshCzuDN0YrBzbF_g/edit?pli=1&tab=t.0

----------------------------------
Contributors
----------------------------------

Patrick Little
Github profile link: https://github.com/little-Patrick

Rig Freyr
Github profile link: https://github.com/ontruster74

Logan Sauer
Github profile link: https://github.com/ldsauer


Starter repository for the [Turing School](https://turing.edu/) Futbol project.
21 changes: 21 additions & 0 deletions data/simple_game_teams.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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
2012030313,5,away,LOSS,OT,Dan Bylsma,1,13,46,16,6,0,57.3,8,10
2012030313,6,home,WIN,OT,Claude Julien,2,10,34,18,5,0,42.7,10,13
2012030314,5,away,LOSS,REG,Dan Bylsma,0,6,33,8,3,0,47.5,8,1
2012030314,6,home,WIN,REG,Claude Julien,1,6,25,8,3,0,52.5,11,5
2012030231,17,away,LOSS,REG,Mike Babcock,1,5,43,10,3,0,52.5,6,4
2012030231,16,home,WIN,REG,Joel Quenneville,2,10,24,10,3,1,47.5,2,11
21 changes: 21 additions & 0 deletions data/simple_games.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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
2012030236,20122013,Postseason,5/28/13,16,17,2,3,Dignity Health Sports Park,/api/v1/venues/null
2012030237,20122013,Postseason,5/30/13,17,16,1,2,Gillette Stadium,/api/v1/venues/null
2012030121,20122013,Postseason,5/2/13,9,8,2,2,Red Bull Arena,/api/v1/venues/null
2012030122,20122013,Postseason,5/3/13,9,8,1,3,Red Bull Arena,/api/v1/venues/null
2012030123,20122013,Postseason,5/5/13,8,9,1,5,Yankee Stadium,/api/v1/venues/null
2012030124,20122013,Postseason,5/7/13,8,9,2,3,Yankee Stadium,/api/v1/venues/null
21 changes: 21 additions & 0 deletions data/simple_teams.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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
30,37,Orlando City SC,ORL,Exploria Stadium,/api/v1/teams/30
15,24,Portland Timbers,POR,Providence Park,/api/v1/teams/15
19,18,Philadelphia Union,PHI,Talen Energy Stadium,/api/v1/teams/19
24,32,Real Salt Lake,RSL,Rio Tinto Stadium,/api/v1/teams/24
27,28,San Jose Earthquakes,SJ,Avaya Stadium,/api/v1/teams/27
2,22,Seattle Sounders FC,SEA,Centruy Link Field,/api/v1/teams/2
11 changes: 11 additions & 0 deletions lib/game.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Game
attr_reader :home_team_id, :away_goals, :home_goals, :venue, :venue_link

def initialize(home_team_id, away_goals, home_goals, venue, venue_link)
@home_team_id = home_team_id
@away_goals = away_goals
@home_goals = home_goals
@venue = venue
@venue_link = venue_link
end
end
9 changes: 9 additions & 0 deletions lib/game_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class GameFactory
def self.create_games(filepath)
games = []
CSV.foreach(filepath, headers: true, header_converters: :symbol) do |row|
games << Game.new(row[:home_team_id], row[:away_goals].to_i, row[:home_goals].to_i, row[:venue], row[:venue_link])
end
return games
end
end
21 changes: 21 additions & 0 deletions lib/game_team.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class GameTeam
attr_reader :game_id, :team_id, :hoa, :result, :head_coach, :goals, :shots, :tackles, :pim, :powerPlayOpportunities, :faceOffWinPercentage, :giveaways, :takeaways

def initialize(game_id, team_id, hoa, result, head_coach, goals, shots, tackles, pim, powerPlayOpportunities, faceOffWinPercentage, giveaways, takeaways)
@game_id = game_id
@team_id = team_id
@hoa = hoa
@result = result
@head_coach = head_coach
@goals = goals
@shots = shots
@tackles = tackles
@pim = pim
@powerPlayOpportunities = powerPlayOpportunities
@faceOffWinPercentage = faceOffWinPercentage
@giveaways = giveaways
@takeaways = takeaways
end
end


10 changes: 10 additions & 0 deletions lib/game_team_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class GameTeamFactory
def self.create_game_teams(filepath)
game_teams = []
CSV.foreach(filepath, headers: true, header_converters: :symbol) do |row|
game_teams << GameTeam.new(row[:game_id], row[:team_id], row[:hoa], row[:result], row[:head_coach], row[:goals].to_i, row[:shots].to_i, row[:tackles].to_i, row[:pim].to_i, row[:powerPlayOpportunities].to_i, row[:faceOffWinPercentage].to_i, row[:giveaways].to_i, row[:takeaways].to_i)
end
return game_teams
end
end

118 changes: 118 additions & 0 deletions lib/stat_tracker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
require 'pry'
class StatTracker
attr_reader :games, :teams, :game_teams

def initialize(games, teams, game_teams)
@games = games
@teams = teams
@game_teams = game_teams
end

def self.from_csv(filepaths_hash)
games = GameFactory.create_games(filepaths_hash[:games])
teams = TeamFactory.create_teams(filepaths_hash[:teams])
game_teams = GameTeamFactory.create_game_teams(filepaths_hash[:game_teams])

return StatTracker.new(games, teams, game_teams)
end

# Game Statistics

def highest_total_score
highest_game = @games.max_by {|game| game.away_goals + game.home_goals}
return (highest_game.away_goals + highest_game.home_goals)
end

def lowest_total_score
lowest_game = @games.min_by {|game| game.away_goals + game.home_goals}
return (lowest_game.away_goals + lowest_game.home_goals)
end

def percentage_home_wins
# (wins / total_games) * 100.round(2)
home_wins = @game_teams.find_all { |game| (game.hoa == "home") && (game.result == "WIN")}.count.to_f
total_games = @game_teams.count.to_f
return (home_wins / total_games) * 100.round(2)
end

def percentage_visitor_wins
visitor_wins = @game_teams.find_all { |game| (game.hoa == "away") && (game.result == "WIN")}.count.to_f
total_games = @game_teams.count.to_f
return (visitor_wins / total_games) * 100.round(2)
end

def percentage_ties
games_tied = @game_teams.find_all { |game| game.result == "TIE"}.count.to_f
total_games = @game_teams.count.to_f
return (games_tied / total_games) * 100.round(2)
end

def count_of_games_by_season

end

def average_goals_per_game

end

def average_goals_by_season

end

# League Statistics

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

# Season Stats

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
12 changes: 12 additions & 0 deletions lib/team.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Team
attr_reader :team_id, :franchiseId, :teamName, :abbreviation, :stadium, :link

def initialize(team_id, franchiseId, teamName, abbreviation, stadium, link)
@team_id = team_id
@franchiseId = franchiseId
@teamName = teamName
@abbreviation = abbreviation
@stadium = stadium
@link = link
end
end
9 changes: 9 additions & 0 deletions lib/team_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class TeamFactory
def self.create_teams(filepath)
teams = []
CSV.foreach(filepath, headers: true, header_converters: :symbol) do |row|
teams << Team.new(row[:team_id], row[:franchiseId], row[:teamName], row[:abbreviation], row[:stadium], row[:link])
end
return teams
end
end
16 changes: 16 additions & 0 deletions runner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# runner.rb
require './spec/spec_helper'

game_path = './data/simple_games.csv'
team_path = './data/simple_teams.csv'
game_teams_path = './data/simple_game_teams.csv'

locations = {
games: game_path,
teams: team_path,
game_teams: game_teams_path
}

stat_tracker = StatTracker.from_csv(locations)

require 'pry'; binding.pry
Empty file added spec/game_factory.rb
Empty file.
Empty file added spec/game_spec.rb
Empty file.
Empty file added spec/game_team.rb
Empty file.
Empty file added spec/game_team_factory.rb
Empty file.
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require './lib/stat_tracker'
require './lib/game'
require './lib/team'
require './lib/game_team'
require './lib/game_factory'
require './lib/team_factory'
require './lib/game_team_factory'
require 'csv'
require 'rspec'
require 'pry'
Loading