X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;ds=sidebyside;f=yarrg%2Fweb%2Fquery_commod;h=34b1347f20f5034315a1821d535cd6de40f8f8e2;hb=880b063ca880504e85bbeba2e37fc8faa187947e;hp=a4063c12204e703bbb748e07e3d444c3c0f89bc3;hpb=529d79634e714733d47e4cbcd385a727e9fae703;p=ypp-sc-tools.db-live.git
diff --git a/yarrg/web/query_commod b/yarrg/web/query_commod
index a4063c1..34b1347 100644
--- a/yarrg/web/query_commod
+++ b/yarrg/web/query_commod
@@ -52,6 +52,7 @@ my $qa= \%ARGS;
Commodity enquiry
% $prselector->('BuySell');
+% $prselector->('ShowBlank');
%#---------- textbox, user enters route as string ----------
% if (!$qa->{Dropdowns}) {
@@ -88,18 +89,21 @@ $someresults->();
#---------- actually compute the results and print them ----------
+my $onloads= "";
+
foreach my $bs (split /_/, $ARGS{BuySell}) {
$bs =~ m/^(buy|sell)$/ or die;
$bs= $1;
my ($ascdesc) = ($bs eq 'buy')
? ('DESC')
: ('ASC');
-
+ my $joinkind= $ARGS{ShowBlank} ? 'LEFT OUTER JOIN' : 'INNER JOIN';
my $islands= $dbh->prepare(
- "SELECT islandid, archipelago, islandname, sum(qty) as tqty
- FROM $bs NATURAL JOIN islands
- WHERE commodid = ?
- GROUP BY islandid,
+ "SELECT islands.islandid AS islandid, archipelago, islandname,
+ sum(qty) as tqty
+ FROM islands $joinkind $bs offers
+ ON islands.islandid == offers.islandid AND commodid == ?
+ GROUP BY islands.islandid
ORDER BY archipelago, islandname"
);
@@ -115,41 +119,44 @@ foreach my $bs (split /_/, $ARGS{BuySell}) {
Offers to <% uc $bs |h %> <% $commodname |h %>
-
+
| Prices
- | Quantities available
- |
+Quantity at price
+ |
Archipelago
| Island
- | Unique best stall
+ | Stall(s)
| Best
| Median
- | At best
- | Within 10%
- | Total
+ | Best
+ | +/-10%
+ | Any
|
% $islands->execute($commodid);
% my $island;
+% my %ts_sortkeys;
+% my $rowix= 0;
% while ($island= $islands->fetchrow_hashref) {
% my $islandid= $island->{'islandid'};
% $offers->execute($commodid, $islandid);
-% my ($offer, $bestprice, $median, $marginal, @beststalls);
+% my ($offer, $bestprice, $marginal, @beststalls);
% my $tqty= $island->{'tqty'};
-% my $cqty= 0;
-% my $bestqty= 0;
-% my $approxqty= 0;
+% my $cqty= '';
+% my $bestqty= '';
+% my $approxqty= '';
+% my $median= '-';
% while ($offer= $offers->fetchrow_hashref) {
% my $price= $offer->{'price'};
% my $qty= $offer->{'qty'};
-% defined $bestprice or $bestprice= $price;
+% length $bestqty or $bestprice= $price;
% if ($price == $bestprice) {
% $bestqty += $qty;
% push @beststalls, $offer->{'stallname'};
% }
% $cqty += $qty;
-% if ($cqty*2 >= $tqty && !defined $median) {
+% if ($cqty*2 >= $tqty && $median eq '-') {
% $median= $price;
% }
% if ($bestprice*9 <= $price*10 and
@@ -157,20 +164,65 @@ foreach my $bs (split /_/, $ARGS{BuySell}) {
% $approxqty += $qty;
% }
% }
-% my $nstalls= @beststalls;
+% my $stallname;
+%
+% my $rowid= "id_${bs}_$islandid";
+% my $s= [ ];
+%
+% $s->[2]= sprintf "%06d", scalar @beststalls;
+% if (!@beststalls) {
+% $stallname= '-';
+% } elsif (@beststalls==1) {
+% $stallname= $beststalls[0];
+% $s->[2] .= " $stallname";
+% } else {
+% $stallname= sprintf "%d offers", scalar @beststalls;
+% }
+%
% $cqty == $tqty or die "$bs $cqty $tqty $commodid $islandid ";
- <% $island->{'archipelago'} |h %>
- | <% $island->{'islandname'} |h %>
- | <% $nstalls==1 ? $beststalls[0] : "$nstalls offers" |h %>
- | <% $bestprice %>
- | <% $median %>
- | <% $bestqty %>
- | <% $approxqty %>
- | <% $tqty %>
+ |
class="<% 'datarow'.($rowix & 1) %>">
+ <% $s->[0]= $island->{'archipelago'} |h %>
+ | <% $s->[1]= $island->{'islandname'} |h %>
+ | <% $stallname |h %>
+ | <% $s->[3]= (length $bestqty ? $bestprice : '-') %>
+ | <% $s->[4]= $median %>
+ | <% $s->[5]= $bestqty %>
+ | <% $s->[6]= $approxqty %>
+ | <% $s->[7]= $cqty %>
|
+% for my $cix (0..$#$s) {
+% $ts_sortkeys{$cix}{$rowid}= $s->[$cix];
+% }
+% $rowix++;
% }
+<& tabsort, table => "${bs}_table", sortkeys => "${bs}_sortkeys",
+ throw => "${bs}_table_thr", rowclass => 'datarow', cols => [
+ {}, {},
+ { DoReverse => 1 },
+ { DoReverse => 1, Numeric => 1, MapFn => "ts_Pricemap_${bs}" },
+ { DoReverse => 1, Numeric => 1, MapFn => "ts_Pricemap_${bs}" },
+ { DoReverse => 1, Numeric => 1 },
+ { DoReverse => 1, Numeric => 1 },
+ { DoReverse => 1, Numeric => 1 },
+ ] &>
+<&| script &>
+ <% $bs %>_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>;
+ function ts_Pricemap_<% $bs %>(price) {
+ if (price=='-') { return <% $bs eq 'buy' ? '-1' : '99999999' %>; }
+ return price;
+ }
+&>
+% $onloads .= " ts_onload__${bs}_table();\n";
+
<%perl>
}
%perl>
+
+<&| script &>
+ function all_onload() {
+<% $onloads %>
+ }
+ window.onload= all_onload;
+&>