X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.main.git;a=blobdiff_plain;f=yarrg%2Fweb%2Fquery_routesearch;h=6877536b14b20068ecda828c8a72a7364c58ecc1;hp=af18d36193c5a7f16ad05e38ce7a275421de566e;hb=9326add47a682bbbe4ffc0b1408ea661994474dd;hpb=e0e0711ed505eb9de89ac5a26848b30785e58816 diff --git a/yarrg/web/query_routesearch b/yarrg/web/query_routesearch index af18d36..6877536 100644 --- a/yarrg/web/query_routesearch +++ b/yarrg/web/query_routesearch @@ -52,10 +52,13 @@ my $emsg; my @warningfs; my @islandids; +my $maxmaxdist=35; +my $maxcpu=90; + my $qa= \%ARGS; my $routeparams= { EmsgRef => \$emsg, SayRequiredCapacity => 1 }; my $maxdist; -my $maxcountea=10; +my $maxcountea=15; @@ -94,8 +97,8 @@ This feature is not available from the "drop down menus" interface. <%perl> -if (!$emsg && $maxdist > 30) { - $emsg= "Searching for routes of more than 30 leagues is not". +if (!$emsg && $maxdist > $maxmaxdist) { + $emsg= "Searching for routes of more than $maxmaxdist leagues is not". " supported, sorry."; } @@ -103,9 +106,26 @@ $emsgokorprint->($emsg) or return; @islandids or return; defined $routeparams->{MaxMass} or defined $routeparams->{MaxVolume} or return; +#---------- prepare island names ---------- + +my $islandname_stmt= $dbh->prepare(<execute($id); + my $row= $islandname_stmt->fetchrow_hashref(); + local $_= $row->{'islandname'}; + s/ Island$//; + return $_, $row->{'archipelago'}; +}; + #---------- compute the results ---------- -my @rsargs; +my @rsargs= qw(-DN); foreach my $k (qw(MaxMass MaxVolume MaxCapital)) { my $v= $routeparams->{$k}; @@ -113,20 +133,19 @@ foreach my $k (qw(MaxMass MaxVolume MaxCapital)) { } push @rsargs, defined $routeparams->{LossPerLeaguePct} ? $routeparams->{LossPerLeaguePct}*0.01 : 1e-9; -push @rsargs, 'search', $maxcountea,$maxcountea, $maxdist, 'any', @islandids; +push @rsargs, '0'; +push @rsargs, 'search',$maxdist, $maxcountea,$maxcountea, 'any', @islandids; m/[^-.0-9a-zA-Z]/ and die "$_ $& ?" foreach @rsargs; -unshift @rsargs, dbw_filename($qa->{'Ocean'}); -unshift @rsargs, qw(-DN); - if ($qa->{'debug'}) { [[ <% "@rsargs" |h %> ]]
 <%perl>
 }
 
-unshift @rsargs, sourcebasedir().'/yarrg/routesearch';
+unshift @rsargs, sourcebasedir().'/yarrg/routesearch',
+	'-d', dbw_filename($qa->{'Ocean'});
 
 my %results; # $results{$ap}{"5 6 9 10"} = { stuff }
 
@@ -135,8 +154,7 @@ my $child= $fh->open("-|"); defined $child or die $!;
 if (!$child) {
 	my $cpu= BSD::Resource::RLIMIT_CPU;
 	my ($soft,$hard)= getrlimit($cpu);
-	my $max=10;
-	setrlimit($cpu,$max,$hard) or die $! if $soft>$max;
+	setrlimit($cpu,$maxcpu,$hard) or die $! if $hard<=$maxcpu;
 	exec @rsargs;
 	die $!;
 }
@@ -153,7 +171,21 @@ while (<$fh>) {
 	my ($ap,$isles) = (uc $1,$4);
 	next if $results{$ap} && %{$results{$ap}} >= $maxcountea;
 	my $item= { A => $2, P => $3 };
-#	my @isles= map { @islenames[$_] }, split / /, @isles;
+	my (@i, @a);
+	foreach (split / /, $isles) {
+		my ($name,$arch)= $isleinfo->($_);
+		push @i, $name;
+		push @a, $arch unless @a && $a[-1] eq $arch;
+	}
+	$item->{Isles}= [ @i ];
+	$item->{Archs}= [ @a ];
+	$item->{Start}= $i[0];
+	$item->{Finish}= $i[-1];
+	$item->{Vias}= [ ];
+	my $i;
+	for ($i=1; $i < @i-1; $i++) {
+		push @{ $item->{Vias} }, $i[$i];
+	}
 	$results{$ap}{$isles}= $item;
 }
 
@@ -164,17 +196,38 @@ if ($qa->{'debug'}) {
 
 % foreach my $ap (qw(A P)) {
 

ap=<% $ap %>

- +
++++ + + + +% my $datarow=0; % foreach my $isles (sort { -% $results{$ap}{$a}{Values}{$ap} <=> -% $results{$ap}{$b}{Values}{$ap} +% $results{$ap}{$b}{$ap} <=> +% $results{$ap}{$a}{$ap} % } keys %{$results{$ap}}) { % my $item= $results{$ap}{$isles}; - + +% $datarow ^= 1; % } # $isles
Profit +Archipelagoes +Route +
Abs. +Per.lg. + +Start +Via +Finish +
<% $item->{A} |h %> <% $item->{P} |h %> -<% $isles |h %> +<% join ', ', @{ $item->{Archs} } |h %> +<% $item->{Start} |h %>, +<% join ' ', map { $_.',' } @{ $item->{Vias} } |h %> +<% $item->{Finish} |h %>
% } # $ap