From f7c3c04f684b0e9cac4518beeece11853ef75109 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 18 Oct 2009 17:49:02 +0100 Subject: [PATCH] printable trading plans --- yarrg/CommodsWeb.pm | 11 +- yarrg/TODO | 6 - yarrg/example-plan.html | 315 ---------------------------------------- yarrg/web/autohandler | 48 +++++- yarrg/web/lookup | 5 + yarrg/web/qtextstring | 6 + yarrg/web/routetrade | 37 +++-- yarrg/web/script | 14 +- 8 files changed, 96 insertions(+), 346 deletions(-) delete mode 100644 yarrg/example-plan.html diff --git a/yarrg/CommodsWeb.pm b/yarrg/CommodsWeb.pm index 0f3f43d..37bbfe7 100644 --- a/yarrg/CommodsWeb.pm +++ b/yarrg/CommodsWeb.pm @@ -50,7 +50,7 @@ BEGIN { @ISA = qw(Exporter); @EXPORT = qw(&dbw_connect &dbw_filename &ocean_list &sourcebasedir &to_json_shim &to_json_protecttags - &set_ctype_utf8 &webdatadir + &set_ctype_utf8 &webdatadir &printable &expected_error &dbw_lookup_string &prettyprint_age &meta_prettyprint_age); %EXPORT_TAGS = ( ); @@ -200,6 +200,15 @@ sub expected_error ($) { die $r; } +sub printable ($) { # printable($m) where $m is the Mason request object + my ($m) = @_; + my $a= scalar $m->caller_args(-1); + foreach my $t (qw(pdf ps html)) { + return $t if $a->{"printable_$t"}; + } + return 0; +} + package CommodsWeb::ExpectedError; sub emsg ($) { diff --git a/yarrg/TODO b/yarrg/TODO index 1486d1a..b202aad 100644 --- a/yarrg/TODO +++ b/yarrg/TODO @@ -1,9 +1,3 @@ - -printable trading plan - curl -s 'http://yarrg.chiark.net/lookup?routestring=eta%2C+jorvik&capacitystring=&lossperleague=&capitalstring=&submit=Go' >example-plan.html - /' | htmldoc >t.ps -t pdf --continuous --gray --size 210x279mm --nup 2 - - - UPLOADER -------- diff --git a/yarrg/example-plan.html b/yarrg/example-plan.html deleted file mode 100644 index 7187c8c..0000000 --- a/yarrg/example-plan.html +++ /dev/null @@ -1,315 +0,0 @@ - - - - - - -Trades for route - YARRG - - - - -QUERY HERE - - -commit 8198bdb1afdf8ebedb130006e3af2af6b11045ab -Author: Ian Jackson -Date: Thu Sep 24 19:01:44 2009 +0100 - - Use full URLs for query sites - -commit 207dec6556d4642ce7223e243f08af3bbe8fd157 -Author: Ian Jackson -Date: Thu Sep 24 19:00:12 2009 +0100 - - YARRG website is fine - -commit 19c49821438f668c75868ca696bd0b06c6a47d2a -Author: Ian Jackson -Date: Thu Sep 24 18:58:48 2009 +0100 - - Document that we actually upload to the main PCTB db - -commit 68843821b559b609abb26e50ed20171b108fb60c -Author: Ian Jackson -Date: Wed Sep 23 20:58:09 2009 +0100 - - Switch to main PCTB server now we are approved - -commit 016f2797ee2dfea8948bbb1247eaa9fc5234a35a -Author: Ian Jackson -Date: Thu Sep 24 00:09:43 2009 +0100 - - Dump bogus XML in _commodmap.xml if we can't parse it - -commit 938b4dd547bfc4d9538a5714b6f21ab3da50d8d1 -Author: Ian Jackson -Date: Wed Sep 23 23:55:45 2009 +0100 - - Better HTTP User-Agent strings (rot13 the library, say who we are) - -commit c810347487961a59b3d8dfb2fed123f49dc22ed4 -Author: Ian Jackson -Date: Wed Sep 23 15:12:46 2009 +0100 - - Do not allow caller to specify arbitrary content-types - -commit a9a88c14c5a5bd057932f76ad721b5f0fc845c20 -Author: Ian Jackson -Date: Tue Sep 22 15:25:57 2009 +0100 - - Minor html style changes - - -commit 8198bdb1afdf8ebedb130006e3af2af6b11045ab -Author: Ian Jackson -Date: Thu Sep 24 19:01:44 2009 +0100 - - Use full URLs for query sites - -commit 207dec6556d4642ce7223e243f08af3bbe8fd157 -Author: Ian Jackson -Date: Thu Sep 24 19:00:12 2009 +0100 - - YARRG website is fine - -commit 19c49821438f668c75868ca696bd0b06c6a47d2a -Author: Ian Jackson -Date: Thu Sep 24 18:58:48 2009 +0100 - - Document that we actually upload to the main PCTB db - -commit 68843821b559b609abb26e50ed20171b108fb60c -Author: Ian Jackson -Date: Wed Sep 23 20:58:09 2009 +0100 - - Switch to main PCTB server now we are approved - -commit 016f2797ee2dfea8948bbb1247eaa9fc5234a35a -Author: Ian Jackson -Date: Thu Sep 24 00:09:43 2009 +0100 - - Dump bogus XML in _commodmap.xml if we can't parse it - -commit 938b4dd547bfc4d9538a5714b6f21ab3da50d8d1 -Author: Ian Jackson -Date: Wed Sep 23 23:55:45 2009 +0100 - - Better HTTP User-Agent strings (rot13 the library, say who we are) - -commit c810347487961a59b3d8dfb2fed123f49dc22ed4 -Author: Ian Jackson -Date: Wed Sep 23 15:12:46 2009 +0100 - - Do not allow caller to specify arbitrary content-types - -commit a9a88c14c5a5bd057932f76ad721b5f0fc845c20 -Author: Ian Jackson -Date: Tue Sep 22 15:25:57 2009 +0100 - - Minor html style changes - - -

Voyage trading plan

- - - - - - - - - - - - - - - - - - - - - - -
-
-Start at Eta Island -(Data age: 2 days) -
Collect -Wood -Finagle's Distilling Stall -22 poe ea. -276 unit(s) -6072 total -
Samjones's Ironworking Stall -
Collect -Wood -Acute Irony -23 poe ea. -647 unit(s) -14881 total -
Fumundacheez's Ironworking Stall -
Tesla Foils -
-In hold 161525kg, 230750 l. - -Outlay -20953 total -
-
-Sail to Jorvik Island -- 5 leagues, - 22991poe at risk - (Data age: 2 days) -
Deliver -Wood -Biker's Distilling Stall -25 poe ea. -839 unit(s) -20975 total -
Canterbury Ales -
Darkseid's Ironworking Stall -
Spearhalk's Distilling Stall -
Deliver -Wood -Affjordable Furnishing -24 poe ea. -84 unit(s) -2016 total -
Helsingkor -
- -Proceeds -22991 total -
-
Collect -Iron -Helsingkor -14 poe ea. -21 unit(s) -294 total -
Collect -Rambutan -Yggdrasil -51 poe ea. -2 unit(s) -102 total -
- -(Arbitrage) outlay -396 total -
-
Deliver -Iron -Jergs's Ironworking Stall -15 poe ea. -21 unit(s) -315 total -
Deliver -Rambutan -Merchant of Vanir -59 poe ea. -2 unit(s) -118 total -
- -(Arbitrage) proceeds -433 total -
Total distance: 5 leagues. -Overall net cash flow -2075 gain -
- - - - - - - - - -

- - - - - - -


-
-YARRG is Yet Another Revenue Research Gatherer, a project of the -crew Special Circumstances on the Midnight Ocean -and of the Sinister Greenend Organisation. -

- -YARRG is Free Software. -You may share and modify the code and the -website, according to the terms of the GNU General Public Licence and -the GNU Affero General Public Licence respectively (v3 or later). -Note that there is NO WARRANTY. -Please see the YARRG Development webpage for -details of how to obtain the client and server code and full details -of the licences. - -

-YARRG is Copyright 2009 Ian Jackson, Clare Boothby, Steve Early. -Yohoho and Puzzle Pirates are trademarks of Three Rings and are used -without permission. YARRG is not endorsed or sponsored by Three -Rings. - -

- - - diff --git a/yarrg/web/autohandler b/yarrg/web/autohandler index 7344f07..55b9a93 100644 --- a/yarrg/web/autohandler +++ b/yarrg/web/autohandler @@ -33,7 +33,45 @@ copyright message. - +<%perl> + +use CommodsWeb; + +my $printable= printable($m); +if ($printable eq 'pdf' || $printable eq 'ps') { + my $output; + my $got= $m->call_self(\$output); + if ($got) { + my $tmpfile= IO::File::new_tmpfile(); + print $tmpfile $output or die $!; + $tmpfile->flush() or die $!; + seek $tmpfile,0,0 or die $!; + my $htmldoc= open HTMLDOC, "-|"; + defined $htmldoc or die $!; + if (!$htmldoc) { + eval { + $ENV{'HTMLDOC_NOCGI'}=1; + open STDIN, '<&', $tmpfile or die $!; + exec qw(htmldoc -t),$printable,qw( + --continuous --gray --size 210x279mm -); + die $!; + }; + print STDERR "HTMLDOC FAILURE $@"; + _exit(1); + } + my ($data,$read); + $r->content_type($printable eq 'pdf' ? 'application/pdf' : + 'application/postscript'); + while ($read= read HTMLDOC,$data,32768) { print $data; } + defined $read or die $!; + $?=0; $!=0; close HTMLDOC or die "$! $? $output "; + return; + } +} +set_ctype_utf8(); +$r->content_type('text/html; charset=UTF-8'); + + -% $m->call_next; - -<%init> -use CommodsWeb; -set_ctype_utf8(); -$r->content_type('text/html; charset=UTF-8'); - +% $m->call_next(); diff --git a/yarrg/web/lookup b/yarrg/web/lookup index 2f67760..a2ccc8d 100755 --- a/yarrg/web/lookup +++ b/yarrg/web/lookup @@ -146,6 +146,7 @@ tr.datarow1 { background: #ffffff; } +% if (!printable($m)) { YARRG - Yet Another Revenue Research Gatherer | @@ -155,6 +156,7 @@ tr.datarow1 { background: #ffffff; } | development

+% } <%perl> foreach my $var (@vars) { @@ -186,6 +188,7 @@ my $quri= sub { my $prselector_core= sub { my ($var)= @_; + return if printable($m); my $name= $var->{Name}; my $lname= lc $var->{Name}; my $delim= $var->{Before}; @@ -251,7 +254,9 @@ my $someresults= sub { $debug => 0 +% if (!printable($m)) {


+% } <& "query_$styles{Query}", %baseqf, %queryqf, %styles, quri => $quri, dbh => $dbh, queryqf => \%queryqf, allargs => \%ARGS, diff --git a/yarrg/web/qtextstring b/yarrg/web/qtextstring index 93eb124..e046c56 100644 --- a/yarrg/web/qtextstring +++ b/yarrg/web/qtextstring @@ -97,6 +97,7 @@ function <%$p%>Ready() { register_onload(<%$p%>Needed); +% if (!printable($m)) { content %> id="<% $thingstring %>" name="<% $thingstring %>" onchange="<%$p%>Needed();" onkeyup="<%$p%>Later();" @@ -104,6 +105,11 @@ register_onload(<%$p%>Needed); ><% defined($helpref) ? "[?]" : '' %>
 

+% } else { +<% $stringval |h %> +
+
+% } <%perl> if ($significant_nonempty || length $thingstring) { diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index c6ed408..1f8df2a 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -585,17 +585,23 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw( % } # ========== OPTIMISATION ========== +% if (!printable($m)) {

Contents

+% } % if ($optimise) { # ========== TRADING PLAN ========== % @@ -781,7 +787,7 @@ Expected average profit: % % } # ========== TRADING PLAN ========== -% { +% if (!printable($m)) {

Data age summary

<%perl> my $sth_i= $dbh->prepare(< $now, fetchrow => $fetchrow &> Islands shown in reverse order of visits.
+% } else { +% my @tl= gmtime $now or die $!; +

+Generated by YARRG at <% + sprintf "%04d-%02d-%02d %02d:%02d:%02d UTC", + $tl[5]+1900, @tl[4,3,2,1,0] + |h %>. +%# % } -% my %ts_sortkeys; -% { +% if (!printable($m)) { +% my %ts_sortkeys; +% { % my $cdspan= $qa->{ShowStalls} ? ' colspan=2' : ''; % my $cdstall= $qa->{ShowStalls} ? 'Stall' : '';

Relevant trades

@@ -882,14 +897,14 @@ Islands shown in reverse order of visits.
Capital Profit % } -% } +% } -% foreach my $col (@cols) { +% foreach my $col (@cols) { -% } +% } -% foreach my $flowix (0..$#flows) { +% foreach my $flowix (0..$#flows) { % my $flow= $flows[$flowix]; % my $rowid= "id_row_$flow->{UidShort}"; @@ -923,17 +938,17 @@ Islands shown in reverse order of visits.
%>><% exists $spec->{String} ? $spec->{String} : $v |h %> % $ci += $spec->{Span}; % } -% } +% } Total -% foreach my $ci (3..$#cols) { +% foreach my $ci (3..$#cols) { % my $col= $cols[$ci]; % if (defined $col->{Total}) { <% $col->{Total} |h %> % } -% } +% } <&| tabsort, cols => \@cols, table => 'trades', rowclass => 'datarow', @@ -943,6 +958,8 @@ Islands shown in reverse order of visits.
+% } # !printable + <%init> use CommodsWeb; use Commods; diff --git a/yarrg/web/script b/yarrg/web/script index b8e7d03..05ba792 100644 --- a/yarrg/web/script +++ b/yarrg/web/script @@ -36,14 +36,16 @@ http://www.htmlhelp.com/tools/validator/problems.html#script +<%perl> +my $ct= $m->content; + +die "bad script content $&" + if $ct =~ m,\<\/|--\>,; + +% if (!printable($m)) { -<%init> -my $ct= $m->content; - -die "bad script content $&" - if $ct =~ m,\<\/|--\>,; - +% } -- 2.30.2