From: Ian Jackson Date: Mon, 24 Aug 2009 14:33:52 +0000 (+0100) Subject: Show arbitrage purchases sooner in plan X-Git-Tag: 3.4~106^2~5 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-test.git;a=commitdiff_plain;h=6f2f4d2443ccb3ce9fb30820c27c3cd0cb67fa07 Show arbitrage purchases sooner in plan --- diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index 4dbe36e..12b4a89 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -563,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} }; @@ -632,12 +652,24 @@ Sail to <% $islandname |h %> % % $dline ^= 1; % } -% if (%todo) { +% }; +% my $show_total= sub { +% my ($totaldesc)= @_; +% if (defined $total) { -
% $iquery->execute($islandids[$i]); % my ($islandname) = $iquery->fetchrow_array(); @@ -575,19 +576,24 @@ Sail to <% $islandname |h %> % } % my $age_reported= 0; -% foreach my $od (qw(dst org)) { -% my $sign= $od eq 'dst' ? -1 : +1; -% my %todo; +% 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= \$todo{ $f->{'commodname'}, -% (sprintf "%07d", $price), -% $stallname }; -% $$todo= { Qty => 0 } unless $$todo; +% my $todo= \$flowlists{$od}{ +% $f->{'commodname'}, +% (sprintf "%07d", $price), +% $stallname +% }; +% $$todo= { +% Qty => 0, +% orgArbitrage => 0, +% dstArbitrage => 0, +% } unless $$todo; % $$todo->{'commodname'}= $f->{'commodname'}; % $$todo->{'stallname'}= $stallname; % $$todo->{Price}= $price; @@ -595,23 +601,37 @@ 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; +% } % } -% if (%todo && !$age_reported++) { -% my $age= $now - (values %todo)[0]->{Timestamp}; -% my $cellid= "da_${i}"; -% $da_ages{$cellid}= $age; -\ +% } +% +% 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; +
<% $od eq 'org' ? 'Outlay' : 'Proceeds' %> + +<% $totaldesc %> <% $total |h %> total % } -% } +% $total= undef; +% $dline= 0; +% }; +% +% $show_flows->('org',1,'Collect'); $show_total->('(Arbitrage) outlay'); +% $show_flows->('dst',1,'Deliver'); +% $show_flows->('dst',0,'Deliver'); $show_total->('Proceeds'); +% $show_flows->('org',0,'Collect'); $show_total->('Outlay'); +% % }
<& query_age:dataages, id2age => \%da_ages &>