Index: /trunk/ippScripts/scripts/night_report.pl
===================================================================
--- /trunk/ippScripts/scripts/night_report.pl	(revision 41459)
+++ /trunk/ippScripts/scripts/night_report.pl	(revision 41460)
@@ -514,5 +514,6 @@
 # check the status of exposures:
 if (1) { 
-    if ($report) { print "Exposure overview:\n"; }
+    if ($report) { print "General exposure overview:\n"; }
+    if ($report) { print "Distribution is split between clean=0/1 (fullbundles vs catalog)\n"; }
 
     my $query = "SELECT exp_type, obs_mode,(CASE WHEN position(' ' in comment)>1 THEN substr(comment, 1, position(' ' in comment)-1) WHEN position('.' in comment)>1 THEN substr(comment, 1, position('.' in comment)-1) ELSE comment END) as cmt, state, count(*)";
@@ -525,5 +526,5 @@
     my $result = &mysql_select ($query);
 
-    if ($report) { printf "%8s | %12s | %30s | %7s | %7s | %7s | %9s %9s | %9s %12s |\n", "exp_type", "obs_mode","comment", "N(raw)", "N(chip)", "N(cam)", "N(wrp)", "N(wrppub)", "N(wsdiff)", "N(wsdiffpub)"; }
+    if ($report) { printf "%8s | %12s | %30s | %7s | %7s | %7s | %9s %9s | %9s %13s |\n", "exp_type", "obs_mode","comment", "N(raw)", "N(chip)", "N(cam)", "N(wrp)", "N(wrpdist)", "N(WSdiff)", "N(WSdiffdist)"; }
     while (@row = $result->fetchrow_array()) {
         #query chip stage
@@ -544,4 +545,5 @@
         $query .= " FROM rawExp join chipRun using (exp_id)";
         $query .= " JOIN camRun using (chip_id)";
+        $query .= " JOIN camProcessedExp USING (cam_id)";
         $query .= " WHERE dateobs LIKE '$date%'";
         $query .= " AND exp_id > $refExpID"; #REF
@@ -550,4 +552,5 @@
             $query .= " AND comment LIKE BINARY '$row[2]%'";
         }    
+        $query .= " AND (camProcessedExp.quality IS NULL OR camProcessedExp.quality = 0)";
 
         my $result3 = &mysql_select ($query);
@@ -555,5 +558,5 @@
 
         #query warp stage
-        my $query = "SELECT exp_type, obs_mode, warpRun.state, count(*)";
+        my $query = "SELECT exp_type, obs_mode, warpRun.state, count(DISTINCT warpRun.warp_id) AS Nwarp,count(if(distRun.state LIKE 'full' and distRun.stage LIKE 'warp' and distRun.clean = 0,1,NULL)) AS Ndist0,count(if(distRun.state LIKE 'full' and distRun.stage LIKE 'warp' and distRun.clean = 1,1,NULL)) AS Ndist1";
         $query .= " FROM rawExp";
         $query .= " JOIN chipRun using (exp_id)";
@@ -562,4 +565,5 @@
         $query .= " JOIN fakeRun using (cam_id)";
         $query .= " JOIN warpRun using (fake_id)";
+        $query .= " LEFT JOIN distRun ON (warp_id = stage_id)";
         $query .= " WHERE dateobs LIKE '$date%'";
         $query .= " AND exp_id > $refExpID"; #REF
@@ -568,13 +572,11 @@
             $query .= " AND comment LIKE '$row[2]%'";
         }    
-        $query .= " AND (camProcessedExp.quality IS NULL OR camProcessedExp.quality = 0)";
-
         my $result4 = &mysql_select ($query);
         @row4 = $result4->fetchrow_array();
 
-        #query warp-stack diff stage and publish status
+        #query warp-stack diff stage and distribution status
         my $query = "SELECT diff_id,warp1,stack1,warp2,stack2";
         $query .= " FROM diffInputSkyfile";
-        $query .= " JOIN warpRun ON (warp1=warp_id OR warp2=warp_id)";
+        $query .= " JOIN warpRun ON warp1=warp_id";
         $query .= " JOIN fakeRun USING (fake_id)";
         $query .= " JOIN camRun USING (cam_id)";
@@ -582,6 +584,8 @@
         $query .= " JOIN chipRun USING (chip_id)";
         $query .= " JOIN rawExp USING (exp_id)";
