#!/usr/bin/perl # AUTHORS # Hans Van Slooten # $Date: 2016-12-16 12:21:26 -0500 (Fri, 16 Dec 2016) $ # $Author: hvs $ # $Rev: 47257 $ # $HeadURL: http://svn.sports-reference.com/svn/br_repos/br/branches/2016-03-klecko/lib/SRlocal/Register/Batting.pm $ # Copyright 2000-2016, SPORTS REFERENCE, LLC All rights reserved. use Carp; use Encode qw(decode_utf8 encode_utf8); use FindBin '$Bin'; use Modern::Perl '2010'; use open qw(:std :utf8); use CGI::Fast ':standard'; # Include our local and global SR modules. use lib "$Bin/../lib"; use SR::Cache; use SR::Defaults; use SR::Statline; use SRlocal::Constants; use SRlocal::DB; use SRlocal::Defaults; use SRlocal::Formatting; use SRlocal::Register::Fetch; use SRlocal::Stats; use SRlocal::Templates; chomp($0); @ARGV = map { decode_utf8( $_, 1 ) } @ARGV; MAIN: { our $site_params_ref = get_site_params($Bin); our $dbh = get_site_db_connection($Bin); our $srtemplates = new SRlocal::Templates; $dbh->{mysql_auto_reconnect} = $TRUE; while ( my $q = new CGI::Fast ) { my $page_data = cache_get( 'register', 'index' ); ## Check to see if we got a result from the cache if ( _nemp($page_data) && !_empz( $q->param('bust_cache') ) ) { print $q->header( -type => 'text/html', -charset => 'utf-8', -SR_SRC => 'memcached' ); print $page_data; next; } my $page_title = 'Professional Baseball History'; my $model = { header => { page_url => $SITE_URL . '/register/', page_title => $page_title, page_description => 'The most complete history of professional baseball. MLB, MiLB, NLB, NPB, KBO, Cuba, …', }, inpage_title => $page_title, inpage_subhead => 'Majors, Minors, NLB, Japan, Korea, Cuba, …', class => 'forcelinear', content => [], }; $model = _register_search_section( $dbh, $srtemplates, $model ); $model = _register_minors_section( $dbh, $srtemplates, $model ); $model = _register_npb_section( $dbh, $model ); $model = _register_nlb_section( $dbh, $model ); $model = _register_kbo_section( $dbh, $model ); $model = _register_cns_section( $dbh, $model ); my $content = SRlocal::Register::register_data_note( srtemplates => $srtemplates, section => $TRUE ); ## Add the data source notes push @{ $model->{content} }, { id => 'register_data', header => 'About the Register Data', forcefull => $TRUE, text => $content, }; $page_data = $srtemplates->process( 'Local/RegisterHome.tt2', $model ); print $q->header( -type => 'text/html', -charset => 'utf-8', -SR_SRC => 'build' ); print $page_data; cache_set( 'register', 'index', $page_data ); } $dbh->disconnect; } =head2 _register_search_section =cut sub _register_search_section { my ( $dbh, $srtemplates, $model ) = @_; my $section = { id => 'register_search', header => 'Register Search', forcefull => $TRUE }; $section->{text} = $srtemplates->process( 'General/Search.tt2', { placeholder => ' ', search_index => 'register_players' } ); push @{ $model->{content} }, $section; return $model; } =head2 _register_minors_section =cut sub _register_minors_section { my ( $dbh, $srtemplates, $model ) = @_; my $section = { id => 'minors', header => 'Minor Leagues', }; my $content = ''; ## Players my $query = <<"..."; select key_person, milbID, name_common, concat('/register/player.fcgi?id=', milbID) as player_link from sabr_ba_prospects prospects join register_people p using (milbID) where year = (select max(year) from sabr_ba_prospects) order by rank asc limit 10; ... my $sth = db_prepare_and_execute( $dbh, $query ); my @players; while ( my $row = $sth->fetchrow_hashref ) { push @players, qq{$row->{name_common}}; } push @players, qq{...}; my $players = join( ', ', @players ); $content .= <<"...";

Players

$players
... ## Years my $years = register_fetch_league_years( $dbh, { group => 'Minors' } ); my @years; my $last_year = 0; foreach my $year (@$years) { push @years, qq{}; $last_year = $year; } $years = join( "\n", @years ); $content .= <<"...";

Years:

... ## Affiliates $content .= <<"...";

Minor League Affiliates / $CURRENT_YEAR

Arizona Diamondbacks
Atlanta Braves
Baltimore Orioles
Boston Red Sox
Chicago Cubs
Chicago White Sox
Cincinnati Reds
Cleveland Indians
Colorado Rockies
Detroit Tigers
Houston Astros
Kansas City Royals
Los Angeles Angels of Anaheim
Los Angeles Dodgers
Miami Marlins
Milwaukee Brewers
Minnesota Twins
New York Mets
New York Yankees
Oakland Athletics
Philadelphia Phillies
Pittsburgh Pirates
San Diego Padres
San Francisco Giants
Seattle Mariners
St. Louis Cardinals
Tampa Bay Rays
Texas Rangers
Toronto Blue Jays
Washington Nationals
... # get leagues list and links. my $league_list = gtrc( $dbh, 'register_leagues', { year => $CURRENT_YEAR, classification => 'NOT:MLB' }, 'GROUP_CONCAT(CONCAT("/register/league.cgi?id=",key_league,":", name_full) order by name_full separator "::")' ); my @pages = split( '::', $league_list ); my $form_template .= SR::Defaults::output_goto_nav( { srtemplates => $srtemplates, fieldset_label => '', not_linear => $FALSE, select_array => [ { select_ref => \@pages, desc_option => qq{Choose a League ($CURRENT_YEAR)}, }, ], } ); ## Leagues $content .= <<"...";

