The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Sport::Analytics::NHL::Tools - Commonly used routines that are system-dependent

SYNOPSIS

Commonly used routines that are specific to the Sport::Analytics::NHL ecosystem. For the independent stuff see Sport::Analytics::NHL::Util .

  use Sport::Analytics::NHL::Tools;
  my $game = parse_nhl_game_id(2011020001);
  my $season = get_season_from_date(20110202); # returns 2010
  my $team = resolve('NY Rangers'); # returns NYR
  #and so on

Provides global variable $DB that can be used to store the MongoDB handle.

FUNCTIONS

parse_nhl_game_id
 Parses the SSSSTTNNNN nhl id
 Arguments: the nhl game id
 Returns: hashref with season, stage, season id and our SSSSTNNNN id
parse_our_game_id
 Parses the SSSSTNNNN our id
 Arguments: our game id
 Returns: hashref with season, stage, season id and our SSSSTNNNN id
get_season_from_date
 Figures out the NHL season (start year) the given YYYYMMDD date refers to
 Arguments: the YYYYMMDD date
 Returns: the YYYY or YYYY-1 season
get_schedule_json_file
 Returns the path to the schedule file in the filesystem
 Arguments: the season and the root of the data (optional)
 Returns: the path to the schedule file
resolve_team
 Attempts to resolve the name of a team to the normalized 3-letter id
 Arguments: the name of a team, optional no-db force flag
 Returns: the 3-letter normalized id
convert_new_schedule_game

Converts a game record obtained from the 'live' interface to a normalized form

 Arguments: the game record
 Returns: the normalized game
arrange_new_schedule_by_date

Arranges the schedule obtained from the 'live' interface by dates

 Arguments: the schedule
 Returns: hashref with keys of dates,
  values of lists of normalized game records
convert_old_schedule_game

Converts a game record obtained from the API interface to a normalized form

 Arguments: the game record
 Returns: the normalized game
arrange_old_schedule_by_date

Arranges the schedule obtained from the API interface by dates

 Arguments: the schedule
 Returns: hashref with keys of dates,
  values of lists of normalized game records
convert_schedule_game

Converts a game record obtained scraping the schedules to a normalized form

 Arguments: the game record
 Returns: the normalized game
arrange_schedule_by_date

Arranges the schedule obtained by the scraper by dates

 Arguments: the schedule
 Returns: hashref with keys of dates,
  values of lists of normalized game records
get_games_for_dates_from_db

Gets the list of the games scheduled for given dates using the file storage

 Arguments: the list of dates
 Returns: the list of normalized game records
get_games_for_dates_from_fs

Gets the list of the games scheduled for given dates using the database

 Arguments: the list of dates
 Returns: the list of normalized game records
get_games_for_dates

Gets the list of the games scheduled for given dates

 Arguments: the list of dates
 Returns: the list of normalized game records
get_start_stop_date

Gets the earliest possible start and latest possible end for a season in format YYYY-MM-DD

 Arguments: the season
 Returns: (YYYY-09-02,YYYY+1-09-01)
make_game_path

Creates and/or returns the game path for a given season, stage, season_id

 Arguments: season, stage, season_id, root storage dir (optional)
 Returns: the storage path (created if necessary)
read_schedules

Reads the existing schedules for the given range of seasons

 Arguments: the hashref with first and last season of the range
 Returns: the schedule data, hashref by season
get_game_id_from_path

Given the game path, produces our SSSSTNNNN game id

 Arguments: the game path
 Returns the SSSSTNNNN id, or undef if the matching of the path failed
read_existing_game_ids

Find games already scraped into the filesystem and returns the game ids of them.

 Arguments: the season to look for
 Returns: hashref of game ids as keys and 1s as values
str3time

Wraps around str2time to fix its parsing the pre-1969 dates to the same timestamp as their 100 years laters. Arguments: the str2time argument string Returns: the correct timestamp (negative for pre-1969)

get_game_path_from_id

Gets the expected SSSS/TTTT/NNNN path for our 9-digit game id. Arguments: our 9-digit game id Returns: the path (creates it if necessary)

get_game_files_by_id

Gets existing game files for the given game Id. Assumes SSSS/TTTT/NNNN file tree structure under the root data directory. Arguments: * our 9-digit game id * (optional) root data directory Returns: The list of html/json reports from the game directory

vocabulary_lookup

Normalizes one of the following event properties from different variants: * penalty * shot_type * miss * strength * stoppage reason

Arguments: the property name and the original string Returns: the normalized, vocabulary-matched string

normalize_penalty

Normalizes an NHL Report penalty string including a vocabulary lookup Arguments: the original string Returns: the normalized, vocabulary-matched string

Prints the list of parsed events in a compact for. Work in progress. Do not use.

AUTHOR

More Hockey Stats, <contact at morehockeystats.com>

BUGS

Please report any bugs or feature requests to contact at morehockeystats.com, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Sport::Analytics::NHL::Tools. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Sport::Analytics::NHL::Tools

You can also look for information at: