chiark / gitweb /
routesearch: link to full voyage plans
[ypp-sc-tools.db-live.git] / yarrg / web / query_offers
index b9befe2c60ce3ed0016a6a37683737686a6e4d19..76f45c0da52f143bb39fd7de472c5a1118539cdf 100644 (file)
@@ -88,14 +88,15 @@ return unless defined $cmid and @islandids;
 
 foreach my $wf (@warningfs) { $wf->(); }
 
+if ($qa->{'debug'}) {
 </%perl>
 <pre>
-NOT YET IMPLEMENTED
 bs= <% $qa->{BuySell} %>
 cmdid= <% $cmid %>
 islandids= <% join ',', map { defined($_) ? $_ : 'U' } @islandids %>
 </pre>
 <%perl>
+}
 
 my $locdesc;
 if (@islandids>1) {
@@ -109,6 +110,8 @@ if (@islandids>1) {
        $locdesc= ' in '.$archipelagoes[0];
 }
 
+my $now= time;
+
 my @conds;
 my @condvals;
 push @condvals, $cmid;
@@ -124,13 +127,18 @@ foreach my $ix (0..$#islandids) {
        }
 }
 foreach my $bs (split /_/, $qa->{BuySell}) {
+       my %da_ages;
+       my %ts_sortkeys;
+
        die unless grep { $bs eq $_ } qw(buy sell);
        my $ascdesc= $bs eq 'buy' ? 'DESC' : 'ASC';
 </%perl>
 <h2>Offers to <% uc $bs |h %> <% $commodname |h %> <% $locdesc %></h2>
 <%perl>
        my $stmt= "
-           SELECT archipelago, islandname, stallname, price, qty, timestamp
+           SELECT      archipelago, islandname,
+                       stallname, price, qty, timestamp,
+                       offers.stallid
                FROM $bs AS offers
                JOIN islands ON offers.islandid==islands.islandid
                JOIN uploads ON offers.islandid==uploads.islandid
@@ -151,11 +159,65 @@ foreach my $bs (split /_/, $qa->{BuySell}) {
 <%perl>
        }
 
+       my $row;
        my $sth= $dbh->prepare($stmt);
        $sth->execute(@condvals);
+       my $rowix= 0;
 </%perl>
-       <& dumptable, sth => $sth &>
+%      while ($row= $sth->fetchrow_arrayref) {
+%              if (!$rowix) {
+<table id="<% $bs %>_table" rules=groups>
+<colgroup span=2>
+<colgroup span=3>
+<colgroup span=1>
+<tr>
+<th>Archipelago
+<th>Island
+<th>Stall or Shoppe
+<th>Price
+<th>Quantity
+<th>Data age
+</tr>
+%              }
+%              my $rowid= ${bs}.$row->[6];
+%              my $tscellid= "c$rowid";
+%              my $age= $now - $row->[5];
+%              $da_ages{$rowid}= $age;
+%              $row->[5]= 
+<tr id=<% $rowid %> class="<% 'datarow'.($rowix & 1) %>" >
+%              foreach my $ci (0..4) {
+%                      my $val= $row->[$ci];
+%                      $ts_sortkeys{$ci}{$rowid}= $val;
+<td <% $ci >= 3 ? 'align=right' : '' %> ><% $val |h %>
+%              }
+<td id="<% $tscellid %>" align=right><% prettyprint_age($age) %>
+</tr>
+%              $rowix++;
+%      }
+%      if ($rowix) {
+</table>
+
+<&| tabsort, table => "${bs}_table", rowclass => 'datarow', cols => [
+       {}, {}, {},
+       { Numeric => 1, DoReverse => 1 },
+       { Numeric => 1, DoReverse => 1 },
+       { Numeric => 1, DoReverse => 1, SortKey => "${bs}_ages[rowid]" }],
+       sortkeys => "${bs}_sortkeys"
+  &>
+  <%$bs%>_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>;
+  <%$bs%>_ages= <% to_json_protecttags(\%da_ages) %>;
+</&tabsort>
+%      } else {
+No offers.
+%      }
+
 <%perl>
 }
-
 </%perl>
+
+<p>
+(Please don't use these pages to scrape data out of the YARRG
+database.  This will be a pain for you to program, slow to run, and
+pointlessly overload our server.  Instead, see our
+<a href="devel">information for developers</a>
+to find out how to get testing data or a real-time feed.)