package PaintGraphCited; # -------------------------------------------------------------------- # The copyright and all other proprietary rights in this Database # (including software - SEE LICENSING AGREEMENT) are the sole and # exclusive property of the Institute for Scientific Information # (ISI). This Database and source code, or any derivative works # thereof, are confidential and proprietary to ISI . Therefore, # duplication, reuse, redistribution, reverse assembling, reverse # compiling, or translation of the Database, source code, or any # portion thereof IS NOT PERMITTED. Consult Licensing Agreement. # -------------------------------------------------------------------- use strict; use Data::Dumper; use JCR::GraphCite; use ISIBench; use JCR::Journal; use JCR::Category; use Log::Log4perl qw(get_logger); use base qq(JCRPage); sub build_page { ISIBench::start(); my $logger = get_logger("PaintGraphCited"); my $self = shift; my $args = (ref $_[0] eq 'HASH') ? shift : { @_ }; #Get input parameters my $request = $self->{request}; my $j20 = $request->{'journal'}; my $cat = $request->{'category'}; my $journal_rank = $request->{'rank'}; $logger->debug("Args are : ", sub{Dumper($request)}); my($path,$results,$graph_filename,$category,$journal); my($title,$details,$jlist,$jall,$bself_cite,$cathash); my(%all_cites,%other_cites,%all_cites_impact,%other_cites_impact); # Get session object my $session = $self->{session}; # Get year & edition my $edition = $session->get( 'value' => 'edition' ); my $year = $session->get( 'value' => 'year' ); # Get Graph Object my $graph = JCR::GraphCite->new('year' => $year->{year}); # Check for Cache before hitting the database if ( $j20 ) { $path = qq{$CF::cache_directory/journals/$year->{year}/$edition->{edition}/$j20/Graphs}; $path =~ tr/ /_/; } elsif ( $cat ) { $path = qq{$CF::cache_directory/journals/$year->{year}/$edition->{edition}/$cat/Graphs}; $path =~ tr/ /_/; } $results = $graph->load( 'path' => $path, 'filename' => $CF::TDCitedCacheFilename, ) if ($CF::cache_cite_graph); # So could we load the cache+? if (! defined($results) ) { if ( $j20 ) { # No cache, so build the graph $logger->debug("Cited Journal Graph Built, not found in $path"); # Create Journal Object $journal = JCR::Journal->new( 'db' => $self->{db}, 'edition' => $edition->{edition}, 'year' => $year->{year}, ); unless (defined($journal) && (ref($journal) =~ /journal/i)) { $logger->error("Could not create journal object (#$journal)!"); ISIBench::stop(); return $journal; } # Verify that this journal actually exists - this is to stop invalid # blank graphs from being generated $title = $journal->get_journal_title('j20' => $j20); if (defined($title) && (ref($title) =~ /hash/i)) { unless (length($title->{'title'})) { $logger->error("Could not retrieve title for : $j20!"); ISIBench::stop(); return $title; } } # Get journal detail data $details = $journal->get_journal_data( 'j20' => $j20, 'mode' => 'brief', ); $logger->debug("Journal Detail Data is : ", sub{Dumper($details)}); # Get journal cited data (all and other (non self)) $jlist = $journal->get_journal_cite_cites( 'j20' => $j20, 'mode' => 'cited', ); $jall = $journal->get_journal_cites( 'j20' => $j20, 'mode' => 'cited', ); unless (defined($jlist) && (ref($jlist) =~ /array/i)) { $logger->error("Could not retrieve journal Cited list! (#$jlist)"); ISIBench::stop(); return 0; } if (ref($jall) =~ /hash/i) { $all_cites{'current_year'} = $jall->{current_year} || 0; $all_cites{'year_1'} = undef; $all_cites{'year_2'} = undef; $all_cites{'year_3'} = $jall->{year_3} || 0; $all_cites{'year_4'} = $jall->{year_4} || 0; $all_cites{'year_5'} = $jall->{year_5} || 0; $all_cites{'year_6'} = $jall->{year_6} || 0; $all_cites{'year_7'} = $jall->{year_7} || 0; $all_cites{'year_8'} = $jall->{year_8} || 0; $all_cites{'year_9'} = $jall->{year_9} || 0; $all_cites_impact{'current_year'} = undef; $all_cites_impact{'year_1'} = $jall->{year_1} || 0; $all_cites_impact{'year_2'} = $jall->{year_2} || 0; $all_cites_impact{'year_3'} = undef; $all_cites_impact{'year_4'} = undef; $all_cites_impact{'year_5'} = undef; $all_cites_impact{'year_6'} = undef; $all_cites_impact{'year_7'} = undef; $all_cites_impact{'year_8'} = undef; $all_cites_impact{'year_9'} = undef; } $logger->debug("All Cite is : ", sub{Dumper(\%all_cites)}); # FF to the self cite record if it exists $bself_cite = 0; foreach my $rec (@$jlist) { if ( $rec->{journal} eq $j20 ) { # The 'Other Cites' calculation is = All Cites - Self Cites $other_cites{'current_year'} = ($all_cites{current_year} - $rec->{current_year}) || 0; $other_cites{'year_1'} = undef; $other_cites{'year_2'} = undef; $other_cites{'year_3'} = ($all_cites{year_3} - $rec->{year_3}) || 0; $other_cites{'year_4'} = ($all_cites{year_4} - $rec->{year_4}) || 0; $other_cites{'year_5'} = ($all_cites{year_5} - $rec->{year_5}) || 0; $other_cites{'year_6'} = ($all_cites{year_6} - $rec->{year_6}) || 0; $other_cites{'year_7'} = ($all_cites{year_7} - $rec->{year_7}) || 0; $other_cites{'year_8'} = ($all_cites{year_8} - $rec->{year_8}) || 0; $other_cites{'year_9'} = ($all_cites{year_9} - $rec->{year_9}) || 0; $other_cites_impact{'current_year'} = undef; $other_cites_impact{'year_1'} = ($all_cites_impact{year_1} - $rec->{year_1}) || 0; $other_cites_impact{'year_2'} = ($all_cites_impact{year_2} - $rec->{year_2}) || 0; $other_cites_impact{'year_3'} = undef; $other_cites_impact{'year_4'} = undef; $other_cites_impact{'year_5'} = undef; $other_cites_impact{'year_6'} = undef; $other_cites_impact{'year_7'} = undef; $other_cites_impact{'year_8'} = undef; $other_cites_impact{'year_9'} = undef; # Flag that we found a self cite $bself_cite = 1; last; } } # Did we find a self cite? unless ($bself_cite) { # Well, there are no self cites, so the other cites are the same as the all cites $other_cites{'current_year'} = $all_cites{current_year} || 0; $other_cites{'year_1'} = undef; $other_cites{'year_2'} = undef; $other_cites{'year_3'} = $all_cites{year_3} || 0; $other_cites{'year_4'} = $all_cites{year_4} || 0; $other_cites{'year_5'} = $all_cites{year_5} || 0; $other_cites{'year_6'} = $all_cites{year_6} || 0; $other_cites{'year_7'} = $all_cites{year_7} || 0; $other_cites{'year_8'} = $all_cites{year_8} || 0; $other_cites{'year_9'} = $all_cites{year_9} || 0; $other_cites_impact{'current_year'} = undef; $other_cites_impact{'year_1'} = $all_cites_impact{year_1} || 0; $other_cites_impact{'year_2'} = $all_cites_impact{year_2} || 0; $other_cites_impact{'year_3'} = undef; $other_cites_impact{'year_4'} = undef; $other_cites_impact{'year_5'} = undef; $other_cites_impact{'year_6'} = undef; $other_cites_impact{'year_7'} = undef; $other_cites_impact{'year_8'} = undef; $other_cites_impact{'year_9'} = undef; } $logger->debug("Other Cite is : ", sub{Dumper(\%other_cites)}); $results = $graph->build( 'title' => '', 'pad' => $CF::TDCiteGraphPad, 'type' => 'cited', 'half_life' => $details->{'cited_hlife'}, 'all_cites' => \%all_cites, 'other_cites' => \%other_cites, 'all_cites_impact' => \%all_cites_impact, 'other_cites_impact' => \%other_cites_impact, 'graph_type' => 'journal', ); } elsif ( $cat ) { # No cache, so build the graph $logger->debug("Cited Subject Category Graph Built, not found in $path"); # Get the category list from the database $category = JCR::Category->new( 'db' => $self->{db}, 'edition' => $edition->{edition}, 'year' => $year->{year}, ); unless (defined($category) && (ref($category) =~ /category/i)) { $logger->error("Could not create category object (#$category)!"); ISIBench::stop(); return $cat; } # Verify that this subject category actually exists - this is to stop invalid # blank graphs from being generated # Get category subject by name $jlist = $category->get_category_cite_cites( 'subject' => $cathash, 'mode' => 'cited', ); $cathash = $category->get_category_by_name( 'name' => $cat, 'order_by' => 'name', ); unless (defined($jlist) && (ref($jlist) =~ /array/i)) { $logger->error("Could not retrieve subject category Cited list! (#$jlist)"); ISIBench::stop(); return 0; } if (defined($cathash)) { unless (length($cathash)) { $logger->error("Could not retrieve Subject for : $cat!"); ISIBench::stop(); return $cathash; } } $title->{title} = $cat; $logger->debug("Cat Hash : ", sub{Dumper($cathash)}); # Get subject category detail data $details = $category->get_category_data( 'subject' => $cathash, 'mode' => 'brief', ); $logger->debug("Subject Category Detail Data is : ", sub{Dumper($details)}); # Get subject category cited data (all and other (non self)) $jall = $category->get_category_cites( 'subject' => $cathash, 'mode' => 'cited', ); if (ref($jall) =~ /hash/i) { $all_cites{'current_year'} = $jall->{current_year} || 0; $all_cites{'year_1'} = undef; $all_cites{'year_2'} = undef; $all_cites{'year_3'} = $jall->{year_3} || 0; $all_cites{'year_4'} = $jall->{year_4} || 0; $all_cites{'year_5'} = $jall->{year_5} || 0; $all_cites{'year_6'} = $jall->{year_6} || 0; $all_cites{'year_7'} = $jall->{year_7} || 0; $all_cites{'year_8'} = $jall->{year_8} || 0; $all_cites{'year_9'} = $jall->{year_9} || 0; $all_cites_impact{'current_year'} = undef; $all_cites_impact{'year_1'} = $jall->{year_1} || 0; $all_cites_impact{'year_2'} = $jall->{year_2} || 0; $all_cites_impact{'year_3'} = undef; $all_cites_impact{'year_4'} = undef; $all_cites_impact{'year_5'} = undef; $all_cites_impact{'year_6'} = undef; $all_cites_impact{'year_7'} = undef; $all_cites_impact{'year_8'} = undef; $all_cites_impact{'year_9'} = undef; } $logger->debug("All Cite is : ", sub{Dumper(\%all_cites)}); # FF to the self cite record if it exists $bself_cite = 0; foreach my $rec (@$jlist) { if ( $rec->{journal} eq $j20 ) { # The 'Other Cites' calculation is = All Cites - Self Cites $other_cites{'current_year'} = ($all_cites{current_year} - $rec->{current_year}) || 0; $other_cites{'year_1'} = undef; $other_cites{'year_2'} = undef; $other_cites{'year_3'} = ($all_cites{year_3} - $rec->{year_3}) || 0; $other_cites{'year_4'} = ($all_cites{year_4} - $rec->{year_4}) || 0; $other_cites{'year_5'} = ($all_cites{year_5} - $rec->{year_5}) || 0; $other_cites{'year_6'} = ($all_cites{year_6} - $rec->{year_6}) || 0; $other_cites{'year_7'} = ($all_cites{year_7} - $rec->{year_7}) || 0; $other_cites{'year_8'} = ($all_cites{year_8} - $rec->{year_8}) || 0; $other_cites{'year_9'} = ($all_cites{year_9} - $rec->{year_9}) || 0; $other_cites_impact{'current_year'} = undef; $other_cites_impact{'year_1'} = ($all_cites_impact{year_1} - $rec->{year_1}) || 0; $other_cites_impact{'year_2'} = ($all_cites_impact{year_2} - $rec->{year_2}) || 0; $other_cites_impact{'year_3'} = undef; $other_cites_impact{'year_4'} = undef; $other_cites_impact{'year_5'} = undef; $other_cites_impact{'year_6'} = undef; $other_cites_impact{'year_7'} = undef; $other_cites_impact{'year_8'} = undef; $other_cites_impact{'year_9'} = undef; # Flag that we found a self cite $bself_cite = 1; last; } } # Did we find a self cite? unless ($bself_cite) { # Well, there are no self cites, so the other cites are the same as the all cites $other_cites{'current_year'} = $all_cites{current_year} || 0; $other_cites{'year_1'} = undef; $other_cites{'year_2'} = undef; $other_cites{'year_3'} = $all_cites{year_3} || 0; $other_cites{'year_4'} = $all_cites{year_4} || 0; $other_cites{'year_5'} = $all_cites{year_5} || 0; $other_cites{'year_6'} = $all_cites{year_6} || 0; $other_cites{'year_7'} = $all_cites{year_7} || 0; $other_cites{'year_8'} = $all_cites{year_8} || 0; $other_cites{'year_9'} = $all_cites{year_9} || 0; $other_cites_impact{'current_year'} = undef; $other_cites_impact{'year_1'} = $all_cites_impact{year_1} || 0; $other_cites_impact{'year_2'} = $all_cites_impact{year_2} || 0; $other_cites_impact{'year_3'} = undef; $other_cites_impact{'year_4'} = undef; $other_cites_impact{'year_5'} = undef; $other_cites_impact{'year_6'} = undef; $other_cites_impact{'year_7'} = undef; $other_cites_impact{'year_8'} = undef; $other_cites_impact{'year_9'} = undef; } $logger->debug("Other Cite is : ", sub{Dumper(\%other_cites)}); $results = $graph->build( 'title' => '', 'pad' => $CF::TDCiteGraphPad, 'type' => 'cited', 'half_life' => $details->{'cited_hlife'}, 'all_cites' => \%all_cites, 'other_cites' => \%other_cites, 'all_cites_impact' => \%all_cites_impact, 'other_cites_impact' => \%other_cites_impact, 'graph_type' => 'category', ); } # Save Cited Journal graph in cache $graph->save( 'path' => $path, 'filename' => $CF::TDCitedCacheFilename, ) if ($CF::cache_cite_graph); } else { $logger->debug("Cited Journal Graph Loaded from: $path"); } $self->set_header( 'name' => 'Expires', 'value' => 'Thu, 01 Jan 1970 00:00:01 GMT', ); $self->set_header( 'name' => 'Cache-Control', 'value' => 'no-cache', ); $self->set_header( 'name' => 'Pragma', 'value' => 'no-cache', ); $self->set_header( 'name' => 'Content-type', 'value' => 'image/jpeg', ); $self->{CONTENT} = $results->{'data'}; ISIBench::stop(); return 0; } # Overriding Page.pm's get_content method since we don't use a template for this output sub get_content { my $self = shift; return $self->{CONTENT}; } 1;