<& /htmlheader &> <& modelheader &>

### First <% $limit %> attributed known objects, sorted by <% $sortby %>.

Name/Designation (sort) | q (AU) (sort) | e | i (deg) | hV (deg) | Num Tracklets (sort)
--- | --- | --- | --- | --- | ---
<%perl> print foreach (@stuff); # print all rows

<& /htmlfooter &> <%args> $sortby => 'num' $desc => 0 $limit => 1000 <%init> use Data::Dumper; my $inst = $m->notes('INST'); my $dbh = $inst->dbh(); my %stuff; # Create a query from the DB, and create HTML schtuff. my $href; my $sth = $dbh->prepare("select k.known_id known_id, k.known_name known_name, k.q q, k.e e, k.i i, k.h_v h_v, count(t.tracklet_id) num_trk from tracklets t join known k using (known_id) group by known_id") or die $dbh->errstr; $sth->execute() or die $sth->errstr; my %known_stuff; while ($href = $sth->fetchrow_hashref()) { $known_stuff{$href->{known_id}} = $href; } my @keys; if ($sortby eq 'num') { @keys = sort { $known_stuff{$a}->{num_trk} <=> $known_stuff{$b}->{num_trk} } keys %known_stuff; } elsif ($sortby eq 'q') { @keys = sort { $known_stuff{$a}->{q} <=> $known_stuff{$b}->{q} } keys %known_stuff; } else { @keys = sort { $known_stuff{$a}->{known_name} cmp $known_stuff{$b}->{known_name} } keys %known_stuff; } @keys = reverse @keys if ($desc); $limit = $#keys if $limit and $limit > scalar @keys; @keys = @keys[0..$limit]; my @stuff; # Make HTML, put back in @stuff. my ($q, $e, $i, $h_v); if ($sortby eq 'num') { foreach my $k (@keys) { $q = sprintf "%.4f", $known_stuff{$k}->{q}; $e = sprintf "%.4f", $known_stuff{$k}->{e}; $i = sprintf "%.4f", $known_stuff{$k}->{i}; $h_v = sprintf "%.2f", $known_stuff{$k}->{h_v}; push @stuff, <<"HTML";
$known_stuff{$k}->{known_name} $q $e $i $h_v $known_stuff{$k}->{num_trk}
HTML } } elsif ($sortby eq 'q') { # Same as above, but sorted by known name. foreach my $k (@keys) { $q = sprintf "%.4f", $known_stuff{$k}->{q}; $e = sprintf "%.4f", $known_stuff{$k}->{e}; $i = sprintf "%.4f", $known_stuff{$k}->{i}; $h_v = sprintf "%.2f", $known_stuff{$k}->{h_v}; push @stuff, <<"HTML";
$known_stuff{$k}->{known_name} $q $e $i $h_v $known_stuff{$k}->{num_trk}
HTML } } else { # Same as above, but sorted by known name. foreach my $k (@keys) { $q = sprintf "%.4f", $known_stuff{$k}->{q}; $e = sprintf "%.4f", $known_stuff{$k}->{e}; $i = sprintf "%.4f", $known_stuff{$k}->{i}; $h_v = sprintf "%.2f", $known_stuff{$k}->{h_v}; push @stuff, <<"HTML";
$known_stuff{$k}->{known_name} $q $e $i $h_v $known_stuff{$k}->{num_trk}
HTML } }