Learn R Programming

nhlscrape

A package for scraping the nhl API and HTML reports to build a database. Can be used to generate statistics from the information pulled.

Usage

To use this package:

  1. Import 'nhlscraper' and run SetDbPath to set the location for the database file.
  2. Use AddAllTeams() and the find team_id using the GetTeamId function.
  3. Find game_ids using the GetGameIdRange() function.
  4. Add game reports to the database using AddGameEvents().
  5. Find a player_id using the GetPlayerId('player_name') function.
  6. Get player statistics using GetPlayerStats(). You can also manually query the database using QueryDb.

Example:

library(nhlscrape)

# Set db path to somewhere
SetDbPath("C:/Users/Adam/Documents/nhl.sqlite")

# Select the leafs
AddAllTeamsDb()
team_id <- GetTeamId("toronto maple leafs")
gids <- GetGameIdRange(team_id, "2019-09-30", "2019-12-18")

# Add games
AddGameEvents(gids)

# Get stats for player
# Tavares
player_id <- GetPlayerId("john tavares")

stats <- GetPlayerStats(player_id, gids, team_id)

Example Shiny App

You can see an example of the heatmap function being plotted in this demo shiny app at: https://aazoulay.shinyapps.io/nhl_shiny/

Copy Link

Version

Install

install.packages('nhlscrape')

Monthly Downloads

23

Version

0.1.3

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Adam Azoulay

Last Published

February 25th, 2020

Functions in nhlscrape (0.1.3)

QueryDb

Send query to database
SetDbPath

Set database location on system
GetPlayerId

Search player id using name
AddAllTeamsDb

Add team metadata to the database
GetGameIdRange

Find game ids for a specific team and date range
GetPlayerStats

WIP - Get advanced statistics for player_id on team_id in a list of games.
AddTeamRoster

Adds rosters for team id and a specific season
AddGameEvents

Adds all game events for game_id to the database for analysis
GetHeatmapCoords

Get the heatmap coordinates for certain events in the database
GetTeamId

Search for team id from team name
GetDbPath

Retrieve database location on system
GetApiJson

Call the nhl api and parse the retun