From 099cd920655c1db6da4a1a57ec3baa30d16321d7 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 3 Sep 2009 00:17:06 +0100 Subject: [PATCH] Permit entry of loss per league --- yarrg/web/check_lossperleague | 65 +++++++++++++++++++++++++++++++++++ yarrg/web/lookup | 1 + yarrg/web/qtextstringcheck | 7 ++-- yarrg/web/query_route | 26 ++++++++++++-- yarrg/web/routetrade | 6 ++++ 5 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 yarrg/web/check_lossperleague diff --git a/yarrg/web/check_lossperleague b/yarrg/web/check_lossperleague new file mode 100644 index 0000000..aaeb5b0 --- /dev/null +++ b/yarrg/web/check_lossperleague @@ -0,0 +1,65 @@ +<%doc> + + This is part of the YARRG website. YARRG is a tool and website + for assisting players of Yohoho Puzzle Pirates. + + Copyright (C) 2009 Ian Jackson + Copyright (C) 2009 Clare Boothby + + YARRG's client code etc. is covered by the ordinary GNU GPL (v3 or later). + The YARRG website is covered by the GNU Affero GPL v3 or later, which + basically means that every installation of the website will let you + download the source. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + + Yohoho and Puzzle Pirates are probably trademarks of Three Rings and + are used without permission. This program is not endorsed or + sponsored by Three Rings. + + + This Mason component simply defines how to interpret capacities. + + + +<%attr> + + +<%method preparse> +<%args> +$h + +<%perl> + +$_= ${ $h->{String} }; +s/^\s+//; s/\s+$//; + +my $res= sub { + my ($pct,$str) = @_; + push @{ $h->{Results} }, [ $pct ]; + ${ $h->{Canon} }= "Considering expected losses of $str per league"; +}; + +if (!m/\S/) { +} elsif (m/^(\d{1,2}(?:\.\d{0,5})?)\%$/) { + $res->( $1 * 1.0, sprintf("%g%%", $1) ); +} elsif (m/^1\s*\/\s*([1-9]\d{0,4})/) { + $res->( 100.0/$1, sprintf("1/%d", $1) ); +} else { + ${ $h->{Emsg} }= "Cannot understand loss per league \`$_'."; + return; +} + + + diff --git a/yarrg/web/lookup b/yarrg/web/lookup index 39da2e9..35b6ce7 100755 --- a/yarrg/web/lookup +++ b/yarrg/web/lookup @@ -154,6 +154,7 @@ foreach my $var (@vars) { foreach my $var (keys %ARGS) { next unless $var =~ m/^(?: (?:route|commod|capacity)string | + lossperleague | commodid | islandid \d | archipelago \d | diff --git a/yarrg/web/qtextstringcheck b/yarrg/web/qtextstringcheck index a6c84fe..a489d8e 100755 --- a/yarrg/web/qtextstringcheck +++ b/yarrg/web/qtextstringcheck @@ -74,8 +74,10 @@ if ($chk->method_exists('sqlstmt')) { my $emsg= ''; my @results; my @specs; +my $canontext; my $hooks = { Emsg => \$emsg, String => \$string, Results => \@results, Specs => \@specs, + Canon => \$canontext }; if ($chk->method_exists('preparse')) { @@ -114,9 +116,10 @@ foreach my $each (@specs) { push @results, $results->[0]; }; -my $canontext= join ' | ', map { $_->[0] } @results; +if (!defined $canontext) { + $canontext= join ' | ', map { $_->[0] } @results; +} if ($chk->method_exists('postquery')) { - $hooks->{Canon}= \$canontext; $chk->call_method('postquery', h => $hooks); } diff --git a/yarrg/web/query_route b/yarrg/web/query_route index 759c9c5..a65ef1c 100644 --- a/yarrg/web/query_route +++ b/yarrg/web/query_route @@ -39,6 +39,7 @@ $dbh $prselector $routestring => ''; $capacitystring => ''; +$lossperleague => ''; $someresults $emsgokorprint @@ -49,6 +50,7 @@ my @archipelagoes; my @islandids; my %islandid2; my ($max_volume, $max_mass); +my $lossperleaguepct; my $qa= \%ARGS; @@ -86,6 +88,10 @@ Enter route (islands, or archipelagoes, separated by |s or commas; size=80 + + +
+ Vessel capacity: <&| qtextstring, qa => $qa, dbh => $dbh, prefix => 'cs', thingstring => 'capacitystring', emsgstore => \$emsg, @@ -95,6 +101,21 @@ Vessel capacity: &> + +  +  + + +Estimated loss per league: + +<&| qtextstring, qa => $qa, dbh => $dbh, prefix => 'll', + thingstring => 'lossperleague', emsgstore => \$emsg, + perresult => sub { ($lossperleaguepct)= @_; } + &> + + +
+ % } else { #---------- dropdowns, user selects from menus ---------- % $startform->(grep { @@ -193,7 +214,7 @@ function ms_Setarch(dd) { % my $ours= sub { $_[0] =~ -% m/^island|^archipelago|^routestring|^capacitystring|^[RT]/; +% m/^island|^archipelago|^routestring|^capacitystring|^lossperleague|^[RT]/; % }; <& "lookup:formhidden", ours => $ours &> @@ -240,7 +261,8 @@ for my $dd (0..$qa->{Dropdowns}-1) { archipelagoes => \@archipelagoes, qa => $qa, max_mass => $max_mass, - max_volume => $max_volume + max_volume => $max_volume, + lossperleaguepct => $lossperleaguepct &> % } diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index 7e1a06e..9a6824e 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -40,6 +40,7 @@ $dbh $qa $max_mass $max_volume +$lossperleaguepct <&| script &> da_pageload= Date.now(); @@ -49,6 +50,11 @@ $max_volume WARNING - VESSEL CAPACITY LIMIT NOT YET IMPLEMENTED

% } +% if (defined $lossperleaguepct) { +WARNING - DEFINED LOSS PER LEAGUE NOT YET IMPLEMENTED +<% $lossperleaguepct |h %> +

+% } <%perl> -- 2.30.2