<& /htmlheader, title => "TJD $tjd $model" &> <& modelheader &>
<% $tjd_str %>
<% qq{$utdate_str
OC $ocnum} %>

% foreach my $k (@chunks_ingested) { % }
Chunk Name Last Processing Status Num Exposures
<% $k->{cn} %> <% $statmap{$k->{status}} || 'UNKNOWN' %> <% $k->{ct} %>

Czaring

    % if ($have_quads) {
  • All Quads
  • % foreach my $rk (sort {$b <=> $a} keys %runs_quad) {
    <% $rk ? "Run ".$rk."
    " : ''%>
    % for(my $i = 0; $i < @{$runs_quad{$rk}}; $i++) { % my ($qv) = $quadchunkmap{$runs_quad{$rk}[$i]{name}}; % my $ch = $qv->{name}; my $qct = $qv->{nfoot}; % my $urlenc = $qv->{sel}; $urlenc = uri_escape($urlenc); <% qq{$ch} %> <% $statmap{$runs_quad{$rk}[$i]{status}} || 'UNKNOWN' %> <% qq{($qct footprint} . ($qct > 1 ? 's' : '') . qq{)} %>
    Start Num


    % }
    % } Slow Movers (experts only)

    % } % if ($have_mds) {
  • All MDs
  • % foreach my $rk (sort {$b <=> $a} keys %runs_md) {
    <% $rk ? "Run ".$rk."
    " : ''%>
    % for(my $i = 0; $i < @{$runs_md{$rk}}; $i++) { % my ($mv) = $quadchunkmap{$runs_md{$rk}[$i]{name}}; % my $ch = $mv->{name}; my $mct = $mv->{nfoot}; % my $urlenc = $mv->{sel}; $urlenc = uri_escape($urlenc); <% qq{$ch} %> <% $statmap{$runs_md{$rk}[$i]{status}} || 'UNKNOWN' %> <% qq{($mct footprint} . ($mct > 1 ? 's' : '') . qq{)} %>
    % }

    % } % } % if ($have_pairs) {
  • Pairs (experimental)
  • % foreach my $rk (sort {$b <=> $a} keys %runs_pair) {
    <% $rk ? "Run ".$rk."
    " : ''%>
    % for(my $i = 0; $i < @{$runs_pair{$rk}}; $i++) { % my ($pv) = $pairchunkmap{$runs_pair{$rk}[$i]{name}}; % my $ch = $pv->{name}; my $pct = $pv->{nfoot}; % my $urlenc = $pv->{sel}; $urlenc = uri_escape($urlenc); % my $pminv = $guru ? .15 : .3; <% qq{$ch} %> <% $statmap{$runs_pair{$rk}[$i]{status}} || 'UNKNOWN' %> <% qq{($pct footprint} . ($pct > 1 ? 's' : '') . qq{)} %>
    % }

    % } % }
  • Comets MBOs | Unknown (Diff | Chip)
  • Derived Objects (<% $tjd %> only, OC <% $ocnum %>)
  • Known Pairs
  • Submitted NEOs

Efficiency

Custom

Night <% $tjd %> field list
Old index page

Your lame browser doesn't support canvas.

