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.
GLOBAL VARIABLES
- $DB
-
This global exported variable is used to hold an instance of a MongoDB connection.
- $CACHES
-
This global exported hash reference is used to hold various information for caching purposes
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
get_catalog_map
-
Convert a catalog collection (i.e. stopreasons) to a hashref NAME to MongoID
Arguments: the catalog name Returns: the aforementioned hashref
get_event_strength
-
Gets the event strength from the 'str' collection.
Arguments: the event the timeline of the game's strengths Returns: the matched strength.
get_first_coord_adjust_event
-
The NHL coordinates are inconsistent in a way that sometimes the home team's zone is a negative X, and sometimes is a positive. Therefore there's a need to coordinate adjustments. This function returns the first suitable event to deduce this adjustment.
Arguments: the game the zones map Returns: the matched event or undef.
get_game_coords_adjust
-
As described above, this produces an adjustment for the coordinates. The coordinates are adjusted either by the first goal, or by other suitable event.
Arguments: the game the zones map Returns: 1 or -1
get_game_first_coord_goal
-
Gets the first goal that allows to adjust the coordinates.
Arguments: the game the zones map Returns: the matched goal or undef.
get_game_goalies
-
Gets the list of all goalies who participated in the game
Arguments: the game Returns: the arrayref with the goalies.
get_games_from_schedule
-
Gets the scheduled games from the schedule collection by game ids
Arguments: array of game ids Returns: array of scheduled game entries
get_player_position
-
Gets the position of a given player and stores it in the global cache ($CACHE->{players})
Arguments: player's NHL ID Returns: the position or 'S'
get_zones
-
Gets the catalog map of zones
Arguments: none Returns: hashref of four zones (OFF, NEU, DEF, UNK) and their Mongo IDs.
has_on_ice
-
Tests if the event has a valid on-ice field (an array of two vectors)
Arguments: the event Returns: 0 or 1
is_lead_changing_goal
-
Tests if the goal changes the lead in the game
Arguments: the current score the scoring team index (0 or 1) Returns: 0 or 1
is_lead_swinging_goal
-
Tests if the goal swings the lead in the game
Arguments: the current score the scoring team index (0 or 1) the last leader in the game Returns: 0 or 1
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
is_noplay_event
-
Check if the event is not a played one (PEND, GEND, PSTR, STOP)
set_player_stat
-
A testing helper that sets the player stats the way they seem to appear in the event summary rather than in the boxscore, or finds a way to arbitrate the discrepancies.
Arguments: * The boxscore * The NHL id of the player being fixed * The stat to fix * The value of the stat in the event summary * The possible arbitration delta
Returns: void. The boxscore is updated.
fix_playergoals
-
Fixes the number of goals and assists for players in the boxscore as shown by the summary.
Arguments: * The boxscore * The index of the team of the player (0 - away, 1 - home) * The event summary
Returns: void. Boxscore is modified.
print_events
-
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:
RT: CPAN's request tracker (report bugs here)
https://rt.cpan.org/NoAuth/Bugs.html?Dist=Sport::Analytics::NHL::Tools
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN