Index: trunk/ippToPsps/perl/exposureSummary.pl
===================================================================
--- trunk/ippToPsps/perl/exposureSummary.pl	(revision 29989)
+++ trunk/ippToPsps/perl/exposureSummary.pl	(revision 29989)
@@ -0,0 +1,209 @@
+#!/usr/bin/env perl
+
+# script to provide a summary of loading status given an upper and lower exposure ID limit
+
+use warnings;
+use strict;
+
+use LWP::UserAgent;
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use File::Temp qw(tempfile);
+use ippToPsps::IppToPspsDb;
+use ippToPsps::Gpc1Db;
+use ippToPsps::Batch;
+
+my $dvoDb = undef;
+my $beginExp = undef;
+my $endExp = undef;
+my $verbose = undef;
+my $save_temps = undef;
+
+GetOptions(
+        'startexp|b=s' => \$beginExp,
+        'endexpi|e=s' => \$endExp,
+        'dvodb|d=s' => \$dvoDb,
+        'verbose|v' => \$verbose,
+        'save_temps|s' => \$save_temps
+        );
+
+
+my $quit = 0;
+print "\n*******************************************************************************\n";
+print "* \n";
+if (@ARGV) {
+    $quit=1;
+    print "* UNKNKOWN: option                          @ARGV\n";
+}
+if (!defined $beginExp) {
+    $quit = 1;
+    print "* REQUIRED: a begin exp_id                  -b <name>\n";
+}
+if (!defined $endExp) {
+    $quit = 1;
+    print "* REQUIRED: an end exp_id                   -e <name>\n";
+}
+if (!defined $dvoDb) {
+    $quit = 1;
+    print "* REQUIRED: a dvo Db name                   -d <name>\n";
+}
+if (!defined $verbose) {
+    $verbose = 0;
+    print "* OPTIONAL: run in verbose mode             -v                   (default = $verbose)\n";
+}
+if (!defined $save_temps) {
+    $save_temps = 0;
+    print "* OPTIONAL: keep temp files                 -t                   (default = $save_temps)\n";
+}
+print "*\n*******************************************************************************\n";
+
+if ($quit) { exit; }
+
+my $gpc1Db = new ippToPsps::Gpc1Db("gpc1", "ippdb01", "ippuser", "ippuser", $verbose, $save_temps);
+my $ippToPspsDb = new ippToPsps::IppToPspsDb("ippToPsps", "ippdb01", "ipp", "ipp", $verbose, $save_temps);
+
+my $exposures;
+#if (!$gpc1Db->getExposureListFromDvoDb($dvoDb, \$exposures, 0)) {exit;}
+
+my $totalExposures = $ippToPspsDb->countExposures($beginExp, $endExp, "PSPS_test", "P2", $dvoDb);
+my $totalMerged = $ippToPspsDb->countMergedExposures($beginExp, $endExp, "PSPS_test", "P2", $dvoDb);
+
+if(!$ippToPspsDb->getUnmergedExposures(\$exposures, $beginExp, $endExp, "PSPS_test", "P2", $dvoDb)) {
+
+    print "No unmerged exposures\n";
+    exit;
+}
+
+my $exposure;
+my $totalUnmerged = 0;
+my $totalMergeWorthy = 0;
+my $totalProcessed = 0;
+my $totalOnDatastore = 0;
+my $totalLoadedToOdm = 0;
+my $totalLoadFailed = 0;
+my $totalUnderObjIdLimit = 0;
+my @unprocessedExposures;
+my @odmFailures;
+
+foreach $exposure ( @{$exposures} ) {
+    my ($expId) = @{$exposure};
+
+    if ($ippToPspsDb->isExposureMerged($expId)) {next;}
+
+    $totalUnmerged++;
+    if ($verbose) {print "$totalUnmerged | $expId \n"; }
+
+    if ($ippToPspsDb->isExposureProcessed($expId)) {
+
+        $totalProcessed++;
+
+        if ($ippToPspsDb->isExposureAlreadyPublished($expId)) {
+
+            $totalOnDatastore++;
+
+            if ($ippToPspsDb->isExposureLoadedToOdm($expId)) {
+
+                $totalLoadedToOdm++;
+
+                if ($ippToPspsDb->didLoadFail($expId)) {
+
+                    $totalLoadFailed++;
+                }
+                if ($ippToPspsDb->isMinObjIdUnderLimit($expId)) {
+
+                    $totalUnderObjIdLimit++;
+                }
+                else {
+                
+                    push(@odmFailures, $expId);
+                }
+            }
+        }
+    }
+    else {
+
+        push(@unprocessedExposures, $expId);
+    }
+}
+
+my $totalUnprocessed = @unprocessedExposures;
+my $totalOdmFailures = @odmFailures;
+my $totalProcessedNotOnDatastore = $totalProcessed - $totalOnDatastore;
+my $totalOnDatastoreNotLoaded = $totalOnDatastore - $totalLoadedToOdm;
+print "***********************************************************\n";
+print "* Summary of IPP->PSPS loading from the '$dvoDb' DVO database for exposures between $beginExp and $endExp:\n";
+print "*\n";
+print "* total Exposures                            = $totalExposures\n";
+print "*   merged into PSPS                         = $totalMerged\n";
+print "*   un-merged                                = $totalUnmerged\n";
+print "*     unprocessed by ippToPsps               = $totalUnprocessed\n";
+print "*     processed by ippToPsps                 = $totalProcessed\n";
+print "*       not on datastore                     = $totalProcessedNotOnDatastore\n";
+print "*       on datastore                         = $totalOnDatastore\n";
+print "*         not loaded to ODM                  = $totalOnDatastoreNotLoaded\n";
+print "*         loaded to ODM but rejected         = $totalLoadedToOdm\n";
+print "*           under -30 dec limit              = $totalUnderObjIdLimit\n";
+print "*           remaining ODM failures           = $totalOdmFailures\n";
+print "*\n";
+print "***********************************************************\n";
+
+my $gnuplotDat = "gnuplot.dat";
+open (FILE, ">$gnuplotDat") or print "* Problem opening data file for gnuplot\n";
+
+print FILE "totalExposures $totalExposures";
+print FILE "mergedintoPSPS $totalMerged\n";
+print FILE "un-merged  $totalUnmerged\n";
+print FILE "unprocessedbyippToPsps  $totalUnprocessed\n";
+print FILE "processedbyippToPsps $totalProcessed\n";
+print FILE "notondatastore   $totalProcessedNotOnDatastore\n";
+print FILE "ondatastore       $totalOnDatastore\n";
+print FILE "notloadedtoODM    $totalOnDatastoreNotLoaded\n";
+print FILE "loadedtoODMbutrejected  $totalLoadedToOdm\n";
+print FILE "ODMfailures             $totalLoadFailed\n";
+print FILE "under-30declimit        $totalUnderObjIdLimit\n";
+print FILE "remainingODMfailures     $totalOdmFailures\n";
+close (FILE);
+
+
+# save list of unprocessed exposures to file
+open (FILE, ">unprocessedExposures.txt") or print "* Problem opening data file for unprocessed exposures\n";
+foreach my $exp_id (@unprocessedExposures) {
+
+    print FILE "$exp_id\n";
+}
+close (FILE);
+
+# save list of ODM failed exposures to file
+open (FILE, ">odmFailures.txt") or print "* Problem opening data file for ODM failures\n";
+foreach my $exp_id (@odmFailures) {
+
+    print FILE "$exp_id\n";
+}
+close (FILE);
+
+
+sub plot {
+
+    open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
+    use FileHandle;
+    GP->autoflush(1);
+
+    print GP
+        #"set term png font \"/usr/share/fonts/corefonts/arial.ttf\" 8;" .
+        "set term X11;" .
+        "set output \"summary.png\";" .
+        "set title \"Summary of IPP->PSPS loading from the '$dvoDb' DVO database\nfor exposures between $beginExp and $endExp\";" .
+        "set grid;" .
+        "set boxwidth;" .
+        "set style data histogram;" .
+        "set style fill solid border -1;" .
+        "set ylabel \"Exposures\";" .
+        "set boxwidth 0.75;" .
+        "plot '$gnuplotDat' using 2:xtic(1) notitle, '' using 3 notitle, '' using 4 notitle;" .
+        "\n";
+
+    close GP;
+
+
+}
+
+
