Index: trunk/ippScripts/scripts/night_report.pl
===================================================================
--- trunk/ippScripts/scripts/night_report.pl	(revision 41371)
+++ trunk/ippScripts/scripts/night_report.pl	(revision 41459)
@@ -466,5 +466,5 @@
     }
     if ($summitSkipped || $summitPending) { 
-        print "*** WARNING: $summitSkipped skipped rawExp, $summitPending incomplete rawExp ***\n\n"; 
+        if ($verbose) {print "*** WARNING: $summitSkipped skipped rawExp, $summitPending incomplete rawExp ***\n\n";} 
 
         my $query = "SELECT summitExp.exp_name,exp_type, fault, state";
@@ -476,8 +476,8 @@
 
         my $result = &mysql_select ($query);
-        printf "%12s %8s %15s %6s\n", "exp_name", "exp_type", "fault", "state"; 
+        if ($verbose) {printf "%12s %8s %15s %6s\n", "exp_name", "exp_type", "fault", "state";} 
         while (@row = $result->fetchrow_array()) {
             if ($row[3] eq "") { $row[3] = "NULL"; }
-	    printf "%12s %8s %15s %6s\n", $row[0], $row[1], $row[2], $row[3]; 
+	    if ($verbose) {printf "%12s %8s %15s %6s\n", $row[0], $row[1], $row[2], $row[3];} 
         }
     }
@@ -512,4 +512,114 @@
 }
 
+# check the status of exposures:
+if (1) { 
+    if ($report) { print "Exposure overview:\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(*)";
+    $query .= " FROM rawExp";
+    $query .= " WHERE dateobs like '$date%'";
+    $query .= " AND exp_id > $refExpID"; # REF
+    $query .= " GROUP BY exp_type, obs_mode,cmt";
+    $query .= " ORDER BY exp_type, obs_mode";
+
+    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)"; }
+    while (@row = $result->fetchrow_array()) {
+        #query chip stage
+        my $query = "SELECT exp_type, obs_mode, chipRun.state, count(*)";
+        $query .= " FROM rawExp";
+        $query .= " JOIN chipRun using (exp_id)";
+        $query .= " WHERE dateobs LIKE '$date%'";
+        $query .= " AND exp_id > $refExpID"; #REF
+        $query .= " AND obs_mode LIKE '$row[1]'";
+	if ($row[2] ne "") {
+            $query .= " AND comment LIKE BINARY '$row[2]%'";
+        }    
+        my $result2 = &mysql_select ($query);
+        @row2 = $result2->fetchrow_array();
+
+        #query cam stage
+        my $query = "SELECT exp_type, obs_mode, camRun.state, count(*)";
+        $query .= " FROM rawExp join chipRun using (exp_id)";
+        $query .= " JOIN camRun using (chip_id)";
+        $query .= " WHERE dateobs LIKE '$date%'";
+        $query .= " AND exp_id > $refExpID"; #REF
+        $query .= " AND obs_mode LIKE '$row[1]'";
+	if ($row[2] ne "") {
+            $query .= " AND comment LIKE BINARY '$row[2]%'";
+        }    
+
+        my $result3 = &mysql_select ($query);
+        @row3 = $result3->fetchrow_array();
+
+        #query warp stage
+        my $query = "SELECT exp_type, obs_mode, warpRun.state, count(*)";
+        $query .= " FROM rawExp";
+        $query .= " JOIN chipRun using (exp_id)";
+        $query .= " JOIN camRun using (chip_id)";
+        $query .= " JOIN camProcessedExp using (cam_id)";
+        $query .= " JOIN fakeRun using (cam_id)";
+        $query .= " JOIN warpRun using (fake_id)";
+        $query .= " WHERE dateobs LIKE '$date%'";
+        $query .= " AND exp_id > $refExpID"; #REF
+        $query .= " AND obs_mode LIKE BINARY '$row[1]'";
+	if ($row[2] ne "") {
+            $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
+        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 fakeRun USING (fake_id)";
+        $query .= " JOIN camRun USING (cam_id)";
+        $query .= " JOIN camProcessedExp USING (cam_id)";
+        $query .= " JOIN chipRun USING (chip_id)";
+        $query .= " JOIN rawExp USING (exp_id)";
+        $query .= " WHERE rawExp.dateobs LIKE '$date%'";
+        $query .= " AND exp_id > $refExpID"; #REF
+        $query .= " AND obs_mode LIKE BINARY '$row[1]'";
+	if ($row[2] ne "") {
+            $query .= " AND comment LIKE '$row[2]%'";
+        }    
+        $query .= " GROUP BY diff_id";
+        my $result5 = &mysql_select ($query);
+
+        my $NWSdiffgood = 0;
+        my $NWSdiffbad = 0;
+        my $NWSdiffpub = 0;
+        my %wrpcnt = ();
+
+        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";
+                  my $result6 = &mysql_select ($query2);
+                  while (@row6 = $result6->fetchrow_array()) {
+                      #if all skycells have bad quality, this is a bad diff. If all the skycells are in a full state in publishRun, it is fully published 
+                      if ($row6[1]<$row6[0]) {$NWSdiffgood ++;}
+                      if ($row6[1]==$row6[0]) {$NWSdiffbad ++;}
+                      if ($row6[2]==$row6[0]) {$NWSdiffpub ++;}
+
+                      #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
+                  }
+              }
+        }
+        #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 ; }
+    }
+    print "\n";
+}
+
 # check the status of raw exposures:
 if (1) { 
@@ -540,4 +650,5 @@
     }
     if ($expSkipped || $expPending) { print "*** WARNING: $expSkipped skipped rawExp, $expPending incomplete rawExp ***\n\n"; } else { if ($verbose) { print "\n"; }}
+
 }
     
