IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41200 for trunk/ippScripts


Ignore:
Timestamp:
Dec 12, 2019, 11:34:42 AM (7 years ago)
Author:
tdeboer
Message:

add output of overridden exposures

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/night_report.pl

    r40972 r41200  
    7979    #We want to stick to only MOPS products, so we do labels %SS%, %EU% and %Bright.% (to avoid BrightTwi and Bright3PI which are not in quads)
    8080    #we need to do a subquery to find the total number of skycells in warpSkyfile, as well as the number of those with a bad quality
    81     my $query = "SELECT suba.chunk,suba.Nvis1,suba.Nvis2,suba.Nvis3,suba.Nvis4,suba.Ncamgood,suba.Ncambad,subb.Nwarpgood,subb.Nwarpbad FROM ";
     81    my $query = "SELECT suba.chunk,suba.Nvis1,suba.Nvis2,suba.Nvis3,suba.Nvis4,suba.Ncamgood,suba.Ncambad,subb.Nwarpgood,subb.Nwarpbad,suba.uniNvis1,suba.uniNvis2,suba.uniNvis3,suba.uniNvis4 FROM ";
    8282    $query .= "    (SELECT substr(comment, 1, position(' ' in comment)) AS chunk,count(if(rawExp.comment LIKE '%visit 1%',1,NULL)) AS Nvis1,";
    8383    $query .= "    count(if(rawExp.comment LIKE '%visit 2%',1,NULL)) AS Nvis2,count(if(rawExp.comment LIKE '%visit 3%',1,NULL)) AS Nvis3,";
    8484    $query .= "    count(if(rawExp.comment LIKE '%visit 4%',1,NULL)) AS Nvis4, count(if(camProcessedExp.sigma_ra <= 5 AND camProcessedExp.sigma_dec <= 5 AND camProcessedExp.quality = 0,1,NULL)) AS Ncamgood,";
    85     $query .= "    count(if(camProcessedExp.sigma_ra > 5 OR camProcessedExp.sigma_dec > 5 OR camProcessedExp.quality > 0,1,NULL)) AS Ncambad";
     85    $query .= "    count(if(camProcessedExp.sigma_ra > 5 OR camProcessedExp.sigma_dec > 5 OR camProcessedExp.quality > 0,1,NULL)) AS Ncambad, COUNT(DISTINCT CASE WHEN rawExp.comment LIKE '%visit 1%' THEN rawExp.comment END) AS uniNvis1,";
     86    $query .= "    COUNT(DISTINCT CASE WHEN rawExp.comment LIKE '%visit 2%' THEN rawExp.comment END) AS uniNvis2,COUNT(DISTINCT CASE WHEN rawExp.comment LIKE '%visit 3%' THEN rawExp.comment END) AS uniNvis3,";
     87    $query .= "    COUNT(DISTINCT CASE WHEN rawExp.comment LIKE '%visit 4%' THEN rawExp.comment END) AS uniNvis4";
    8688    $query .= "    FROM rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) JOIN camProcessedExp USING (cam_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id)";
    8789    $query .= "    WHERE dateobs like '$date%' AND exp_id > $refExpID";
     
    101103    my $result = &mysql_select ($query);
    102104
    103     printf "%18s | %11s | %4s | %4s | %7s | %4s | %7s | %4s | %7s |\n", "chunk", "Nobs", "Ncam","Nwrp","Nwrp_pub", "Nwwd", "Nwwd_pub", "Nwsd", "Nwsd_pub";
     105    printf "%30s | %11s | %4s | %4s | %7s | %4s | %7s | %4s | %7s |\n", "chunk", "Nobs", "Ncam","Nwrp","Nwrp_pub", "Nwwd", "Nwwd_pub", "Nwsd", "Nwsd_pub";
    104106    while (@row = $result->fetchrow_array()) {
    105107          my $Nvis1 = 0;
     
    114116          my $Npubwarps = 0;
    115117          my $uniwarps = undef;
     118          my $uniNvis1 = 0;
     119          my $uniNvis2 = 0;
     120          my $uniNvis3 = 0;
     121          my $uniNvis4 = 0;
    116122
    117123          my $chunkname = $row[0];
     
    124130          if($row[7] gt 0) {$Nwarpgood = $row[7]};
    125131          if($row[8] gt 0) {$Nwarpbad = $row[8]};
     132          if($row[9] gt 0) {$uniNvis1 = $row[9]};
     133          if($row[10] gt 0) {$uniNvis2 = $row[10]};
     134          if($row[11] gt 0) {$uniNvis3 = $row[11]};
     135          if($row[12] gt 0) {$uniNvis4 = $row[12]};
    126136
    127137          #set flags if present
    128138          if($Ncambad >= 1) {$badcamflag = 1};
    129139          if($Nwarpbad >= 1) {$badwarpflag = 1};
    130 
    131           #Find the total published number of unique warps for this chunk
    132           #my $query0 = "     SELECT count(DISTINCT warpRun.warp_id) FROM ";
    133           #$query0 .= "           diffInputSkyfile JOIN warpRun ON (warp1=warp_id OR warp2=warp_id) JOIN fakeRun USING (fake_id) JOIN camRun USING (cam_id) JOIN camProcessedExp USING (cam_id) JOIN chipRun USING (chip_id) JOIN rawExp USING (exp_id) JOIN publishRun ON (diffInputSkyfile.diff_id = stage_id)";
    134           #$query0 .= "           WHERE rawExp.dateobs LIKE '$date%' AND exp_id > $refExpID AND (camRun.label LIKE '%SS%' OR camRun.label LIKE '%EU%' OR camRun.label LIKE '%Bright.%')";
    135           #$query0 .= "            AND obs_mode NOT LIKE 'ENGINEERING' AND obs_mode NOT LIKE 'MANUAL' AND substr(comment, 1, position(' ' in comment)) LIKE '$chunkname%' group by warpRun.warp_id";
    136           #my $result0 = &mysql_select ($query0);
    137           #while (@row = $result0->fetchrow_array()) {$Npubwarps = $row[0];}
    138 
    139140
    140141          #Find the expected number of diffs for this chunk
     
    203204          if(($NWWdiffbad >= 1) or ($NWSdiffbad >= 1)) {$baddiffflag = 1;}
    204205
    205           if ($Nvis1 ne $Nvis4) {
    206             if ($NWWdiffpub ne $NexpWWdiff) {printf "%18s | %2s%1s%2s%1s%2s%1s%2s | %2s%1s%1s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %20s\n", $chunkname, $Nvis1, "/",$Nvis2, "/",$Nvis3, "/",$Nvis4,$Ncamgood, "/",$Ncambad,$Nwarpgood, "/",$Nwarpbad,$Npubwarps,$NWWdiffgood, "/",$NWWdiffbad,$NWWdiffpub,$NWSdiffgood, "/",$NWSdiffbad,$NWSdiffpub, "chunk incomplete, not done";} 
    207             if ($NWWdiffpub eq $NexpWWdiff) {printf "%18s | %2s%1s%2s%1s%2s%1s%2s | %2s%1s%1s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %20s\n", $chunkname, $Nvis1, "/",$Nvis2, "/",$Nvis3, "/",$Nvis4,$Ncamgood, "/",$Ncambad,$Nwarpgood, "/",$Nwarpbad,$Npubwarps,$NWWdiffgood, "/",$NWWdiffbad,$NWWdiffpub,$NWSdiffgood, "/",$NWSdiffbad,$NWSdiffpub, "chunk incomplete, done";}
     206          if (($uniNvis1 ne $uniNvis2) or ($uniNvis1 ne $uniNvis3) or ($uniNvis1 ne $uniNvis4)) {
     207            if ($NWWdiffpub ne $NexpWWdiff) {printf "%30s | %2s%1s%2s%1s%2s%1s%2s | %2s%1s%1s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %20s\n", $chunkname, $Nvis1, "/",$Nvis2, "/",$Nvis3, "/",$Nvis4,$Ncamgood, "/",$Ncambad,$Nwarpgood, "/",$Nwarpbad,$Npubwarps,$NWWdiffgood, "/",$NWWdiffbad,$NWWdiffpub,$NWSdiffgood, "/",$NWSdiffbad,$NWSdiffpub, "chunk incomplete, not done";} 
     208            if ($NWWdiffpub eq $NexpWWdiff) {printf "%30s | %2s%1s%2s%1s%2s%1s%2s | %2s%1s%1s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %20s\n", $chunkname, $Nvis1, "/",$Nvis2, "/",$Nvis3, "/",$Nvis4,$Ncamgood, "/",$Ncambad,$Nwarpgood, "/",$Nwarpbad,$Npubwarps,$NWWdiffgood, "/",$NWWdiffbad,$NWWdiffpub,$NWSdiffgood, "/",$NWSdiffbad,$NWSdiffpub, "chunk incomplete, done";}
    208209          }
    209           if ($Nvis1 eq $Nvis4) {
    210             if ($NWWdiffpub ne $NexpWWdiff) {printf "%18s | %2s%1s%2s%1s%2s%1s%2s | %2s%1s%1s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %20s\n", $chunkname, $Nvis1, "/",$Nvis2, "/",$Nvis3, "/",$Nvis4,$Ncamgood, "/",$Ncambad,$Nwarpgood, "/",$Nwarpbad,$Npubwarps,$NWWdiffgood, "/",$NWWdiffbad,$NWWdiffpub,$NWSdiffgood, "/",$NWSdiffbad,$NWSdiffpub, "chunk complete, not done";}
    211             if ($NWWdiffpub eq $NexpWWdiff) {printf "%18s | %2s%1s%2s%1s%2s%1s%2s | %2s%1s%1s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %20s\n", $chunkname, $Nvis1, "/",$Nvis2, "/",$Nvis3, "/",$Nvis4,$Ncamgood, "/",$Ncambad,$Nwarpgood, "/",$Nwarpbad,$Npubwarps,$NWWdiffgood, "/",$NWWdiffbad,$NWWdiffpub,$NWSdiffgood, "/",$NWSdiffbad,$NWSdiffpub, "chunk complete, done";}
     210          if (($uniNvis1 eq $uniNvis2) and ($uniNvis1 eq $uniNvis3) and ($uniNvis1 eq $uniNvis4)) {
     211            if ($NWWdiffpub ne $NexpWWdiff) {printf "%30s | %2s%1s%2s%1s%2s%1s%2s | %2s%1s%1s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %20s\n", $chunkname, $Nvis1, "/",$Nvis2, "/",$Nvis3, "/",$Nvis4,$Ncamgood, "/",$Ncambad,$Nwarpgood, "/",$Nwarpbad,$Npubwarps,$NWWdiffgood, "/",$NWWdiffbad,$NWWdiffpub,$NWSdiffgood, "/",$NWSdiffbad,$NWSdiffpub, "chunk complete, not done";}
     212            if ($NWWdiffpub eq $NexpWWdiff) {printf "%30s | %2s%1s%2s%1s%2s%1s%2s | %2s%1s%1s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %20s\n", $chunkname, $Nvis1, "/",$Nvis2, "/",$Nvis3, "/",$Nvis4,$Ncamgood, "/",$Ncambad,$Nwarpgood, "/",$Nwarpbad,$Npubwarps,$NWWdiffgood, "/",$NWWdiffbad,$NWWdiffpub,$NWSdiffgood, "/",$NWSdiffbad,$NWSdiffpub, "chunk complete, done";}
    212213          }
    213214    }
     
    316317        if (!$doHeader) { print "\n"; }
    317318    }
     319
     320    #-----------------------------------------
     321    #check for overridden exposures
     322    my $query = "SELECT COUNT(comment), comment";
     323    $query .= " FROM rawExp";
     324    $query .= " JOIN chipRun USING (exp_id)";
     325    $query .= " JOIN camRun USING (chip_id)";
     326    $query .= " WHERE dateobs LIKE '$date%'";
     327    $query .= " AND exp_id > $refExpID";
     328    $query .= " AND exp_type = 'OBJECT'";
     329    $query .= " AND (camRun.label LIKE '%SS%' OR camRun.label LIKE '%EU%' OR camRun.label LIKE '%Bright.%') AND obs_mode NOT LIKE 'ENGINEERING' AND obs_mode NOT LIKE 'MANUAL'";
     330    $query .= " GROUP BY comment";
     331
     332    my $result = &mysql_select ($query);
     333
     334    $doHeader = 1;
     335    while (@row = $result->fetchrow_array()) {
     336        if ($row[0] > 1) {
     337            my $query = "SELECT exp_name,dateobs, comment";
     338            $query .= " FROM rawExp";
     339            $query .= " JOIN chipRun USING (exp_id)";
     340            $query .= " JOIN camRun USING (chip_id)";
     341            $query .= " WHERE dateobs LIKE '$date%' AND comment LIKE '$row[1]'";
     342            $query .= " AND exp_id > $refExpID";
     343            $query .= " AND exp_type = 'OBJECT'";
     344            $query .= " AND (camRun.label LIKE '%SS%' OR camRun.label LIKE '%EU%' OR camRun.label LIKE '%Bright.%') AND obs_mode NOT LIKE 'ENGINEERING' AND obs_mode NOT LIKE 'MANUAL'";
     345            $query .= " ORDER BY dateobs DESC";
     346
     347            my $result = &mysql_select ($query);
     348
     349            $doskip = 0;
     350            while (@row2 = $result->fetchrow_array()) {
     351                if ($doskip) {
     352                    if ($doHeader) {
     353                        print "Overridden exposures:\n";
     354                        printf "%11s |  %9s | %15s\n", "exp_name", "dateobs", "comment";
     355                        $doHeader = 0;
     356                    }
     357                    printf "%11s | %9s | %15s\n", $row2[0], $row2[1], $row2[2];
     358                }
     359                $doskip = 1;
     360            }
     361        }
     362    }
     363    if (!$doHeader) { print "\n"; }
     364
    318365}
    319366
     
    11201167# count the number of chunks, and their status:
    11211168if ($verbose or $report) {
    1122     print "Current status of SS and Euclid chunks:\n";
    1123 
    1124     #First find the number of chunks and their names
    1125     my $query = "SELECT groupchunk.chunk,groupchunk.Nquad_firstvisit,group4.Nquad_fourvisits FROM";
    1126     $query .= "   (";
    1127     $query .= "     SELECT dateobs,comment,substr(comment, 1, position(' ' in comment)) AS chunk,count(distinct(comment)) AS Nquad_firstvisit";
    1128     $query .= "     FROM rawExp";
    1129     $query .= "     WHERE dateobs LIKE '$date%' AND exp_id > $refExpID";
    1130     $query .= "     AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%') AND obs_mode NOT LIKE 'ENGINEERING'";
    1131     $query .= "     AND comment LIKE '%visit 1%'";
    1132     $query .= "     GROUP BY chunk";
    1133     $query .= "   ) AS groupchunk";
    1134     $query .= "   LEFT JOIN";
    1135     $query .= "   (";
    1136     $query .= "     SELECT groupobj.chunk,count(*) AS Nquad_fourvisits FROM ";
    1137     $query .= "       (SELECT substr(comment, 1, position(' ' in comment)) AS chunk,count(distinct(comment)) AS Nvisits";
    1138     $query .= "         FROM rawExp";
    1139     $query .= "         WHERE dateobs LIKE '$date%' AND exp_id > $refExpID AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%')";
    1140     $query .= "         AND obs_mode NOT LIKE 'ENGINEERING' AND comment LIKE '%visit%'";
    1141     $query .= "         GROUP BY object, filter, chunk";
    1142     $query .= "       ) AS groupobj";
    1143     $query .= "     WHERE groupobj.Nvisits = 4 ";
    1144     $query .= "     GROUP BY groupobj.chunk";
    1145     $query .= "   ) AS group4";
    1146     $query .= "   on groupchunk.chunk=group4.chunk ORDER BY dateobs";
     1169    print "Current status of SS, Euclid and BRIGHT chunks:\n";
     1170
     1171    my $badcamflag = 0;
     1172    my $badwarpflag = 0;
     1173    my $baddiffflag = 0;
     1174
     1175    #do a query of raw/chip/cam/warp counts for this night, split by chunk.
     1176    #we need to do a subquery to find the total number of skycells in warpSkyfile, as well as the number of those with a bad quality
     1177    my $query = "SELECT suba.chunk,suba.Nvis1,suba.Nvis2,suba.Nvis3,suba.Nvis4,suba.Ncamgood,suba.Ncambad,subb.Nwarpgood,subb.Nwarpbad,suba.uniNvis1,suba.uniNvis2,suba.uniNvis3,suba.uniNvis4 FROM ";
     1178    $query .= "    (SELECT substr(comment, 1, position(' ' in comment)) AS chunk,count(if(rawExp.comment LIKE '%visit 1%',1,NULL)) AS Nvis1,";
     1179    $query .= "    count(if(rawExp.comment LIKE '%visit 2%',1,NULL)) AS Nvis2,count(if(rawExp.comment LIKE '%visit 3%',1,NULL)) AS Nvis3,";
     1180    $query .= "    count(if(rawExp.comment LIKE '%visit 4%',1,NULL)) AS Nvis4, count(if(camProcessedExp.sigma_ra <= 5 AND camProcessedExp.sigma_dec <= 5 AND camProcessedExp.quality = 0,1,NULL)) AS Ncamgood,";
     1181    $query .= "    count(if(camProcessedExp.sigma_ra > 5 OR camProcessedExp.sigma_dec > 5 OR camProcessedExp.quality > 0,1,NULL)) AS Ncambad, COUNT(DISTINCT CASE WHEN rawExp.comment LIKE '%visit 1%' THEN rawExp.comment END) AS uniNvis1,";
     1182    $query .= "    COUNT(DISTINCT CASE WHEN rawExp.comment LIKE '%visit 2%' THEN rawExp.comment END) AS uniNvis2,COUNT(DISTINCT CASE WHEN rawExp.comment LIKE '%visit 3%' THEN rawExp.comment END) AS uniNvis3,";
     1183    $query .= "    COUNT(DISTINCT CASE WHEN rawExp.comment LIKE '%visit 4%' THEN rawExp.comment END) AS uniNvis4";
     1184    $query .= "    FROM rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) JOIN camProcessedExp USING (cam_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id)";
     1185    $query .= "    WHERE dateobs like '$date%' AND exp_id > $refExpID AND exp_type = 'OBJECT' AND rawExp.comment like '%visit%'";
     1186    $query .= "    AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%') AND obs_mode NOT LIKE 'ENGINEERING' AND obs_mode NOT LIKE 'MANUAL'";
     1187    $query .= "    GROUP BY chunk ORDER BY dateobs) as suba ";
     1188    $query .= "LEFT JOIN";
     1189    $query .= "    (SELECT subc.chunk, count(if(subc.Nwarpskycellbad < subc.Nwarpskycell,1,NULL)) AS Nwarpgood, count(if(subc.Nwarpskycellbad = subc.Nwarpskycell,1,NULL)) AS Nwarpbad";
     1190    $query .= "    FROM ";
     1191    $query .= "      (SELECT substr(comment, 1, position(' ' in comment)) AS chunk,count(warpSkyfile.quality) AS Nwarpskycell,count(if(warpSkyfile.quality > 0,1,NULL)) AS Nwarpskycellbad";
     1192    $query .= "      FROM rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) JOIN warpSkyfile USING (warp_id)";
     1193    $query .= "      WHERE dateobs like '$date%' AND exp_id > $refExpID AND exp_type = 'OBJECT' AND rawExp.comment like '%visit%'";
     1194    $query .= "      AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%') AND obs_mode NOT LIKE 'ENGINEERING' AND obs_mode NOT LIKE 'MANUAL'";
     1195    $query .= "      GROUP BY exp_name) as subc";
     1196    $query .= "    GROUP BY chunk) AS subb ";
     1197    $query .= "ON suba.chunk=subb.chunk";
    11471198 
    11481199    my $result = &mysql_select ($query);
    11491200
    1150     printf "%18s | %13s | %13s | %14s |\n", "chunk", "Nobs_1stvisit", "Nobs_4visits", "Ndiffs_publish";
    1151     while (@row = $result->fetchrow_array()) {
    1152           my $Nfirstvisits = 0;
    1153           my $Nfourvisits = 0;
     1201    printf "%30s | %11s | %4s | %4s | %7s | %4s | %7s | %4s | %7s |\n", "chunk", "Nobs", "Ncam","Nwrp","Nwrp_pub", "Nwwd", "Nwwd_pub", "Nwsd", "Nwsd_pub";
     1202    while (@row = $result->fetchrow_array()) {
     1203          my $Nvis1 = 0;
     1204          my $Nvis2 = 0;
     1205          my $Nvis3 = 0;
     1206          my $Nvis4 = 0;
     1207          my $Ncamgood = 0;
     1208          my $Ncambad = 0;
     1209          my $Nwarpgood = 0;
     1210          my $Nwarpbad = 0;
     1211          my $NexpWWdiff = 0;
     1212          my $Npubwarps = 0;
     1213          my $uniwarps = undef;
     1214          my $uniNvis1 = 0;
     1215          my $uniNvis2 = 0;
     1216          my $uniNvis3 = 0;
     1217          my $uniNvis4 = 0;
    11541218
    11551219          my $chunkname = $row[0];
    1156           if($row[1] gt 0) {$Nfirstvisits = $row[1]};
    1157           if($row[2] gt 0) {$Nfourvisits = $row[2]};
    1158 
    1159           my $query2 .= "     SELECT warp_id FROM ";
    1160           $query2 .= "           warpRun JOIN fakeRun USING (fake_id) JOIN camRun USING (cam_id) JOIN camProcessedExp USING (cam_id) JOIN chipRun USING (chip_id) JOIN rawExp USING (exp_id)";
    1161           $query2 .= "           WHERE rawExp.dateobs LIKE '$date%' AND exp_id > $refExpID AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%')";
    1162           $query2 .= "           AND substr(comment, 1, position(' ' in comment)) LIKE '$chunkname%'";
     1220          if($row[1] gt 0) {$Nvis1 = $row[1]};
     1221          if($row[2] gt 0) {$Nvis2 = $row[2]};
     1222          if($row[3] gt 0) {$Nvis3 = $row[3]};
     1223          if($row[4] gt 0) {$Nvis4 = $row[4]};
     1224          if($row[5] gt 0) {$Ncamgood = $row[5]};
     1225          if($row[6] gt 0) {$Ncambad = $row[6]};
     1226          if($row[7] gt 0) {$Nwarpgood = $row[7]};
     1227          if($row[8] gt 0) {$Nwarpbad = $row[8]};
     1228          if($row[9] gt 0) {$uniNvis1 = $row[9]};
     1229          if($row[10] gt 0) {$uniNvis2 = $row[10]};
     1230          if($row[11] gt 0) {$uniNvis3 = $row[11]};
     1231          if($row[12] gt 0) {$uniNvis4 = $row[12]};
     1232
     1233          #set flags if present
     1234          if($Ncambad >= 1) {$badcamflag = 1};
     1235          if($Nwarpbad >= 1) {$badwarpflag = 1};
     1236
     1237          #Find the expected number of diffs for this chunk
     1238          my $query1 = "SELECT suba.chunk, SUM(IF(suba.Nvisits = 2,1,NULL)) as totvis2, SUM(IF(suba.Nvisits = 3 OR suba.Nvisits = 4,2,NULL)) as totvis34 FROM";
     1239          $query1 .= "    (SELECT substr(comment, 1, position(' ' in comment)) AS chunk,count(distinct(comment)) AS Nvisits FROM";
     1240          $query1 .= "    rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) WHERE dateobs like '$date%'";
     1241          $query1 .= "    AND exp_id > $refExpID AND exp_type = 'OBJECT' AND rawExp.comment like '%visit%' AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%') AND obs_mode NOT LIKE 'ENGINEERING' AND obs_mode NOT LIKE 'MANUAL'";
     1242          $query1 .= "    AND substr(comment, 1, position(' ' in comment)) LIKE '$chunkname%' group by object) as suba group by chunk;";
     1243          my $result1 = &mysql_select ($query1);
     1244          while (@row = $result1->fetchrow_array()) {$NexpWWdiff = $row[1] + $row[2];}
     1245
     1246          #find the unique diff_ids for each chunk, to be matched to the diffRun catalog
     1247          my $query2 = "     SELECT diff_id,warp1,stack1,warp2,stack2 FROM ";
     1248          $query2 .= "           diffInputSkyfile JOIN warpRun ON (warp1=warp_id OR warp2=warp_id) JOIN fakeRun USING (fake_id) JOIN camRun USING (cam_id) JOIN camProcessedExp USING (cam_id) JOIN chipRun USING (chip_id) JOIN rawExp USING (exp_id)";
     1249          $query2 .= "           WHERE rawExp.dateobs LIKE '$date%' AND exp_id > $refExpID AND exp_type = 'OBJECT' AND rawExp.comment like '%visit%' AND (obs_mode LIKE '%SS%' OR obs_mode LIKE '%BRIGHT%')";
     1250          $query2 .= "            AND obs_mode NOT LIKE 'ENGINEERING' AND obs_mode NOT LIKE 'MANUAL' AND substr(comment, 1, position(' ' in comment)) LIKE '$chunkname%' GROUP By diff_id";
    11631251          my $result2 = &mysql_select ($query2);
    11641252
    1165           my $Ndiffs = 0;
     1253          my $NWWdiffgood = 0;
     1254          my $NWWdiffbad = 0;
     1255          my $NWWdiffpub = 0;
     1256
     1257          my $NWSdiffgood = 0;
     1258          my $NWSdiffbad = 0;
     1259          my $NWSdiffpub = 0;
     1260          my %wrpcnt = ();
     1261
    11661262          while (@row2 = $result2->fetchrow_array()) {
    1167               my $query3 .= "     SELECT diff_id FROM ";
    1168               $query3 .= "           diffRun JOIN diffInputSkyfile USING (diff_id) JOIN publishRun ON (diff_id = stage_id) JOIN warpRun ON (warp1=warp_id)";
    1169               $query3 .= "           WHERE stack2 IS NULL AND publishRun.state LIKE 'full' AND warp_id='$row2[0]' GROUP BY diff_id";
    1170               my $result3 = &mysql_select ($query3);
    1171               while (@row3 = $result3->fetchrow_array()) {if ($row3[0] !=0) {$Ndiffs ++;}}
    1172 
    1173               my $query3 .= "     SELECT diff_id FROM ";
    1174               $query3 .= "           diffRun JOIN diffInputSkyfile USING (diff_id) JOIN publishRun ON (diff_id = stage_id) JOIN warpRun ON (warp2=warp_id)";
    1175               $query3 .= "           WHERE stack2 IS NULL AND publishRun.state LIKE 'full' AND warp_id='$row2[0]' GROUP BY diff_id";
    1176               my $result3 = &mysql_select ($query3);
    1177               while (@row3 = $result3->fetchrow_array()) {if ($row3[0] !=0) {$Ndiffs ++;}}
     1263              #distinguish between WW and WS diffs based on stack2
     1264              if ($row2[4] == 0) {
     1265                  #find the total number of skycell and the number of skycell with a bad quality flag as well as the full publish state
     1266                  my $query3 = "     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 ";
     1267                  $query3 .= "           diffRun JOIN diffSkyfile USING (diff_id) LEFT JOIN publishRun ON (diffRun.diff_id = stage_id)";
     1268                  $query3 .= "           WHERE diff_id='$row2[0]' GROUP BY diffRun.diff_id";
     1269                  my $result3 = &mysql_select ($query3);
     1270                  while (@row3 = $result3->fetchrow_array()) {
     1271                      #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
     1272                      if ($row3[1]<$row3[0]) {$NWWdiffgood ++;}
     1273                      if ($row3[1]==$row3[0]) {$NWWdiffbad ++;}
     1274                      if ($row3[2]==$row3[0]) {$NWWdiffpub ++;}
     1275
     1276                      #if this wwdiff is published, record its corresponding warp_ids to see how many unique ones there are
     1277                      if ($row3[2]==$row3[0]) {$wrpcnt{$row2[1]}++;}  # record the presence of warp1
     1278                      if ($row3[2]==$row3[0]) {$wrpcnt{$row2[3]}++;}  # record the presence of warp2
     1279                  }
     1280              }
     1281
     1282              if ($row2[4] > 0) {
     1283                  #find the total number of skycell and the number of skycell with a bad quality flag as well as the full publish state
     1284                  my $query3 = "     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 ";
     1285                  $query3 .= "           diffRun JOIN diffSkyfile USING (diff_id) LEFT JOIN publishRun ON (diffRun.diff_id = stage_id)";
     1286                  $query3 .= "           WHERE diff_id='$row2[0]' GROUP BY diffRun.diff_id";
     1287                  my $result3 = &mysql_select ($query3);
     1288                  while (@row3 = $result3->fetchrow_array()) {
     1289                      #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
     1290                      if ($row3[1]<$row3[0]) {$NWSdiffgood ++;}
     1291                      if ($row3[1]==$row3[0]) {$NWSdiffbad ++;}
     1292                      if ($row3[2]==$row3[0]) {$NWSdiffpub ++;}
     1293                  }
     1294              }
    11781295          }
    1179 
    1180           if ($Nfirstvisits ne $Nfourvisits) {
    1181             if ($Ndiffs ne ($Nfirstvisits*4)) {printf "%18s | %13s | %13s | %10s%4s | %14s\n", $chunkname, $Nfirstvisits, $Nfourvisits, $Ndiffs, "/?  ", "chunk not done";}  # chunk    Nquad_firstvisit        Nquad_fourvisits        Ndiffs
    1182             if ($Ndiffs eq ($Nfirstvisits*4)) {printf "%18s | %13s | %13s | %10s%4s | %14s\n", $chunkname, $Nfirstvisits, $Nfourvisits, $Ndiffs, "/?  ", "chunk done";}          # chunk        Nquad_firstvisit        Nquad_fourvisits        Ndiffs
     1296          #pull out the unique warp_ids
     1297          $Npubwarps = keys %wrpcnt;
     1298
     1299          #check for bad diffs
     1300          if(($NWWdiffbad >= 1) or ($NWSdiffbad >= 1)) {$baddiffflag = 1;}
     1301
     1302          if (($uniNvis1 ne $uniNvis2) or ($uniNvis1 ne $uniNvis3) or ($uniNvis1 ne $uniNvis4)) {
     1303            if ($NWWdiffpub ne $NexpWWdiff) {printf "%30s | %2s%1s%2s%1s%2s%1s%2s | %2s%1s%1s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %20s\n", $chunkname, $Nvis1, "/",$Nvis2, "/",$Nvis3, "/",$Nvis4,$Ncamgood, "/",$Ncambad,$Nwarpgood, "/",$Nwarpbad,$Npubwarps,$NWWdiffgood, "/",$NWWdiffbad,$NWWdiffpub,$NWSdiffgood, "/",$NWSdiffbad,$NWSdiffpub, "chunk incomplete, not done";} 
     1304            if ($NWWdiffpub eq $NexpWWdiff) {printf "%30s | %2s%1s%2s%1s%2s%1s%2s | %2s%1s%1s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %20s\n", $chunkname, $Nvis1, "/",$Nvis2, "/",$Nvis3, "/",$Nvis4,$Ncamgood, "/",$Ncambad,$Nwarpgood, "/",$Nwarpbad,$Npubwarps,$NWWdiffgood, "/",$NWWdiffbad,$NWWdiffpub,$NWSdiffgood, "/",$NWSdiffbad,$NWSdiffpub, "chunk incomplete, done";}
    11831305          }
    1184           if ($Nfirstvisits eq $Nfourvisits) {
    1185             if ($Ndiffs ne ($Nfirstvisits*4)) {printf "%18s | %13s | %13s | %10s%1s%3s | %14s\n", $chunkname, $Nfirstvisits, $Nfourvisits, $Ndiffs,"/",$Nfirstvisits*4, "chunk not done";}  # chunk     Nquad_firstvisit        Nquad_fourvisits        Ndiffs
    1186             if ($Ndiffs eq ($Nfirstvisits*4)) {printf "%18s | %13s | %13s | %10s%1s%3s | %14s\n", $chunkname, $Nfirstvisits, $Nfourvisits, $Ndiffs,"/",$Nfirstvisits*4, "chunk done";}          # chunk Nquad_firstvisit        Nquad_fourvisits        Ndiffs
     1306          if (($uniNvis1 eq $uniNvis2) and ($uniNvis1 eq $uniNvis3) and ($uniNvis1 eq $uniNvis4)) {
     1307            if ($NWWdiffpub ne $NexpWWdiff) {printf "%30s | %2s%1s%2s%1s%2s%1s%2s | %2s%1s%1s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %20s\n", $chunkname, $Nvis1, "/",$Nvis2, "/",$Nvis3, "/",$Nvis4,$Ncamgood, "/",$Ncambad,$Nwarpgood, "/",$Nwarpbad,$Npubwarps,$NWWdiffgood, "/",$NWWdiffbad,$NWWdiffpub,$NWSdiffgood, "/",$NWSdiffbad,$NWSdiffpub, "chunk complete, not done";}
     1308            if ($NWWdiffpub eq $NexpWWdiff) {printf "%30s | %2s%1s%2s%1s%2s%1s%2s | %2s%1s%1s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %2s%1s%1s | %8s | %20s\n", $chunkname, $Nvis1, "/",$Nvis2, "/",$Nvis3, "/",$Nvis4,$Ncamgood, "/",$Ncambad,$Nwarpgood, "/",$Nwarpbad,$Npubwarps,$NWWdiffgood, "/",$NWWdiffbad,$NWWdiffpub,$NWSdiffgood, "/",$NWSdiffbad,$NWSdiffpub, "chunk complete, done";}
    11871309          }
    11881310    }
    11891311
    11901312    print "\n";
     1313
    11911314}
    11921315
Note: See TracChangeset for help on using the changeset viewer.