chiark / gitweb /
Show distances in various places
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 30 Aug 2009 18:16:31 +0000 (19:16 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 30 Aug 2009 18:16:31 +0000 (19:16 +0100)
yarrg/web/routetrade

index ce91b48726c40f4a59da3f5d8ad40f2204fb1e12..7d112b730ae480e938db46648d28038d4b1cf443 100644 (file)
@@ -50,6 +50,7 @@ my $loss_per_league= 1e-7;
 
 my @flow_conds;
 my @query_params;
 
 my @flow_conds;
 my @query_params;
+my %dists;
 
 my $sd_condition= sub {
        my ($bs, $ix) = @_;
 
 my $sd_condition= sub {
        my ($bs, $ix) = @_;
@@ -161,6 +162,20 @@ my $sth= $dbh->prepare($stmt);
 $sth->execute(@query_params);
 my @flows;
 
 $sth->execute(@query_params);
 my @flows;
 
+my $distquery= $dbh->prepare("
+               SELECT dist FROM dists WHERE aiid = ? AND biid = ?
+               ");
+my $distance= sub {
+       my ($from,$to)= @_;
+       my $d= $dists{$from}{$to};
+       return $d if defined $d;
+       $distquery->execute($from,$to);
+       $d = $distquery->fetchrow_array();
+       defined $d or die "$from $to ?";
+       $dists{$from}{$to}= $d;
+       return $d;
+};
+
 my @cols= ({ NoSort => 1 });
 
 my $addcols= sub {
 my @cols= ({ NoSort => 1 });
 
 my $addcols= sub {
@@ -190,7 +205,7 @@ $addcols->({ DoReverse => 1, SortColKey => 'MarginSortKey' },
        qw(     Margin
        ));
 $addcols->({ DoReverse => 1 },
        qw(     Margin
        ));
 $addcols->({ DoReverse => 1 },
-       qw(     unitprofit MaxQty
+       qw(     unitprofit dist MaxQty
                MaxCapital MaxProfit
        ));
 
                MaxCapital MaxProfit
        ));
 
@@ -263,6 +278,8 @@ foreach my $f (@flows) {
                $f->{'dst_price'} * (1.0 - $loss_per_league) ** $f->{'dist'}
                - $f->{'org_price'};
 
                $f->{'dst_price'} * (1.0 - $loss_per_league) ** $f->{'dist'}
                - $f->{'org_price'};
 
+       $dists{'org_id'}{'dst_id'}= $f->{'dist'};
+
        my @uid= $f->{commodid};
        foreach my $od (qw(org dst)) {
                push @uid,
        my @uid= $f->{commodid};
        foreach my $od (qw(org dst)) {
                push @uid,
@@ -469,6 +486,7 @@ $addcols->({ Total => 0, DoReverse => 1 }, qw(
 <colgroup span=2>
 <colgroup span=2>
 <colgroup span=2>
 <colgroup span=2>
 <colgroup span=2>
 <colgroup span=2>
+<colgroup span=1>
 <colgroup span=3>
 %      if ($optimise) {
 <colgroup span=3>
 <colgroup span=3>
 %      if ($optimise) {
 <colgroup span=3>
@@ -481,6 +499,7 @@ $addcols->({ Total => 0, DoReverse => 1 }, qw(
 <th colspan=2>Collect
 <th colspan=2>Deliver
 <th colspan=2>Profit
 <th colspan=2>Collect
 <th colspan=2>Deliver
 <th colspan=2>Profit
+<th colspan=1>
 <th colspan=3>Max
 %      if ($optimise) {
 <th colspan=3>Planned
 <th colspan=3>Max
 %      if ($optimise) {
 <th colspan=3>Planned
@@ -497,6 +516,7 @@ $addcols->({ Total => 0, DoReverse => 1 }, qw(
 <th>Qty
 <th>Margin
 <th>Unit
 <th>Qty
 <th>Margin
 <th>Unit
+<th>Dist
 <th>Qty
 <th>Capital
 <th>Profit
 <th>Qty
 <th>Capital
 <th>Profit
@@ -560,15 +580,15 @@ $addcols->({ Total => 0, DoReverse => 1 }, qw(
 <table rules=groups>
 % foreach my $i (0..$#islandids) {
 <tbody>
 <table rules=groups>
 % foreach my $i (0..$#islandids) {
 <tbody>
-<tr><td colspan=3><strong>
+<tr><td colspan=3>
 %      $iquery->execute($islandids[$i]);
 %      my ($islandname) = $iquery->fetchrow_array();
 %      if (!$i) {
 %      $iquery->execute($islandids[$i]);
 %      my ($islandname) = $iquery->fetchrow_array();
 %      if (!$i) {
-Start at <% $islandname |h %>
+<strong>Start at <% $islandname |h %></strong>
 %      } else {
 %      } else {
-Sail to <% $islandname |h %>
+<strong>Sail to <% $islandname |h %></strong>
+- <% $distance->($islandids[$i-1],$islandids[$i]) |h %>leagues </td>
 %      }
 %      }
-</strong>
 <%perl>
      my $age_reported= 0;
      my %flowlists;
 <%perl>
      my $age_reported= 0;
      my %flowlists;