IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 40530


Ignore:
Timestamp:
Sep 26, 2018, 12:13:43 PM (8 years ago)
Author:
eugene
Message:

cleanup the night_report script

File:
1 edited

Legend:

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

    r40461 r40530  
    1212GetOptions(
    1313    'date=s'            => \$date,
    14     'dbname|d=s'        => \$dbname,    # Database name
    15     'verbose'           => \$verbose,   # Print to stdout
    16     'very-verbose'      => \$verbose2,   # Print to stdout
     14    'dbname|d=s'        => \$dbname,   # Database name
     15    'verbose'           => \$verbose,  # Print to stdout
     16    'report'            => \$report,   # Formatted for ps-obs report
     17    'very-verbose'      => \$verbose2, # Print to stdout
    1718    ) or pod2usage( 2 );
    1819
     
    4546my $dbh = DBI->connect( $dsn, $dbuser, $dbpass ) or die "Unable to connect to database: $DBI::errstr";
    4647
    47 # find a useful exp_id
     48# find a useful exp_id (ALWAYS do this)
    4849$refExpID = 0;
    4950if (1) {
     
    6364      print "*** WARNING: no data in period 10-20 days before requested date (query will be slower) **\n";
    6465    }
    65     # print "Reference exp_id: $refExpID\n";
    66 }
     66    if ($verbose2) { print "Reference exp_id: $refExpID\n"; }
     67}
     68
     69##################33
     70### testing the diff grouping -- this does not work for the Euclid data taken 2018.07.29 because the OBJECT
     71### field is missing
     72if (0) {
     73    print "Expected number of WWdiffs excluding camRuns with bad quality:\n";
     74    print "NOTE: multiple exposures with same comment string (xyz visit a) are treated as 1 exposure\n";
     75
     76    # my $query = "SELECT Nvisit, count(*) FROM";
     77    # $query .= " (";
     78    # $query .= "   SELECT object, filter, chunk, count(*) as Nvisit FROM";
     79    # $query .= "   (";
     80    my $query = "SELECT object, filter, comment, 'S', substr(comment, 1, position(' ' in comment)) as chunk, 'E'";
     81    $query .= "     FROM rawExp";
     82    $query .= "     LEFT JOIN chipRun using (exp_id)";
     83    $query .= "     LEFT JOIN camRun using (chip_id)";
     84    $query .= "     LEFT JOIN camProcessedExp using (cam_id)";
     85    $query .= "     WHERE dateobs LIKE '$date%'";
     86    $query .= "     AND exp_id > $refExpID"; #REF
     87    $query .= "     AND exp_type = 'OBJECT'";
     88    $query .= "     AND obs_mode NOT LIKE 'ENGINEERING'";
     89    $query .= "     AND (obs_mode like '%SS%' or obs_mode like 'BRIGHT')";
     90    $query .= "     AND rawExp.comment like '%visit%'";
     91    $query .= "     AND (camProcessedExp.quality IS NULL or camProcessedExp.quality = 0)";
     92#   $query .= "     GROUP BY comment, filter, substr(comment, 1, position(' ' in comment))";
     93#    $query .= "   ) AS tableChunks GROUP BY object, filter, chunk";
     94#    $query .= " ) AS tableVisits GROUP BY Nvisit";
     95
     96    my $result = &mysql_select ($query);
     97    &mysql_dump_result ($result);
     98    die;
     99
     100    $diffExpect = 0;
     101    while (@row = $result->fetchrow_array()) {
     102        # printf "%8s %15s : ", $row[0], $row[1]; # c, count(*)
     103        if ($row[0] == 1) {
     104            if ($row[1] == 1) { $verb = "tuple has"; } else { $verb = "tuples have"; }
     105            printf "%3d %-11s 1 visit, no WWdiffs\n", $row[1], $verb;
     106        } elsif ($row[0] == 2) {
     107            if ($row[1] == 1) { $verb = "tuple has"; } else { $verb = "tuples have"; }
     108            printf "%3d %-11s 2 visits, expect $row[1] WWdiff(s)\n", $row[1], $verb;
     109            $diffExpect += $row[1];
     110        } elsif ($row[0] == 3) {
     111            if ($row[1] == 1) { $verb = "tuple has"; } else { $verb = "tuples have"; }
     112            printf "%3d %-11s 3 visits, expect %d WWdiffs (2 per tuple)\n", $row[1], $verb,  2 * $row[1];
     113            $diffExpect += $row[1]*2;
     114        } elsif ($row[0] == 4) {
     115            if ($row[1] == 1) { $verb = "tuple has"; } else { $verb = "tuples have"; }
     116            printf "%3d %-11s 4 visits, expect %d WWdiffs (2 per tuple)\n", $row[1], $verb,  2 * $row[1];
     117            $diffExpect += $row[1]*2;
     118        } else {
     119            # print "I don't understand, there are more visits than I expect\n";
     120            if ($row[1] == 1) { $verb = "tuple has"; } else { $verb = "tuples have"; }
     121            if ($row[0] % 2) { $Ndiffs = int($row[0] / 2) + 1; } else { $Ndiffs = int($row[0] / 2); }
     122            printf "%3d %-11s %d visits, expect %d WWdiffs (2 per quad)\n", $row[1], $verb,  $row[0], $Ndiffs;
     123            $diffExpect += $Ndiffs;
     124        }
     125    }
     126    print "\n";
     127    print " * $diffExpect diffRuns expected *\n";
     128    if ($verbose) { print "\n"; }
     129
     130    die;
     131}
     132######################
    67133
    68134# check the status of summit exposures:
     
    129195# check the status of raw exposures:
    130196if (1) {
    131     if ($verbose) { print "Exposures in rawExp:\n"; }
     197    if ($verbose or $report) { print "Exposures in rawExp:\n"; }
    132198
    133199    $expSkipped = 0;
     
    144210    my $result = &mysql_select ($query);
    145211
    146     if ($verbose) { printf "%8s %15s %6s %4s\n", "exp_type", "obs_mode", "state", "N(exp)"; }
    147     while (@row = $result->fetchrow_array()) {
    148         if ($verbose) { printf "%8s %15s %6s %4d\n", $row[0], $row[1], $row[2], $row[3]; }
     212    if ($verbose or $report) { printf "%8s %15s %6s %4s\n", "exp_type", "obs_mode", "state", "N(exp)"; }
     213    while (@row = $result->fetchrow_array()) {
     214        if ($verbose or $report) { printf "%8s %15s %6s %4d\n", $row[0], $row[1], $row[2], $row[3]; }
    149215        if ($row[2] eq "new") {
    150216            $expPending += $row[3];
     
    294360# count the number of exposures per chunk, determine expected diffRuns:
    295361{
    296     print "Expected number of WWdiffs excluding camRuns with bad quality:\n";
    297     print "NOTE: multiple exposures with same comment string (xyz visit a) are treated as 1 exposure\n";
     362    if ($report) {
     363        print "\n";
     364    } else {
     365        print "Expected number of WWdiffs excluding camRuns with bad quality:\n";
     366        print "NOTE: multiple exposures with same comment string (xyz visit a) are treated as 1 exposure\n";
     367    }
    298368
    299369    # my $result = &mysql_select ("");
     
    324394        # printf "%8s %15s : ", $row[0], $row[1]; # c, count(*)
    325395        if ($row[0] == 1) {
    326             if ($row[1] == 1) { $verb = "quad has"; } else { $verb = "quads have"; }
     396            if ($row[1] == 1) { $verb = "tuple has"; } else { $verb = "tuples have"; }
    327397            printf "%3d %-11s 1 visit, no WWdiffs\n", $row[1], $verb;
    328398        } elsif ($row[0] == 2) {
    329             if ($row[1] == 1) { $verb = "quad has"; } else { $verb = "quads have"; }
     399            if ($row[1] == 1) { $verb = "tuple has"; } else { $verb = "tuples have"; }
    330400            printf "%3d %-11s 2 visits, expect $row[1] WWdiff(s)\n", $row[1], $verb;
    331401            $diffExpect += $row[1];
    332402        } elsif ($row[0] == 3) {
    333             if ($row[1] == 1) { $verb = "quad has"; } else { $verb = "quads have"; }
    334             printf "%3d %-11s 3 visits, expect %d WWdiffs (2 per quad)\n", $row[1], $verb,  2 * $row[1];
     403            if ($row[1] == 1) { $verb = "tuple has"; } else { $verb = "tuples have"; }
     404            printf "%3d %-11s 3 visits, expect %d WWdiffs (2 per tuple)\n", $row[1], $verb,  2 * $row[1];
    335405            $diffExpect += $row[1]*2;
    336406        } elsif ($row[0] == 4) {
    337             if ($row[1] == 1) { $verb = "quad has"; } else { $verb = "quads have"; }
    338             printf "%3d %-11s 4 visits, expect %d WWdiffs (2 per quad)\n", $row[1], $verb,  2 * $row[1];
     407            if ($row[1] == 1) { $verb = "tuple has"; } else { $verb = "tuples have"; }
     408            printf "%3d %-11s 4 visits, expect %d WWdiffs (2 per tuple)\n", $row[1], $verb,  2 * $row[1];
    339409            $diffExpect += $row[1]*2;
    340410        } else {
    341             print "I don't understand, there are more visits than I expect\n";
     411            # print "I don't understand, there are more visits than I expect\n";
     412            if ($row[1] == 1) { $verb = "tuple has"; } else { $verb = "tuples have"; }
     413            if ($row[0] % 2) { $Ndiffs = int($row[0] / 2) + 1; } else { $Ndiffs = int($row[0] / 2); }
     414            printf "%3d %-11s %d visits, expect %d WWdiffs (2 per quad)\n", $row[1], $verb,  $row[0], $Ndiffs;
     415            $diffExpect += $Ndiffs;
    342416        }
    343417    }
     
    432506        print "*** WARNING: Expect $diffExpect diffRuns, complete $diffDone diffRuns: inconsistent ***\n";
    433507    } else {
    434         print " * $diffDone of $diffExpect diffRuns completed *\n";
     508        if (not $report) { print " * $diffDone of $diffExpect diffRuns completed *\n";  }
    435509    }
    436510}
     
    452526
    453527    @row = $result->fetchrow_array();
    454     printf " * %d diffRuns can be published *   (has at least 1 skycell with quality = 0 or quality is NULL)\n", $row[0];
     528    if (not $report) { printf " * %d diffRuns can be published *   (has at least 1 skycell with quality = 0 or quality is NULL)\n", $row[0]; }
    455529    if ($verbose) { print "\n"; }
    456530    $diffRunsToBePublished = $row[0];
     
    555629
    556630    while (@row = $result->fetchrow_array()) {
    557         if ($verbose && $doHeader) {
     631        if (($verbose or $report) && $doHeader) {
    558632            print "Bad quality camRun exposures:\n";
    559633            printf "%11s %7s | %15s\n", "exp_name", "quality", "comment";
    560634            $doHeader = 0;
    561635        }
    562         if ($verbose) { printf "%11s %7d | %15s\n", $row[0], $row[1], $row[2]; } else { $NbadCam ++; }
    563     }
    564     if ($verbose && !$doHeader) { print "\n"; }
    565     if (!$verbose) { print "$NbadCam bad quality camera exposures\n\n"; }
     636        if ($verbose or $report) { printf "%11s %7d | %15s\n", $row[0], $row[1], $row[2]; } else { $NbadCam ++; }
     637    }
     638    if (($verbose or $report) && !$doHeader) { print "\n"; }
     639    if (!($verbose or $report)) { print "$NbadCam bad quality camera exposures\n\n"; }
    566640}
    567641
    568642# check the status of diff runs NOT for Solar System:
    569 if ($verbose) {
     643if ($verbose or $report) {
    570644    # my $result = &mysql_select ("");
    571645    my $query = "SELECT * FROM";
     
    595669        if ($doHeader) {
    596670            print "Chunks which should not generate WWdiffs (not Solar System diffs)\n";
    597             printf "%8s %8s %8s %8s\n", "Object", "Filter", "Chunk", "N(visit)";
     671            printf "%16s %-8s %20s | %8s\n", "Object", "Filter", "Chunk", "N(visit)";
    598672            $doHeader = 0;
    599673        }
    600         printf "%8s %8s %8s %4d\n", $row[0], $row[1], $row[2], $row[3];
     674        printf "%16s %-8s %20s | %4d\n", $row[0], $row[1], $row[2], $row[3];
    601675    }
    602676    if (!$doHeader) { print "\n"; }
Note: See TracChangeset for help on using the changeset viewer.