+        #$query .= " LEFT JOIN distRun ON (diffRun.diff_id = stage_id)";
         $query .= " WHERE rawExp.dateobs LIKE '$date%'";
         $query .= " AND exp_id > $refExpID"; #REF
+        $query .= " AND stack2 > 0";
         $query .= " AND obs_mode LIKE BINARY '$row[1]'";
 	if ($row[2] ne "") {
@@ -590,16 +594,18 @@
         $query .= " GROUP BY diff_id";
         my $result5 = &mysql_select ($query);
+        #@row5 = $result5->fetchrow_array();
 
         my $NWSdiffgood = 0;
         my $NWSdiffbad = 0;
-        my $NWSdiffpub = 0;
-        my %wrpcnt = ();
+        my $NWSdiffdist0 = 0;
+        my $NWSdiffdist1 = 0;
+        my %dfcnt = ();
 
         while (@row5 = $result5->fetchrow_array()) {
               if ($row5[4] > 0) {
-                  #find the total number of skycell and the number of skycell with a bad quality flag as well as the full publish state 
-                  my $query2 = "     SELECT count(diffSkyfile.quality) AS Ndiff,count(if(diffSkyfile.quality > 0,1,NULL)) AS Ndiffbad,count(if(publishRun.state LIKE 'full',1,NULL)) AS Npub FROM ";
-                  $query2 .= "           diffRun JOIN diffSkyfile USING (diff_id) LEFT JOIN publishRun ON (diffRun.diff_id = stage_id)";
-                  $query2 .= "           WHERE diff_id='$row5[0]' GROUP BY diffRun.diff_id";
+                  #find the total number of skycell and the number of skycell with a bad quality flag as well as the full dist state 
+                  my $query2 = "SELECT count(DISTINCT diffSkyfile.skycell_id) AS Ndiff,count(if(diffSkyfile.quality > 0,1,NULL)) AS Ndiffbad,count(if(distRun.state LIKE 'full' and distRun.clean = 0,1,NULL)) AS Ndist0,count(if(distRun.state LIKE 'full' and distRun.clean = 1,1,NULL)) AS Ndist1 FROM ";
+                  $query2 .= " diffRun JOIN diffSkyfile USING (diff_id) LEFT JOIN distRun ON (diffRun.diff_id = stage_id)";
+                  $query2 .= " WHERE diff_id='$row5[0]' AND distRun.stage LIKE 'diff' GROUP BY diffRun.diff_id";
                   my $result6 = &mysql_select ($query2);
                   while (@row6 = $result6->fetchrow_array()) {
@@ -607,15 +613,16 @@
                       if ($row6[1]<$row6[0]) {$NWSdiffgood ++;}
                       if ($row6[1]==$row6[0]) {$NWSdiffbad ++;}
-                      if ($row6[2]==$row6[0]) {$NWSdiffpub ++;}
+                      if ($row6[2]==$row6[0]) {$NWSdiffdist0 ++;}
+                      if ($row6[3]==$row6[0]) {$NWSdiffdist1 ++;}
 
                       #if this wsdiff is published, record its corresponding warp_ids to see how many unique ones there are
-                      if ($row6[2]==$row6[0]) {$wrpcnt{$row5[1]}++;}  # record the presence of warp1
+                      $dfcnt{$row5[0]}++;  # record the presence of diff_id
                   }
               }
         }
         #pull out the unique warp_ids
-        $Npubwarps = keys %wrpcnt;
-
-	if ($report) { printf "%8s | %12s | %30s | %7d | %7d | %7d | %9d %9d | %9d %12d |\n", $row[0], $row[1], $row[2], $row[4], $row2[3], $row3[3], $row4[3],$Npubwarps,$NWSdiffgood,$NWSdiffpub ; }
+        $Ndiffs = keys %dfcnt;
+
+	if ($report) { printf "%8s | %12s | %30s | %7d | %7d | %7d | %9d %4d%1s%4d | %9d %6d%1s%6d |\n", $row[0], $row[1], $row[2], $row[4], $row2[3], $row3[3], $row4[3],$row4[4],'/',$row4[5],$Ndiffs,$NWSdiffdist0,'/',$NWSdiffdist1 ; }
     }
     print "\n";
