X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.main.git;a=blobdiff_plain;f=yarrg%2Fweb%2Froutetrade;h=80fc2b13d5e8cf78f5ba1c61d0310e5de0280318;hp=6fe34fee16d382e0eb0e954a2e9fa6f174f04e23;hb=a4e2383b30189c028ae35d2f587b084803e5d888;hpb=b4dc1ddbf31709ff25c08559540f4c6c74100896 diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index 6fe34fe..80fc2b1 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -85,10 +85,12 @@ foreach my $src_i (0..$#islandids) { if ($specific && !$confusing && # With a circular route, do not carry goods round the loop - !($src_i==0 && $dst_i==$#islandids && + !(($src_i==0 || $src_i==$#islandids) && + $dst_i==$#islandids && $src_isle == $islandids[$dst_i])) { if ($islandpair{$src_isle,$dst_isle}) { $confusing= 1; +print "confusing $src_i $src_isle $dst_i $dst_isle\n"; } else { $islandpair{$src_isle,$dst_isle}= [ $src_i, $dst_i ]; @@ -239,6 +241,12 @@ $addcols->({ DoReverse => 1 }, % } <%perl> + +if (!@flows) { + print 'No profitable trading opportunities were found.'; + return; +} + foreach my $f (@flows) { $f->{MaxQty}= $f->{'org_qty_agg'} < $f->{'dst_qty_agg'} @@ -340,7 +348,7 @@ Route contains archipelago(es), not just specific islands. Route is complex - it visits the same island several times and isn't a simple loop. % } -Therefore, optimal trade pattern not calculated. +Therefore, optimal voyage trade plan not calculated. % } else { # ========== OPTMISATION ========== <%perl> @@ -551,6 +559,7 @@ $addcols->({ Total => 0, DoReverse => 1 }, qw( % my $iquery= $dbh->prepare('SELECT islandname FROM islands % WHERE islandid = ?'); % my %da_ages; +% my $total_total= 0; %

Voyage trading plan

@@ -573,6 +582,11 @@ Sail to <% $islandname |h %> next if $f->{Suppress}; next unless $f->{"${od}_id"} == $islandids[$i]; next unless $f->{OptQty}; + my $arbitrage= $f->{'org_id'} == $f->{'dst_id'}; + my $loop= $islandids[0] == $islandids[-1] && + ($i==0 || $i==$#islandids); + next if $loop and ($arbitrage ? $i : + !!$i == !!($od eq 'org')); my $price= $f->{"${od}_price"}; my $stallname= $f->{"${od}_stallname"}; my $todo= \$flowlists{$od}{ @@ -593,9 +607,7 @@ Sail to <% $islandname |h %> $$todo->{Qty} += $f->{OptQty}; $$todo->{Total}= $$todo->{Price} * $$todo->{Qty}; $$todo->{Stalls}= $f->{"${od}Stalls"}; - if ($f->{'org_id'} == $f->{'dst_id'}) { - $$todo->{"${od}Arbitrage"}= 1; - } + $$todo->{"${od}Arbitrage"}= 1 if $arbitrage; } } @@ -647,25 +659,32 @@ Sail to <% $islandname |h %> % } % }; % my $show_total= sub { -% my ($totaldesc)= @_; +% my ($totaldesc, $sign)= @_; % if (defined $total) { +
<% $totaldesc %> <% $total |h %> total +% $total_total += $sign * $total; % } % $total= undef; % $dline= 0; <%perl> }; - $show_flows->('dst',0,'Deliver'); $show_total->('Proceeds'); - $show_flows->('org',1,'Collect'); $show_total->('(Arbitrage) outlay'); - $show_flows->('dst',1,'Deliver'); $show_total->('(Arbitrage) proceeds'); - $show_flows->('org',0,'Collect'); $show_total->('Outlay'); + $show_flows->('dst',0,'Deliver'); $show_total->('Proceeds',1); + $show_flows->('org',1,'Collect'); $show_total->('(Arbitrage) outlay',-1); + $show_flows->('dst',1,'Deliver'); $show_total->('(Arbitrage) proceeds',1); + $show_flows->('org',0,'Collect'); $show_total->('Outlay',-1); } +
+Overall net cash flow +<% + $total_total < 0 ? -$total_total." loss" : $total_total." gain" + %>
<& query_age:dataages, id2age => \%da_ages &> %