#!/usr/bin/perl -w # AUTHORS # Sean Forman # Hans Van Slooten # $Date: 2017-02-17 16:37:30 -0500 (Fri, 17 Feb 2017) $ # $Author: sean $ # $Rev: 48802 $ # $HeadURL: http://svn.sports-reference.com/svn/br_repos/br/branches/2016-03-klecko/leagues/scripts/daily.fcgi $ # Copyright 2000-2017, SPORTS REFERENCE, LLC. All rights reserved. use Carp; use CGI; use FindBin qw($Bin); use Modern::Perl '2010'; # Include our local and global SR modules. use lib "$Bin/../lib"; use SR::Cache; use SR::Defaults; use SR::Formatting; use SR::Statline; use SRlocal::Constants; use SRlocal::DB; use SRlocal::Defaults; use SRlocal::Formatting; use SRlocal::Stats; use SRlocal::Templates; use SRlocal::Leagues; our $IP_per_game_qual = 0.5; our $PA_per_game_qual = 2.0; $STATLINE_DEFAULTS{inplay_gb_total}{header} = 'GB/FB'; chomp($0); #### [] Starting: "$Bin/$0 " . join(' ',@ARGV) MAIN: { # Connect to the database. our $dbh = get_site_db_connection($Bin); our $site_params_ref = get_site_params($Bin); our $srtemplates = new SRlocal::Templates; $site_params_ref->{serve_as_cgi_script} = $TRUE; ##################################################################################### ##################################################################################### # set up memcached and fastcgi $dbh->{mysql_auto_reconnect} = $TRUE; our $memd = get_memcached_connection($Bin); my $q = new CGI; # build a unique id for this page's data, and retrieve from # mysql or memcached if available. Print if it is returned, # build if not and then add to cache. my $memd_key = $ENV{'REQUEST_URI'}; my $page_data = SR::Cache::get_data_from_cache( { dbh => $dbh, memd => $memd, key => $memd_key } ); ################################################################### # check to see if we got a result from the cache ################################################################### if ( is_nonempty($page_data) && !is_empty_zero( $q->param('bust_cache') ) ) { print "SR-SRC: memcached\n"; print $q->header( -type => 'text/html', -charset => 'utf-8' ); print $page_data; exit; } else { print "SR-SRC: build\n"; } my $url = '/leagues/team_compare.cgi'; my $year = is_empty_zero( $q->param('year') ) || $CURRENT_YEAR; my $lg = is_empty_zero( $q->param('lg') ) || 'MLB'; $lg = ( $lg eq 'ML' ) ? 'MLB' : $lg; my $stat = is_nonempty( $q->param('stat') ) ? $q->param('stat') : 'WAA'; # see if the stat is in @BASE_STATS my $page_title = sprintf qq{%d %s Team Position Performance by %s}, $year, $lg eq 'ML' ? 'Major League' : $lg, is_nonempty( $STATLINE_DEFAULTS{$stat}{name} ) ? $STATLINE_DEFAULTS{$stat}{name} : ( grep( /^$stat$/, @SRlocal::Leagues::BASE_STATS ) ) ? $stat : 'a stat'; my @yah = ( qq{Seasons}, qq{$year Season}, qq{$page_title} ); my %model = ( header => { page_title => $page_title, you_are_here => generate_you_are_here( \@yah ), page_url => $SRlocal::Constants::SITE_URL . $url, page_description => 'Compare the teams across positions by a particular stat', qi_section => 'leagues', }, description => $page_title, ); my @pagecontent = (); push @pagecontent, SRlocal::Leagues::output_team_compare_form( $dbh, { year => $year, lg => $lg, stat => $stat } ); if ( $year < $SRlocal::Constants::FIRST_YEAR_RETRO && $SRlocal::Leagues::BASE_STATS{$stat} ) { my $callout = <<"END_HTML";
We apologize, but due to limitations in our play-by-play data, we can not produce these positional statistics prior to $SRlocal::Constants::FIRST_YEAR_RETRO.
END_HTML push @pagecontent, $callout; } else { push @pagecontent, SRlocal::Leagues::output_team_compare_table( $dbh, { year => is_nonempty_print( $q->param('year') ), lg => is_nonempty_print( $q->param('lg') ), title => $page_title, stat => is_nonempty_print( $q->param('stat') ), } ); } # put everything into a content section and put into pagecontent # for the model. We do this to prevent any ads popping up in # between our for and our output. push( @{ $model{pagecontent} }, output_content_section( { comment_by_default => $FALSE, section_content => join( "\n", @pagecontent ), section_label => 'Show Team Comparisons', suppress_header => $TRUE, } ) ); ## Output the file $page_data = $srtemplates->process( 'Pages/General.tt2', \%model ); ## Stuff the page into our cache. SR::Cache::put_data_in_cache( { dbh => $dbh, memd => $memd, key => $memd_key, data => $page_data, } ); print $q->header( -type => 'text/html', -charset => 'utf-8' ); print $page_data; $dbh->disconnect; }