Index: trunk/tools/czartool/Plotter.pm
===================================================================
--- trunk/tools/czartool/Plotter.pm	(revision 29802)
+++ trunk/tools/czartool/Plotter.pm	(revision 29864)
@@ -1,3 +1,4 @@
 #!/usr/bin/perl -w
+
 package czartool::Plotter;
 
@@ -56,5 +57,4 @@
 }
 
-
 ###########################################################################
 #
@@ -67,10 +67,9 @@
 
     my $timeDiff = $self->{_czarDb}->diffTimes($end, $begin);
-
 
     if ($self->{_czarDb}->isBefore($timeDiff, "00:00:01")) {return 0;}
     elsif ($self->{_czarDb}->isBefore($timeDiff, "03:00:00")) {${$interval} = "15 MINUTE";}
     elsif ($self->{_czarDb}->isBefore($timeDiff, "10:00:00")) {${$interval} = "30 MINUTE";}
-    elsif ($self->{_czarDb}->isBefore($timeDiff, "24:00:00")) {${$interval} = "1 HOUR";} # under 1 day
+    elsif ($self->{_czarDb}->isBefore($timeDiff, "26:00:00")) {${$interval} = "1 HOUR";} # under 1 day
     elsif ($self->{_czarDb}->isBefore($timeDiff, "36:00:00")) {${$interval} = "2 HOUR";} # under 1.5 days
     elsif ($self->{_czarDb}->isBefore($timeDiff, "48:00:00")) {${$interval} = "3 HOUR";} # under 2 days
@@ -83,4 +82,6 @@
     else {${$interval} = "1 MONTH";}
 
+# ${$interval} = "2 HOUR";
+
     return 1;
 }
@@ -92,5 +93,5 @@
 ###########################################################################
 sub createRateTimeSeries {
-    my ($self, $label, $selectedStage, $beginTime, $endTime, $interval, $isLog) = @_;
+    my ($self, $label, $selectedStage, $beginTime, $endTime, $interval) = @_;
 
     # stages
@@ -109,5 +110,5 @@
     my $stage = undef;
     my $gnuplotFile = undef;
-    my $outputFile = createImageFileName($self, $label, $selectedStage, "r", $isLog);
+    my $outputFile = createImageFileName($self, $label, $selectedStage, "r", 0);
     open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
     use FileHandle;
@@ -118,5 +119,5 @@
     print GP
         "set term $self->{_outputFormat};" .
-        "set title \"'$label', '$selectedStage' during '$beginTime' to '$endTime'\";" .
+        "set title \"'$label', '$selectedStage'\\nFrom '$beginTime' to '$endTime' HST\";" .
         "set boxwidth;" .
         "set xtic rotate by -90 scale 0;" .
@@ -137,6 +138,5 @@
                     $endTime, 
                     $interval,
-                    \$gnuplotFile,
-                    $isLog)) {
+                    \$gnuplotFile)) {
 
             $gnuplotFiles{$stage} = $gnuplotFile;
@@ -251,5 +251,5 @@
                 \$faults)) {next;}
 
-        $pendingMinusFaults = $pending - $faults;
+        $pendingMinusFaults = $pending - $faults; 
         print GNUDAT "$stage $faults $processed $pendingMinusFaults\n";
     }
@@ -264,5 +264,5 @@
     print GP
         "set term $self->{_outputFormat};" .
-        "set title \"'$label', '$beginTime' to '$endTime'\";" .
+        "set title \"'$label'\\nFrom '$beginTime' to '$endTime' HST\";" .
         "set grid;" .
         "set boxwidth;" .
@@ -379,5 +379,5 @@
     my $yTitle = undef;
     if ($isLog) {$yTitle = "Log( Exposures )";}
-    elsif ($isDeriv) {$yTitle = "dExposures/dTime";}
+    elsif ($isDeriv) {$yTitle = "dExposures/dTime(secs)";}
     else {$yTitle = "Exposures";}
 
@@ -392,5 +392,5 @@
     else {$title .= "'all stages'"}
 
-    $title .= " for '$label', '$fromTime' to '$toTime'";
+    $title .= " for '$label'\\nFrom '$fromTime' to '$toTime' HST";
 
     open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
@@ -454,5 +454,5 @@
 
     my $tmpFile = File::Temp->new( TEMPLATE => "czarplot_gnuplot_storage_timeseries.XXXXX", DIR => '/tmp', SUFFIX => 'dat');
-    $self->{_czarDb}->createStorageTimeSeriesData($tmpFile, $fromTime, $toTime, \$minX, \$maxX, \$minY, \$maxY, \$timeDiff);
+    if (!$self->{_czarDb}->createStorageTimeSeriesData($tmpFile, $fromTime, $toTime, \$minX, \$maxX, \$minY, \$maxY, \$timeDiff)) {return 0;}
 
     my $timeFormat = undef;
