& /htmlheader, title => "TJD $tjd $model" &>
<& modelheader &>
|
<% $tjd_str %>
% foreach my $k (@chunks_ingested) {
| <% $k->{cn} %> |
<% $statmap{$k->{status}} || 'UNKNOWN' %> |
<% $k->{ct} %> |
% }
Czaring
% if ($have_quads) {
- All Quads
% foreach my $qk (sort keys %quadchunkmap) {
% my ($qv) = $quadchunkmap{$qk};
% my $ch = $qv->{name}; my $qct = $qv->{nfoot};
% my $urlenc = $qv->{sel}; $urlenc = uri_escape($urlenc);
<% qq{- $ch ($qct footprint} . ($qct > 1 ? 's' : '') . qq{)} %>
% }
- Slow Movers (experts only)
% }
% if ($have_mds) {
- MDs
% }
% if ($have_pairs) {
- Pairs (experimental)
% foreach my $pk (sort keys %pairchunkmap) {
% my ($pv) = $pairchunkmap{$pk};
% my $ch = $pv->{name}; my $pct = $pv->{nfoot};
% my $urlenc = $pv->{sel}; $urlenc = uri_escape($urlenc);
% my $pminv = $guru ? .15 : .3;
<% qq{- $ch ($pct footprint} . ($pct > 1 ? 's' : '') . qq{)} %>
% }
% }
Comets MBOs | Unknown (Diff | Chip)
Derived Objects (<% $tjd %> only, OC <% $ocnum %>)
Known Pairs
Submitted NEOs
Efficiency
Custom
|
|
% 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
%args>
<%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} };
}
# Figure out what quads we have.
my %quads_ingested;
$sth = $dbh->prepare(<<"SQL") or die $dbh->errstr;
select q1.quad_name survey_mode, count(*) ct
from
(select group_concat(distinct survey_mode order by survey_mode separator ',') quad_name
from fields
where nn=?
group by if(parent_id is null, field_id, parent_id)
having count(*) >= 3)
as q1
group by quad_name
SQL
$sth->execute($nn) or die $sth->errstr;
my $have_mds;
my $have_quads;
while (my $href = $sth->fetchrow_hashref) {
if ($href->{survey_mode} =~ /^MD/) {
$have_mds = 1;
}
else {
$have_quads = 1;
}
$quads_ingested{$href->{survey_mode}} = $href->{ct};
}
# 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) {
next if $ch =~ /MD/;
if ($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 p1.pair_name survey_mode, count(*) ct
from
(select group_concat(distinct survey_mode order by survey_mode separator ',') pair_name
from fields
where nn=?
group by if(parent_id is null, field_id, parent_id)
having count(*) = 2)
as p1
group by pair_name
SQL
$sth->execute($nn) or die $sth->errstr;
my $have_pairs;
while (my $href = $sth->fetchrow_hashref) {
$have_pairs = 1;
$pairs_ingested{$href->{survey_mode}} = $href->{ct};
}
# 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;
# if ($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]);
# }
$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));
}
%init>