chiark / gitweb /
Permit entry of loss per league
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 2 Sep 2009 23:17:06 +0000 (00:17 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 2 Sep 2009 23:17:06 +0000 (00:17 +0100)
yarrg/web/check_lossperleague [new file with mode: 0644]
yarrg/web/lookup
yarrg/web/qtextstringcheck
yarrg/web/query_route
yarrg/web/routetrade

diff --git a/yarrg/web/check_lossperleague b/yarrg/web/check_lossperleague
new file mode 100644 (file)
index 0000000..aaeb5b0
--- /dev/null
@@ -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 <ijackson@chiark.greenend.org.uk>
+ 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 <http://www.gnu.org/licenses/>.
+
+ 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.
+
+</%doc>
+
+<%attr>
+</%attr>
+
+<%method preparse>
+<%args>
+$h
+</%args>
+<%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;
+}
+
+</%perl>
+</%method>
index 39da2e9699bc4a599e6360ca63f774d27df3cef3..35b6ce7039c2fb6eea242d4560f77668e72bb26c 100755 (executable)
@@ -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 |
index a6c84fe44ba9775f434bc5ff3ac06aad64bc36a6..a489d8e1232940e6c603c44e05f43eed3add47b9 100755 (executable)
@@ -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);
 }
 
index 759c9c547cbd92f01f39a6e9bda8e900a651d6d5..a65ef1c5723d9360e4566152d294ac0fd1350112 100644 (file)
@@ -39,6 +39,7 @@ $dbh
 $prselector
 $routestring => '';
 $capacitystring => '';
+$lossperleague => '';
 $someresults
 $emsgokorprint
 </%args>
@@ -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
 </&>
 
+<table>
+<tr>
+<td>
+
 Vessel capacity:
 <&| qtextstring, qa => $qa, dbh => $dbh, prefix => 'cs',
     thingstring => 'capacitystring', emsgstore => \$emsg,
@@ -95,6 +101,21 @@ Vessel capacity:
  &>
 </&>
 
+<td>
+&nbsp;
+&nbsp;
+
+<td>
+Estimated loss per league:
+
+<&| qtextstring, qa => $qa, dbh => $dbh, prefix => 'll',
+    thingstring => 'lossperleague', emsgstore => \$emsg,
+    perresult => sub { ($lossperleaguepct)= @_; }
+ &>
+</&>
+
+</table>
+
 % } else { #---------- dropdowns, user selects from menus ----------
 
 % $startform->(grep {
@@ -193,7 +214,7 @@ function ms_Setarch(dd) {
 
 <input type=submit name=submit value="<% $goupdate->() %>">
 % 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
  &>
 </form>
 % }
index 7e1a06e6b90fd5cd872bb5ca78048667a3018a6e..9a6824e97ced58bb08b3e84b11e43f975fe8505f 100644 (file)
@@ -40,6 +40,7 @@ $dbh
 $qa
 $max_mass
 $max_volume
+$lossperleaguepct
 </%args>
 <&| script &>
   da_pageload= Date.now();
@@ -49,6 +50,11 @@ $max_volume
 <strong>WARNING - VESSEL CAPACITY LIMIT NOT YET IMPLEMENTED</strong>
 <p>
 % }
+% if (defined $lossperleaguepct) {
+<strong>WARNING - DEFINED LOSS PER LEAGUE NOT YET IMPLEMENTED</strong>
+<% $lossperleaguepct |h %>
+<p>
+% }
 
 <%perl>