chiark / gitweb /
routesearch: nice routesearch
[ypp-sc-tools.main.git] / yarrg / web / query_routesearch
index 8937f285e9f9c77e6f3a77585b5471b6bd3de44e..36e6055b898610a3ccb2910e641203f9923bbddd 100644 (file)
 <%args>
 $quri
 $dbh
+$queryqf
 $islandstring => '';
 $capacitystring => '';
 $lossperleague => '';
 $capitalstring => '';
 $distance => '';
-$someresults
 $emsgokorprint
 </%args>
 
@@ -121,7 +121,7 @@ my $isleinfo = sub {
        my $row= $islandname_stmt->fetchrow_hashref();
        local $_= $row->{'islandname'};
        s/ Island$//;
-       return $_, $row->{'archipelago'};
+       return $_, $row->{'islandname'}, $row->{'archipelago'};
 };
 
 #---------- compute the results ----------
@@ -147,7 +147,7 @@ if ($qa->{'debug'}) {
 }
 
 unshift @rsargs,
-       sourcebasedir().'/yarrg/routesearch',
+       'nice', sourcebasedir().'/yarrg/routesearch',
        '-d', dbw_filename($qa->{'Ocean'}),
        '-C', webdatadir().'/_concur.', '.lock';
 
@@ -182,10 +182,11 @@ while (<$fh>) {
        my ($ap,$isles) = (uc $1,$5);
        next if $results{$ap} && %{$results{$ap}} >= $maxcountea;
        my $item= { A => $3, P => $4, Leagues => $2 };
-       my (@i, @a);
+       my (@i, @fi, @a);
        foreach (split / /, $isles) {
-               my ($name,$arch)= $isleinfo->($_);
+               my ($name,$fullname,$arch)= $isleinfo->($_);
                push @i, $name;
+               push @fi, $fullname;
                push @a, $arch unless @a && $a[-1] eq $arch;
        }
        $item->{Isles}= [ @i ];
@@ -197,6 +198,10 @@ while (<$fh>) {
        for ($i=1; $i < @i-1; $i++) {
                push @{ $item->{Vias} }, $i[$i];
        }
+       my %linkqf= %$queryqf;
+       delete $linkqf{'query'};
+       $linkqf{'routestring'}= join ', ', @fi;
+       $item->{Url}= $quri->(%linkqf);
        $results{$ap}{$isles}= $item;
 }
 
@@ -204,6 +209,26 @@ if ($qa->{'debug'}) {
        print "</pre>\n";
 }
 
+$!=0;
+if (!close $fh) {
+       die $! if $!;
+       die $? if $? != 24; # SIGXCPU but not in POSIX.pm :-/
+</%perl>
+<h2>Search took too long and was terminated</h2>
+
+Sorry, but your query resulted in a search that took too long.
+Searches are limited to <% $maxcpu |h %> seconds of CPU time to
+avoid them consuming excessive resources on the server system, and to
+make sure that shorter searches can still happen.
+
+<p>
+Please try a search with a smaller minimum distance, or place more
+restrictions on the route.
+
+<%perl>
+       return;
+}
+
 if ($concur_fail) {
 </%perl>
 <h2>Server too busy</h2>
@@ -229,7 +254,11 @@ seconds of CPU time so more processing resources should be available soon.
 
 </%perl>
 % foreach my $ap (qw(A P)) {
-<h2>ap=<% $ap %></h2>
+%      if ($ap eq 'A') {
+<h2>Best routes for total profit</h2>
+%      } else {
+<h2>Best routes for profit per league</h2>
+%      }
 <table rules=groups>
 <colgroup span=2>
 <colgroup span=1>
@@ -260,7 +289,7 @@ seconds of CPU time so more processing resources should be available soon.
 <td align=right><% $item->{A} |h %>
 <td align=right><% $item->{P} |h %>
 <td align=right><% $item->{Leagues} |h %>
-<td align=left><% join ', ', @{ $item->{Archs} } |h %>
+<td align=left><a href="<% $item->{Url} |h %>"><% join ', ', @{ $item->{Archs} } |h %></a>
 <td align=left><% $item->{Start} |h %>,
 <td align=left><% join ' ', map { $_.',' } @{ $item->{Vias} } |h %>
 <td align=left><% $item->{Finish} |h %>
@@ -269,6 +298,16 @@ seconds of CPU time so more processing resources should be available soon.
 %      } # $isles
 </table>
 % } # $ap
+
+<p>
+
+<h2>Notes</h2>
+
+Per league values count each island visited as one
+(additional) league; the `Dist.' column is however the actual distance
+to be sailed.  All profit figures are somewhat approximate; get a
+complete trading plan for a route for accurate information.
+
 <%perl>