Leagues

Pacific Coast League, Southern League, South Atlantic League, New York-Penn League, Gulf Coast League, Arizona Fall League, Frontier League, …
$form_template
... ## Teams $content .= <<"...";

Teams

1992 Greenville Braves, 1946 Montreal Royals, Buffalo Team History, …
... ## Leaders $content .= <<"...";

Leaders / $CURRENT_YEAR Pitching / $CURRENT_YEAR Batting

1938 AA Batting, 2009 Carolina Lg Doubles, 1962 HR, 2009 SO/9, …
... ## Bullpen Wiki $content .= <<"...";

Bullpen Wiki

Albuquerque Isotopes, Pacific Coast League, Contribute, …
... $section->{text} = $content; push @{ $model->{content} }, $section; return $model; } =head2 _register_npb_section =cut sub _register_npb_section { my ( $dbh, $model ) = @_; my $section = { id => 'npb', header => 'Japanese and Nippon Pro Baseball (NPB)', }; my $content = ''; my $years = register_fetch_league_years( $dbh, { league_type => 'Japan' } ); my @years; my $last_year = 0; my $first_year = 0; foreach my $year (@$years) { $last_year = $year if $last_year == 0; push @years, qq{}; $first_year = $year; } $years = join( "\n", @years ); my $total_years = $last_year - 1950 + 1; $content .= <<"...";

Players

Sadaharu Oh, Ichiro Suzuki, Charlie Manuel, Eiji Sawamura, High Schools for Japanese Major Leaguers, Players born in Japan, …

Japanese League History

Years:


Japan Central League
   (1950-$last_year, $total_years seasons)
Japan Pacific League
   (1950-$last_year, $total_years seasons)
Japanese Baseball League
   (1939-1949, 11 seasons)
Japanese Baseball League (Fall)
   (1936-1938, 3 seasons)
Japanese Baseball League (Spring)
   (1936-1938, 3 seasons)

Teams by Japanese Cities

Tokyo, JP (243 tms), Osaka, JP (154 tms), Nishinomiya, JP (102 tms), Nagoya, JP (86 tms), Fukuoka, JP (54 tms),

Bullpen Wiki

Japanese Baseball Content, Team Summaries, Player Bios, Managers, Team Summaries, Japan Series, No-Hitters, Posted Players, Black Mist Scandal, Contribute, …
... $section->{text} = $content; push @{ $model->{content} }, $section; return $model; } =head2 _register_nlb_section =cut sub _register_nlb_section { my ( $dbh, $model ) = @_; my $section = { id => 'nlb', header => 'Negro Leagues (NLB)', }; my $content = ''; my $years = register_fetch_league_years( $dbh, { group => 'NLB' } ); my @years; my $last_year = 0; my $first_year = 0; foreach my $year (@$years) { $last_year = $year if $last_year == 0; push @years, qq{}; $first_year = $year; } $years = join( "\n", @years ); $content .= <<"...";

Players

Satchel Paige, Buck O'Neil, Josh Gibson, Ray Brown, …

Years:

Teams

1932 Pittsburgh Crawfords, 1933 Homestead Grays, 1920 Chicago American Giants, 1924 Kansas City Monarchs, 1928 St. Louis Stars, Chicago Team History, …

Leaders

1938 Batting, 1921 Pitching, …

Bullpen Wiki

Season Summaries, Ballparks, Owners, Player Bios, 1946 Negro World Series, Contribute, …
... $section->{text} = $content; push @{ $model->{content} }, $section; return $model; } =head2 _register_kbo_section =cut sub _register_kbo_section { my ( $dbh, $model ) = @_; my $section = { id => 'kbo', header => 'Korean Baseball Organization (KBO)', }; my $years = register_fetch_league_years( $dbh, { code => 'KBO', class => 'Fgn' } ); my $last_year = 0; my $first_year = 0; foreach my $year (@$years) { $last_year = $year if $last_year == 0; $first_year = $year; } my $total_years = $last_year - $first_year + 1; my $content = <<"...";

Players

Seung-Yeop Lee, Min-Han Son, Byung-ho Park, …

KBO League

($first_year-$last_year, $total_years seasons)

Bullpen Wiki

South Korean Baseball Content
... $section->{text} = $content; push @{ $model->{content} }, $section; return $model; } =head2 _register_cns_section =cut sub _register_cns_section { my ( $dbh, $model ) = @_; my $section = { id => 'cns', header => 'Cuban National Series (CNS)', }; my $years = register_fetch_league_years( $dbh, { code => 'CNS', class => 'Fgn' } ); my $last_year = 0; my $first_year = 0; foreach my $year (@$years) { $last_year = $year if $last_year == 0; $first_year = $year; } my $total_years = $last_year - $first_year + 1; my $content = <<"...";

Players

Alfredo Despaigne, Frederich Cepeda, Yosvani Torres, …

Cuban National Series

($first_year-$last_year, $total_years seasons, note year given is start of season, so 2016 means 2016-17)

Bullpen Wiki

Cuban Baseball Content
... $section->{text} = $content; push @{ $model->{content} }, $section; return $model; }