@@ -468,5 +468,5 @@
     print GP
         "set term $self->{_outputFormat};" .
-        "set title \"Total available cluster space over time\";" .
+        "set title \"Total available cluster space over time\\nFrom $fromTime to $toTime HST\";" .
         "set key left top;" .
         "set xdata time;" .
@@ -482,4 +482,6 @@
     print GP "\n";
     close GP;
+
+    return 1;
 }
 
@@ -530,5 +532,5 @@
 ###########################################################################
 #
-# Generates 3D plot of magic mask fraction for provided exposure ID
+# Generates 2D plot of magic mask fraction for provided exposure ID
 #
 ###########################################################################
@@ -546,4 +548,5 @@
     open (GNUDAT, ">".$tmpFile->filename);
 
+    # missing corner chip
     print GNUDAT "0 0 0.0\n";
     foreach my $row ( @{$fracs} ) {
@@ -551,8 +554,10 @@
         if (@{$row}[0] =~ m/XY([0-9])([0-9])/) {
             print GNUDAT "$1 $2 @{$row}[1]\n";
+            # missing corner chips
             if($1 == 0 && $2 == 6) {print GNUDAT "0 7 0.0\n";}
             if($1 == 6 && $2 == 7) {print GNUDAT "7 0 0.0\n";}
         }
     }
+    # missing corner chip
     print GNUDAT "7 7 0.0\n";
 
@@ -596,5 +601,5 @@
 #
 ###########################################################################
-sub plotMagicMaskFractionHistogram {
+sub plotMagicMaskFraction {
     my ($self, $begin, $end) = @_;
 
@@ -623,16 +628,28 @@
     }
 
+    my $meanMask = undef;
+    my $sumMask = undef;
+    my $chipCount = undef;
+    my $expCount = 0;
+    my $totalChipCount = 0;
+    my $totalMask = 0;
+    my $exp_id = undef;
+
     # get mask for each exposure, and bin
-    my $mask = undef;
-    my $expCount = 0;
     foreach my $row ( @{$exp_ids} ) {
 
-        $mask = $self->{_gpc1Db}->getAverageMagicMaskFraction(@{$row}[0]);
-
-        if (!$mask) {next;}
+        $exp_id = @{$row}[0];
+
+        if (!$self->{_gpc1Db}->getMagicMaskStats($exp_id, \$meanMask, \$sumMask, \$chipCount )) {next;}
+
+
+        if (!$meanMask) {next;}
+        #print "expId=$exp_id meanMask=$meanMask sumMask=$sumMask nChips=$chipCount\n";
         $expCount++;
+        $totalMask += $sumMask;
+        $totalChipCount += $chipCount;
 
         foreach my $bin (@bins) {
-            if ($mask <= ($bin+$interval)) {
+            if ($meanMask <= ($bin+$interval)) {
 
                 $histogram{$bin}++;
@@ -640,4 +657,15 @@
             }
         }
+    }
+
+    my $totalMaskFrac;
+    
+    if ($totalChipCount > 0) {
+
+        $totalMaskFrac = sprintf( "%.1f", ($totalMask/$totalChipCount) * 100.0);
+    }
+    else {
+
+        $totalMaskFrac = "NA";
     }
 
@@ -655,16 +683,18 @@
     close(GNUDAT);
 
-    # now plot
+
+    $maxBin = $maxBin * 1.1;
+    $accum = $accum * 1.1;
+
+    my $title = "Magic Mask Fraction for $expCount exposures\\nData taken between '$begin' and '$end'\\nTotal masked fraction is $totalMaskFrac%";
+
+    # make histogram
     open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
     use FileHandle;
     GP->autoflush(1);
-
-    $maxBin = $maxBin * 1.1;
-    $accum = $accum * 1.1;
-
     if ($self->{_outputFormat} ne "X11") {print GP "set output \"$histoOutputFile\";";}
     print GP
         "set term $self->{_outputFormat};" .
-        "set title \"Magic mask fraction for $expCount exposures between '$begin' and '$end'\";" .
+        "set title \"$title\";" .
         "set grid;" .
         "set boxwidth;" .
@@ -682,13 +712,12 @@
     close GP;
 
-
+    # make cumulative distribution
     open (GP, "|/usr/bin/gnuplot -persist") or die "no gnuplot";
     use FileHandle;
     GP->autoflush(1);
-
     if ($self->{_outputFormat} ne "X11") {print GP "set output \"$distOutputFile\";";}
     print GP
         "set term $self->{_outputFormat};" .
-        "set title \"Cumulative distribution of magic streaks per image between '$begin' and '$end'\";" .
+        "set title \"Cumulative distribution of $title\";" .
         "set yrange [0:$accum];" .
         "set key left top;" .
