chiark / gitweb /
Show arbitrage purchases sooner in plan
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 24 Aug 2009 14:33:52 +0000 (15:33 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 24 Aug 2009 14:33:52 +0000 (15:33 +0100)
yarrg/web/routetrade

index 4dbe36e95c533e95cfecce13497c3baba0df66b4..12b4a895f28f29e3847ab4ccbbd2c87a47b81668 100644 (file)
@@ -563,8 +563,9 @@ $addcols->({ Total => 0, DoReverse => 1 }, qw(
 % my %da_ages;
 %
 <h1>Voyage trading plan</h1>
 % my %da_ages;
 %
 <h1>Voyage trading plan</h1>
-<table>
+<table rules=groups>
 % foreach my $i (0..$#islandids) {
 % foreach my $i (0..$#islandids) {
+<tbody>
 <tr><td colspan=3><strong>
 %      $iquery->execute($islandids[$i]);
 %      my ($islandname) = $iquery->fetchrow_array();
 <tr><td colspan=3><strong>
 %      $iquery->execute($islandids[$i]);
 %      my ($islandname) = $iquery->fetchrow_array();
@@ -575,19 +576,24 @@ Sail to <% $islandname |h %>
 %      }
 </strong>
 %    my $age_reported= 0;
 %      }
 </strong>
 %    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"};
 %      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;
 %              $$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"};
 %              $$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;
-<td colspan=3 align=right>\
+%    }
+%
+%    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;
+<td colspan=3>\
 (Data age: <span id="<% $cellid %>"><% prettyprint_age($age) %></span>)
 (Data age: <span id="<% $cellid %>"><% prettyprint_age($age) %></span>)
-%      }
-%      my $total= 0;
-%      my $dline= 0;
-%      foreach my $tkey (sort keys %todo) {
-%              my $t= $todo{$tkey};
+%              } elsif (!defined $total) {
+%                      $total= 0;
+<tbody>
+%              }
 %              $total += $t->{Total};
 %              my $span= 0 + keys %{ $t->{Stalls} };
 %              my $td= "td rowspan=$span";
 <tr class="datarow<% $dline %>">
 %              $total += $t->{Total};
 %              my $span= 0 + keys %{ $t->{Stalls} };
 %              my $td= "td rowspan=$span";
 <tr class="datarow<% $dline %>">
-<<% $td %>><% $od eq 'org' ? 'Collect' : 'Deliver' %>
+<<% $td %>><% $collectdeliver %>
 <<% $td %>><% $t->{'commodname'} |h %>
 %
 %              my @stalls= sort keys %{ $t->{Stalls} };
 <<% $td %>><% $t->{'commodname'} |h %>
 %
 %              my @stalls= sort keys %{ $t->{Stalls} };
@@ -632,12 +652,24 @@ Sail to <% $islandname |h %>
 %
 %              $dline ^= 1;
 %      }
 %
 %              $dline ^= 1;
 %      }
-%      if (%todo) {
+%    };
+%    my $show_total= sub {
+%      my ($totaldesc)= @_;
+%      if (defined $total) {
 <tr>
 <tr>
-<td colspan=4><td align=right><% $od eq 'org' ? 'Outlay' : 'Proceeds' %>
+<td colspan=3>
+<td colspan=2 align=right><% $totaldesc %>
 <td align=right><% $total |h %> total
 %      }
 <td align=right><% $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');
+%
 % }
 </table>
 <& query_age:dataages, id2age => \%da_ages &>
 % }
 </table>
 <& query_age:dataages, id2age => \%da_ages &>