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

NAME

Sport::Analytics::NHL - Crawl data from NHL.com and put it into a database

VERSION

Version 1.53

SYNOPSIS

Crawl data from NHL.com and put it into a database.

Crawls the NHL.com website, processes the game reports and stores them into a Mongo database or into the filesystem.

    use Sport::Analytics::NHL;

    my $nhl = Sport::Analytics::NHL->new();
    $nhl->scrape_games();
    ...
    # more functionality to be added in later releases.

EXPORT

hdb_version() - report the version. All the other interface is OOP via the new() constructor.

METHODS

hdb_version

Returns the current version of the package

new

Returns a new Sport::Analytics::NHL object. If a Mongo DB is configured, the connection to the database is established, and the handle is stored in the object.

parse_game_args
 Parses various game arguments to the scrape_games() method:
 * NHL IDs of format SSSS0TIIII (2016020201)
 * Our IDs of format SSSSTIIII  (201620201)
 * Dates in format YYYYMMDD (20160202)

 where S stands for starting year of season, T - stage (2 - regular, 3 - playoffs), I - the ID of the game within the year.

Modifies the games array reference passed as the first argument, and dates array reference passed as the second argument, using the list of number strings as the remaining list of arguments.

get_crawled_games_for_dates

Gets a list of already crawled games on given list of dates. Crawls the season schedule on the NHL website if necessary. Arguments: the options to pass to the scraper that crawls and the list of the dates. Returns: the list of game structures which are hash references with the following fields: * season * stage * season id * Our game ID (see the previous section)

get_nodb_scheduled_games
 Gets a list of scheduled, uncrawled games in the filesystem, based on the schedules already stored in, or crawled into the system.
 Argument: options hashref that specifies whether new schedules should be crawled, and only specific stage should be filtered.
 Returns: the list of game structures which are hash references with the following fields:
 * season
 * stage
 * season id
 * Our game ID (see the previous section)
get_db_scheduled_games
 Same as the previous method, but the information is extracted from the Mongo database rather than the filesystem.
get_scheduled_games
 The generic wrapper for the two previous methods.
scrape_games
 Scrape the games reports from the NHL website and store them in files on the disk.
 Arguments: the hashref of options for the scrape -
 * no_schedule_crawl - whether fresh schedule should be crawled
 * start_season - the first season to start scraping from (default 1917)
 * stop_season - the last season to scrape (default - ongoing)
 * stage - 2 for Regular, 3 for Playoffs, none for both (default - none)
 * force - override the already present files and data
compile_file

Compiles a single JSON or HTML report into a parsed hashref and stores it in a Storable file Arguments: * The options hashref - - force: Force overwrite of already existing file - test: Test the resulted parsed report * The file * Our SSSSTNNNN game id * Optional: preset type of the report

Returns: the path to the compiled file

compile

Compiles reports retrieved into the filesystem into parsed hashrefs and stores them in a Storable file. Arguments: * The options hashref - - force: Force overwrite of already existing file - test: Test the resulted parsed report - doc: limit compilation to these Report types - reports_dir: the root directory of the reports * The list of game ids

Returns: the location of the compiled storables

retrieve_compiled_report

Retrieves the compiled storable file for the given game ID and file type. Compiles the file anew unless explicitly prohibited from doing so.

Arguments: * The options hashref - - no_compile: don't compile files if required - recompile: force recompilation * game ID * doc type (e.g. BS, PL, RO, ...) * path to the storable file. The file is expected at location $path/$doc.storable

Returns: the file structure retrieved from storable, or undef.

merge

Merges reports compiled in the filesystem into one boxscore hashref and stores it in a Storable file.

Arguments: * The options hashref - - force: Force overwrite of already existing file - test: Test the resulted parsed report - doc: limit compilation to these Report types - reports_dir: the root directory of the reports - no_compile: don't compile files if required - recompile: force recompilation * The list of game ids

Returns: the location of the merged storable

check_consistency

Checks the consistency between the summarized events and the summary data in the boxscore itself. If there are inconsistencies, the game files are recompiled and remerged and some fix If there are unfixable inconsistencies, the check dies.

Arguments: * The merged file (to manage the game files) * The boxscore to summarize * The produced summary of events

Returns: void. Dies if something goes wrong.

normalize

Normalizes the merged boxscore, providing default values and erasing unnecessary data from the boxscore data structure. Saves the normalized boxscore both as a Perl storable and as a JSON. This is the highest level of integration that this package provides without a database (Mongo) interface.

Arguments: * The options hashref - - force: Force overwrite of already existing file - test: Test the resulted parsed report - doc: limit compilation to these Report types - reports_dir: the root directory of the reports - no_compile: don't compile files if required - recompile: force recompilation - no_merge: don't merge files if required - remerge: force remerging * The list of game ids

Returns: the location of the normalized storable(s). The JSON would be in the same directory.

populate

Populates the Mongo DB from the normalized boxscores. Normalizes the boxscore if necessary and if requested.

Arguments: * The options hashref - - same options as normalize() (q.v.) plus: - no_normalize: don't normalize files if required - renormalize: force normalizing. * The list of the normalized game ids

Returns: the list of inserted game's ids.

check_series_end

Checks if the game ended a playoff series and adds the information about it throughout the series.

 Arguments: the boxscore

 Returns: void

 Caveat: Only applicable to Original Six and later eras.

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. 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

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2018 More Hockey Stats.

This program is released under the following license: gnu