chiark / gitweb /
Reorganise columns
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 19 Aug 2009 23:09:10 +0000 (00:09 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Wed, 19 Aug 2009 23:09:10 +0000 (00:09 +0100)
yarrg/web/query_commod

index 9a7d2bc..a4063c1 100644 (file)
@@ -117,44 +117,55 @@ foreach my $bs (split /_/, $ARGS{BuySell}) {
 
 <table>
 <tr>
+<th colspan=3>
+<th colspan=2>Prices
+<th colspan=3>Quantities available
+<tr>
 <th>Archipelago
 <th>Island
 <th>Unique best stall
-<th>Best price
-<th>Qty at best
-<th>Median price
-<th>Total qty
+<th>Best
+<th>Median
+<th>At best
+<th>Within 10%
+<th>Total
 </tr>
 %      $islands->execute($commodid);
 %      my $island;
 %      while ($island= $islands->fetchrow_hashref) {
 %              my $islandid= $island->{'islandid'};
 %              $offers->execute($commodid, $islandid);
-%              my ($offer, $best, $median);
+%              my ($offer, $bestprice, $median, $marginal, @beststalls);
 %              my $tqty= $island->{'tqty'};
 %              my $cqty= 0;
+%              my $bestqty= 0;
+%              my $approxqty= 0;
 %              while ($offer= $offers->fetchrow_hashref) {
-%                      if (!$best) {
-%                              $best= { 'price' => $offer->{'price'} };
-%                      }
-%                      if ($offer->{'price'} == $best->{'price'}) {
-%                              $best->{'qty'} += $offer->{'qty'};
-%                              push @{ $best->{'stalls'} },
-%                                      $offer->{'stallname'};
+%                      my $price= $offer->{'price'};
+%                      my $qty= $offer->{'qty'};
+%                      defined $bestprice or $bestprice= $price;
+%                      if ($price == $bestprice) {
+%                              $bestqty += $qty;
+%                              push @beststalls, $offer->{'stallname'};
 %                      }
-%                      $cqty += $offer->{'qty'};
+%                      $cqty += $qty;
 %                      if ($cqty*2 >= $tqty && !defined $median) {
-%                              $median= $offer->{'price'};
+%                              $median= $price;
+%                      }
+%                      if ($bestprice*9 <= $price*10 and
+%                          $price*10 <= $bestprice*11) {
+%                              $approxqty += $qty;
 %                      }
 %              }
+%              my $nstalls= @beststalls;
 %              $cqty == $tqty or die "$bs $cqty $tqty $commodid $islandid ";
-%              my $nstalls= @{ $best->{'stalls'} };
 <tr> <td><% $island->{'archipelago'} |h %>
      <td><% $island->{'islandname'} |h %>
-     <td><% $nstalls==1 ? $best->{'stalls'}[0] : "$nstalls offers" |h %>
-     <td><% $best->{'price'} %>
-     <td><% $best->{'qty'} %>
+     <td><% $nstalls==1 ? $beststalls[0] : "$nstalls offers" |h %>
+     <td><% $bestprice %>
      <td><% $median %>
+     <td><% $bestqty %>
+     <td><% $approxqty %>
      <td><% $tqty %>
 </tr>
 %      }