Hammer | Spherical
% if (defined($prev_tjd)) { <% $prev_tjd_str %>
<% "$prev_utdate_str
OC $prev_oc" %> % }
% if (defined($next_tjd)) { <% $next_tjd_str %>
<% "$next_utdate_str
OC $next_oc" %>
% }
% if ($proj eq 's') { <& fieldmapsph.js, tjd => $tjd, show_plan => 's23456' &> % } else { <& fieldmap.js, tjd => $tjd, show_plan => 's23456' &> % } <& /htmlfooter &> <%args> $today => undef $nn => undef $tjd => undef $utdate => undef $proj => 'h' $guru => undef <%init> use Data::Dumper; use POSIX qw(strftime); use Astro::Time; use URI::Escape; use PS::MOPS::Lib; use PS::MOPS::DC::Field; my %statmap = ( I => 'INGESTED', N => 'READY', D => 'SYNTH', T => 'TRACKLET', U => 'POSTTRACKLET', A => 'ATTRIB', K => 'LINKING', L => 'COMPLETED', ); my $inst = $m->notes('INST'); my $mc = $inst->getConfig(); my $model = $m->notes('MODEL'); my $dbh = $inst->dbh; # Today's info. my ($year, $mon, $day); my $today_nn; my $today_tjd; my @schmoo = gmtime; $year = $schmoo[5] + 1900; $mon = $schmoo[4] + 1; $day = $schmoo[3]; $today_tjd = int(cal2mjd($day, $mon, $year, 0)) - 50000; $today_nn = $today_tjd - 1 + 50000; my $today_tjd_str = sprintf "TJD %d", $today_nn + 1 - 50000; my $today_utdate_str = make_nice_date_str($tjd + 50000); #$today_utdate_str =~ s/T.*//; # trim everything after date my $today_oc = mopslib_mjd2ocnum($today_nn); # User info. if ($tjd) { $nn = $tjd - 1 + 50000; } elsif ($utdate) { if ($utdate =~ /today/) { $nn = $today_nn; } elsif ($utdate =~ /^(\d\d\d\d)[\/.-]?(\d\d)[\/.-]?(\d\d)$/) { ($year, $mon, $day) = ($1, $2, $3); $nn = int(cal2mjd($day, $mon, $year, 0)) - 1; } } else { # nothing specified, use latest. ($nn) = $dbh->selectrow_array('select nn from fields order by nn desc limit 1'); $nn = $today_nn unless $nn; # no fields, oh well } $tjd = $nn - 50000 + 1; my $tjd_str = sprintf "TJD %d", $nn + 1 - 50000; my $utdate_str = make_nice_date_str($tjd + 50000); #$utdate_str =~ s/T.*//; # trim everything after date #$utdate_str .= ' UT'; my $ocnum = mopslib_mjd2ocnum($nn); my $off; my $next_tjd; my $next_nn; my $next_tjd_str; my $next_utdate_str; my $next_oc; my $prev_tjd; my $prev_nn; my $prev_tjd_str; my $prev_utdate_str; my $prev_oc; $off = get_nearest_nn_offset($dbh, $nn, 1); if ($off) { $next_tjd = $tjd + $off; $next_nn = $nn + $off; $next_tjd_str = sprintf "TJD %d", $next_tjd; $next_utdate_str = make_nice_date_str($next_tjd + 50000); # $next_utdate_str =~ s/T.*//; # trim everything after date # $next_utdate_str .= ' UT'; $next_oc = mopslib_mjd2ocnum($next_tjd + 50000); } $off = get_nearest_nn_offset($dbh, $nn, -1); if ($off) { $prev_tjd = $tjd + $off; $prev_nn = $nn + $off; $prev_tjd_str = sprintf "TJD %d", $prev_tjd; $prev_utdate_str = make_nice_date_str($prev_tjd + 50000); # $prev_utdate_str =~ s/T.*//; # trim everything after date # $prev_utdate_str .= ' UT'; $prev_oc = mopslib_mjd2ocnum($prev_tjd + 50000); } my $sth; # # Figure out what we've ingested. # $sth = $dbh->prepare(<<"SQL") or die $dbh->errstr; select survey_mode, status, count(*) ct from fields where nn=? group by survey_mode, status order by survey_mode, status SQL $sth->execute($nn) or die $sth->errstr; my @chunks_ingested; while (my $href = $sth->fetchrow_hashref) { push @chunks_ingested, { cn => $href->{survey_mode}, status => $href->{status}, ct => $href->{ct} }; } $sth->finish; # # Determine if simulation contains a runs table. If it does not contain the run table then create a # temporary runs table so that subsequent queries that use it don't fail. # $sth = $dbh->prepare(<<"SQL") or die $dbh->errstr; SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ? SQL $sth->execute($model, "runs") or die $dbh->errstr; my $count = $sth->fetchrow_array(); $sth->finish; if ($count < 1) { $dbh->do(<<"SQL") or die $dbh->errstr; CREATE TEMPORARY TABLE runs (`run_id` BIGINT, `field_id` BIGINT, `status` CHAR, `run_date` TIMESTAMP) SQL } # # Create a temporary table which will report all of the runs processed during the night along with the # chunks processed during the run. # $dbh->do(<<"SQL") or die $dbh->errstr; CREATE TEMPORARY TABLE chunks_processed (run_id BIGINT, survey_mode VARCHAR(120), type VARCHAR(120), status CHAR, footprints INT) SQL # # Insert all quads (including MDs) processed for the night into the temporary table. # $sth = $dbh->prepare(<<"SQL") or die $dbh->errstr; INSERT INTO chunks_processed (run_id, survey_mode, status, type, footprints) SELECT temp.run_id, temp.quad_name survey_mode, status, type, count(*) FROM ( SELECT run_id, group_concat(distinct survey_mode order by survey_mode separator ' ') quad_name, r.status, IF(survey_mode LIKE 'MD%', 'MD', 'Quad') type FROM fields LEFT JOIN runs r USING (field_id) WHERE nn=? GROUP BY run_id, IF(parent_id is null, field_id, parent_id) HAVING count(*) >= 3) AS temp GROUP BY run_id, quad_name SQL $sth->execute($nn) or die $sth->errstr; $sth->finish; # # Insert all pairs processed for the night into the temporary table. # $sth = $dbh->prepare(<<"SQL") or die $dbh->errstr; INSERT INTO chunks_processed (run_id, survey_mode, status, type, footprints) SELECT temp.run_id, temp.quad_name survey_mode, status, type, count(*) FROM ( SELECT run_id, group_concat(distinct survey_mode order by survey_mode separator ' ') quad_name, r.status, 'Pair' type FROM fields LEFT JOIN runs r USING (field_id) WHERE nn=? GROUP BY run_id, IF(parent_id is null, field_id, parent_id) HAVING count(*) = 2) AS temp GROUP BY run_id, quad_name SQL $sth->execute($nn) or die $sth->errstr; $sth->finish; # # This section creates a hash keyed on run_id, for each run_id there is a single array # which contains one or more hash elements. Each hash element consists of two keys : # name which contains the name of the chunk # status which contains the status the chunk was processued up to during the run # my (%runs_pair, %runs_quad, %runs_md); $sth = $dbh->prepare(<<"SQL") or die $dbh->errstr; SELECT run_id, survey_mode, type, status FROM chunks_processed ORDER BY run_id DESC SQL $sth->execute() or die $sth->errstr; while (my $href = $sth->fetchrow_hashref) { my %run_data = ( name => $href->{survey_mode}, status => $href->{status}); if ($href->{type} eq "Quad") { push @{$runs_quad{$href->{run_id}}}, { %run_data }; } elsif ($href->{type} eq "MD") { push @{$runs_md{$href->{run_id}}}, { %run_data }; } elsif ($guru or $href->{survey_mode} !~ /(z|y)$/) { push @{$runs_pair{$href->{run_id}}}, { %run_data }; } } $sth->finish; # # Figure out what quads we have. # my %quads_ingested; my $have_mds; my $have_quads; $sth = $dbh->prepare(<<"SQL") or die $dbh->errstr; SELECT survey_mode, footprints FROM chunks_processed WHERE type IN ('MD', 'Quad') SQL $sth->execute() or die $sth->errstr; while (my $href = $sth->fetchrow_hashref) { if ($href->{survey_mode} =~ /^MD/) { $have_mds = 1; } else { $have_quads = 1; } $quads_ingested{$href->{survey_mode}} = $href->{footprints}; } $sth->finish; # # This section creates a map of queried quad names to a substring # select for czaring. In other words, the GROUP_CONCAT() of all # survey_modes in a quad may include several survey_modes; this # maps the GROUP_CONCAT() result to a single, shorter string # used to select tracklets for czaring, e.g. # 140.3PI.00.ANE1.Q1.g+140.3PI.00.ANE1 => 140.3PI.00.ANE1.Q # my %quadchunkmap; my $sm; foreach my $ch (keys %quads_ingested) { if ($ch =~ /^MD/) { $sm = $ch; } elsif ($ch =~ /CNP/) { $sm = 'CNP'; } elsif ($ch =~ /3PI/) { my $fooz = $ch; $fooz =~ s/\,.*//g; # reduce multicolor quads to single string my @foo = split /\./, $fooz; if ($ch =~ /^\d+\.3PI\.\d\d\.([\w\+-]+)/) { $sm = $1; } else { $sm = join('.', @foo[0..$#foo - 2]); } } elsif ($ch =~ /SS/ ) { my $fooz = $ch; $fooz =~ s/\,.*//g; # reduce multicolor quads to single string my @foo = split /\./, $fooz; $sm = join('.', @foo[0..$#foo - 2]); } $quadchunkmap{$ch} = { name => $ch, sel => $sm, nfoot => $quads_ingested{$ch} }; } # # Figure out what pairs we have. # my %pairs_ingested; $sth = $dbh->prepare(<<"SQL") or die $dbh->errstr; SELECT survey_mode, footprints FROM chunks_processed WHERE type = 'Pair' SQL $sth->execute() or die $sth->errstr; my $have_pairs; while (my $href = $sth->fetchrow_hashref) { $have_pairs = 1; $pairs_ingested{$href->{survey_mode}} = $href->{footprints}; } $sth->finish; # # This section creates a map of queried pair names to a substring # select for czaring. In other words, the GROUP_CONCAT() of all # survey_modes in a quad may include several survey_modes; this # maps the GROUP_CONCAT() result to a single, shorter string # used to select tracklets for czaring, e.g. # 140.3PI.00.ANE1.Q1.g+140.3PI.00.ANE1 => 140.3PI.00.ANE1.Q # my %pairchunkmap; foreach my $ch (keys %pairs_ingested) { next if $ch =~ /MD/ or (!$guru and $ch =~ /(z|y)$/); $sm = $ch; $pairchunkmap{$ch} = { name => $ch, sel => $sm, nfoot => $pairs_ingested{$ch} }; } sub get_nearest_nn_offset { # return the offset to the TJD in the direction specified (forward or backward) from the # specified TJD. Dir should simply be 1 or -1. Return none if there is no data in that direction. my ($dbh, $nn, $dir) = @_; my $foo; my $off; if ($dir > 0) { $foo = $dbh->selectcol_arrayref(<<"SQL") or die $dbh->errstr; select nn from fields where nn > $nn order by nn limit 1 SQL } else { $foo = $dbh->selectcol_arrayref(<<"SQL") or die $dbh->errstr; select nn from fields where nn < $nn order by nn desc limit 1 SQL } if ($foo && $foo->[0]) { $off = $foo->[0] - $nn; # offset from current night } return $off; } sub make_nice_date_str { my ($mjd) = @_; my $unixtime = ($mjd - 40587) * 86400; # seconds since Unix epoch (40587 => Unix epoch Jan 1 1970) return uc strftime("%a %d %b %Y UT", gmtime($unixtime)); }