X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=yarrg%2Fweb%2Froutetrade;h=eadc473d4b23dac47885d569b89a79d12a741ae5;hb=880b063ca880504e85bbeba2e37fc8faa187947e;hp=91ff421625fd7d4757a6def0a6e471341ac073e1;hpb=b6475c671134b0dba4ac23446d90a34a736290ca;p=ypp-sc-tools.db-live.git diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index 91ff421..eadc473 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -259,6 +259,11 @@ foreach my $f (@flows) { $f->{MaxProfit}= $f->{MaxQty} * $f->{'unitprofit'}; $f->{MaxCapital}= $f->{MaxQty} * $f->{'org_price'}; + $f->{MarginSortKey}= sprintf "%d", + $f->{'dst_price'} * 10000 / $f->{'org_price'}; + $f->{Margin}= sprintf "%3.1f%%", + $f->{'dst_price'} * 100.0 / $f->{'org_price'} - 100.0; + $f->{ExpectedUnitProfit}= $f->{'dst_price'} * (1.0 - $loss_per_league) ** $f->{'dist'} - $f->{'org_price'}; @@ -558,8 +563,9 @@ $addcols->({ Total => 0, DoReverse => 1 }, qw( % my %da_ages; %

Voyage trading plan

- +
% foreach my $i (0..$#islandids) { + +% } % $total += $t->{Total}; % my $span= 0 + keys %{ $t->{Stalls} }; % my $td= "td rowspan=$span"; -<<% $td %>><% $od eq 'org' ? 'Collect' : 'Deliver' %> +<<% $td %>><% $collectdeliver %> <<% $td %>><% $t->{'commodname'} |h %> % % my @stalls= sort keys %{ $t->{Stalls} }; % my $pstall= sub { % my $name= $stalls[$_[0]]; -% my $avail= $t->{Stalls}{$name}; - -
% $iquery->execute($islandids[$i]); % my ($islandname) = $iquery->fetchrow_array(); @@ -569,56 +575,76 @@ Start at <% $islandname |h %> Sail to <% $islandname |h %> % } -% my $age_reported= 0; -% foreach my $od (qw(dst org)) { -% my $sign= $od eq 'dst' ? -1 : +1; -% my %todo; -% foreach my $f (@flows) { -% next if $f->{Suppress}; -% next unless $f->{"${od}_id"} == $islandids[$i]; -% next unless $f->{OptQty}; -% my $price= $f->{"${od}_price"}; -% my $stallname= $f->{"${od}_stallname"}; -% my $todo= \$todo{ $f->{'commodname'}, -% (sprintf "%07d", $price), -% $stallname }; -% $$todo= { Qty => 0 } unless $$todo; -% $$todo->{'commodname'}= $f->{'commodname'}; -% $$todo->{'stallname'}= $stallname; -% $$todo->{Price}= $price; -% $$todo->{Timestamp}= $f->{"${od}_timestamp"}; -% $$todo->{Qty} += $f->{OptQty}; -% $$todo->{Total}= $$todo->{Price} * $$todo->{Qty}; -% $$todo->{Stalls}= $f->{"${od}Stalls"}; -% } -% if (%todo && !$age_reported++) { -% my $age= $now - (values %todo)[0]->{Timestamp}; -% my $cellid= "da_${i}"; -% $da_ages{$cellid}= $age; -\ +<%perl> + my $age_reported= 0; + my %flowlists; + foreach my $od (qw(org dst)) { + foreach my $f (@flows) { + next if $f->{Suppress}; + next unless $f->{"${od}_id"} == $islandids[$i]; + next unless $f->{OptQty}; + my $price= $f->{"${od}_price"}; + my $stallname= $f->{"${od}_stallname"}; + my $todo= \$flowlists{$od}{ + $f->{'commodname'}, + (sprintf "%07d", ($od eq 'dst' ? + 9999999-$price : $price)), + $stallname + }; + $$todo= { + Qty => 0, + orgArbitrage => 0, + dstArbitrage => 0, + } unless $$todo; + $$todo->{'commodname'}= $f->{'commodname'}; + $$todo->{'stallname'}= $stallname; + $$todo->{Price}= $price; + $$todo->{Timestamp}= $f->{"${od}_timestamp"}; + $$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; + } + } + } + + my $total; + my $dline= 0; + my $show_flows= sub { + my ($od,$arbitrage,$collectdeliver) = @_; + +% +% my $todo= $flowlists{$od}; +% return unless $todo; +% foreach my $tkey (sort keys %$todo) { +% my $t= $todo->{$tkey}; +% next if $t->{"${od}Arbitrage"} != $arbitrage; +% if (!$age_reported++) { +% my $age= $now - $t->{Timestamp}; +% my $cellid= "da_${i}"; +% $da_ages{$cellid}= $age; +\ (Data age: <% prettyprint_age($age) %>) -% } -% my $total= 0; -% my $dline= 0; -% foreach my $tkey (sort keys %todo) { -% my $t= $todo{$tkey}; +% } elsif (!defined $total) { +% $total= 0; +
<% $avail |h %> <% $od eq 'org' ? 'avail.' : 'wanted' %> <% $name |h %> % }; % % $pstall->(0); -<<% $td %> align=right><% $t->{Price} |h %> each +<<% $td %> align=right><% $t->{Price} |h %> poe ea. <<% $td %> align=right><% $t->{Qty} |h %> unit(s) <<% $td %> align=right><% $t->{Total} |h %> total % @@ -629,13 +655,27 @@ Sail to <% $islandname |h %> % % $dline ^= 1; % } -% if (%todo) { +% }; +% my $show_total= sub { +% my ($totaldesc)= @_; +% if (defined $total) {
<% $od eq 'org' ? 'Outlay' : 'Proceeds' %> + +<% $totaldesc %> <% $total |h %> 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'); + +} +
<& query_age:dataages, id2age => \%da_ages &> %