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

All Chunks By Observation Time
% foreach my $k (@chunks_ingested) { % my ($start_time_str) = mopslib_mjd2utctimestr($k->{start_mjd}, '='); # use = as delimiter bewteen date and time % $start_time_str =~ s/^.*=//; % $start_time_str = $1 if $start_time_str =~ /^(\d\d:\d\d)/; % $start_time_str .= ' UT'; % }
Chunk Name Obs Time (UT) Last Processing Status Num Exposures
<% $k->{cn} %> <% $start_time_str %> <% $statmap{$k->{status}} || 'UNKNOWN' %> <% $k->{ct} %>

By Run ID
% my $rk; % foreach $rk (sort {$b <=> $a} keys %runs_all) { % if ($have_runs) { % } % if (exists $runs_quad{$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); % } % } % if (exists $runs_md{$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); % } % } % if (exists $runs_pair{$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; % } % }
<% $rk ? (sprintf "Run %d updated %s", $rk, $runs_all{$rk}[0]{updated}): '' %>
Chunk Name Type Status Footprints
<% qq{$ch} %> QUAD <% $statmap{$runs_quad{$rk}[$i]{status}} || 'UNKNOWN' %> <% $qct %>
<% qq{$ch} %> MD <% $statmap{$runs_md{$rk}[$i]{status}} || 'UNKNOWN' %> <% $mct %>
% if (!$runs_pair{$rk}[$i]{needguru} || $guru) { <% qq{$ch} %> % } else { <% qq{$ch} %> % } PAIR <% $statmap{$runs_pair{$rk}[$i]{status}} || 'UNKNOWN' %> <% $pct %>

% }

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', X => 'SKIP', ); my $inst = $m->notes('INST'); my $mc = $inst->getConfig(); my $gmt_offset_hours = $mc->{site}->{gmt_offset_hours} || die "can't get gmt_offset_hours"; 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, min(time_start) start_mjd, count(*) ct from fields where nn=? group by survey_mode, status order by epoch_mjd 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}, start_mjd => $href->{start_mjd}, ct => $href->{ct} }; } $sth->finish; # See if we actually have a runs table. Old MOPS DBs don't. my $have_runs = $dbh->selectrow_array(<<"SQL", undef, $model, 'runs'); SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ? SQL if ($have_runs) { # Require non-empty runs table. ($have_runs) = $dbh->selectrow_array("select count(*) from runs r join fields f using(field_id) where f.nn=?", undef, $nn); } #CREATE TEMPORARY TABLE norep_chunks_processed #(run_id BIGINT, # survey_mode VARCHAR(120), # type VARCHAR(120), # status CHAR, # footprints INT, # updated TIMESTAMP) # Gather information about all chunks. my @norep_chunks_processed; # proxy for former temp table if ($have_runs) { $sth = $dbh->prepare(<<"SQL") or die $dbh->errstr; SELECT temp.run_id run_id, temp.quad_name survey_mode, status, type, count(*) footprints, max(run_date) updated FROM ( SELECT run_id, group_concat(distinct survey_mode order by survey_mode separator ' ') quad_name, r.run_date run_date, 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 } else { $sth = $dbh->prepare(<<"SQL") or die $dbh->errstr; SELECT temp.run_id run_id, temp.quad_name survey_mode, status, type, count(*) footprints, max(run_date) updated FROM ( SELECT 1 run_id, group_concat(distinct survey_mode order by survey_mode separator ' ') quad_name, current_timestamp() run_date, f.status, IF(survey_mode LIKE 'MD%', 'MD', 'Quad') type FROM fields f WHERE nn=? GROUP BY IF(parent_id is null, field_id, parent_id) HAVING count(*) >= 3 ) AS temp GROUP BY quad_name SQL } $sth->execute($nn) or die $sth->errstr; while (my $href = $sth->fetchrow_hashref) { push @norep_chunks_processed, $href; } $sth->finish; # Get chunk+run info. if ($have_runs) { $sth = $dbh->prepare(<<"SQL") or die $dbh->errstr; SELECT temp.run_id run_id, temp.quad_name survey_mode, status, type, count(*) footprints, max(run_date) updated FROM ( SELECT run_id, group_concat(distinct survey_mode order by survey_mode separator ' ') quad_name, r.run_date run_date, 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 } else { $sth = $dbh->prepare(<<"SQL") or die $dbh->errstr; SELECT temp.run_id run_id, temp.quad_name survey_mode, status, type, count(*) footprints, max(run_date) updated FROM ( SELECT 1 run_id, group_concat(distinct survey_mode order by survey_mode separator ' ') quad_name, current_timestamp() run_date, f.status, 'Pair' type FROM fields f WHERE nn=? GROUP BY IF(parent_id is null, field_id, parent_id) HAVING count(*) = 2) AS temp GROUP BY quad_name SQL } $sth->execute($nn) or die $sth->errstr; while (my $href = $sth->fetchrow_hashref) { push @norep_chunks_processed, $href; } $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, %runs_all, @sorted); @sorted = sort { $a->{run_id} <=> $b->{run_id} } @norep_chunks_processed; while (my $href = shift @sorted) { my %run_data = ( name => $href->{survey_mode}, status => $href->{status}, updated => $href->{updated}); if ($href->{type} eq "Quad") { push @{$runs_quad{$href->{run_id}}}, { %run_data }; push @{$runs_all{$href->{run_id}}}, { %run_data }; } elsif ($href->{type} eq "MD") { push @{$runs_md{$href->{run_id}}}, { %run_data }; push @{$runs_all{$href->{run_id}}}, { %run_data }; } elsif ($href->{survey_mode} !~ /(z|y)$/) { push @{$runs_pair{$href->{run_id}}}, { %run_data }; push @{$runs_all{$href->{run_id}}}, { %run_data }; } else { # Guru chunks, especially difficult to czar. push @{$runs_pair{$href->{run_id}}}, { %run_data, needguru => 1 }; push @{$runs_all{$href->{run_id}}}, { %run_data, needguru => 1 }; } } # # Figure out what quads we have. # my %quads_ingested; my $have_mds; my $have_quads; @sorted = grep { $_->{type} =~ /MD|Quad/ } @norep_chunks_processed; while (my $href = shift @sorted) { if ($href->{survey_mode} =~ /^MD/) { $have_mds = 1; } else { $have_quads = 1; } $quads_ingested{$href->{survey_mode}} = $href->{footprints}; } # # 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/) { # Break the multicolor quad into its two components which are seperated by a comma. $ch =~ m/\,(.*)/; my $visit = $1; my @components = split /\./, $visit; if ($ch =~ /^\d+\.3PI\.\d\d\.([\w\+-]+)/) { $sm = $1; } else { $sm = join('.', @components[0..$#components - 2]); } } elsif ($ch =~ /SS/ ) { # $ch =~ m/\,(.*)/; # my $visit = $1; my @components = split /\./, $ch; $sm = join('.', @components[0..$#components - 2]); } $quadchunkmap{$ch} = { name => $ch, sel => $sm, nfoot => $quads_ingested{$ch} }; } # # Figure out what pairs we have. # my %pairs_ingested; my $have_pairs; @sorted = grep { $_->{type} eq 'Pair' } @norep_chunks_processed; while (my $href = shift @sorted) { $have_pairs = 1; $pairs_ingested{$href->{survey_mode}} = $href->{footprints}; } # # 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)); }