X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;ds=sidebyside;f=yarrg%2Fweb%2Fquery_commod;h=0bd36cbffa4db9e958ce30cbc84521a181e70862;hb=2007f48bd68be9218b8f41acd9ba32d378a1b22c;hp=4869e5c50fad00d6222fa0a1ce8e2df110f488a9;hpb=890faab73220a817300d53a362464d6a7fc06788;p=ypp-sc-tools.web-live.git diff --git a/yarrg/web/query_commod b/yarrg/web/query_commod index 4869e5c..0bd36cb 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,17 +89,19 @@ $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'); -#INNER JOIN + my $joinkind= $ARGS{ShowBlank} ? 'LEFT OUTER JOIN' : 'INNER JOIN'; my $islands= $dbh->prepare( "SELECT islands.islandid AS islandid, archipelago, islandname, sum(qty) as tqty - FROM islands LEFT OUTER JOIN $bs offers + FROM islands $joinkind $bs offers ON islands.islandid == offers.islandid AND commodid == ? GROUP BY islands.islandid, ORDER BY archipelago, islandname" @@ -116,23 +119,24 @@ foreach my $bs (split /_/, $ARGS{BuySell}) {

Offers to <% uc $bs |h %> <% $commodname |h %>

- +
+ % $islands->execute($commodid); % my $island; +% my %ts_sortkeys; % while ($island= $islands->fetchrow_hashref) { % my $islandid= $island->{'islandid'}; % $offers->execute($commodid, $islandid); @@ -159,21 +163,64 @@ 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 "; - > + +% for my $cix (0..$#$s) { +% $ts_sortkeys{$cix}{$rowid}= $s->[$cix]; +% } % }
Prices -Quantities available -
Quantity at price +
Archipelago Island -Unique best stall +Stall(s) Best Median -At best -Within 10% -Total +Best ++/-10% +Any
<% $island->{'archipelago'} |h %> - <% $island->{'islandname'} |h %> - <% $nstalls==0 ? '-' : - $nstalls==1 ? $beststalls[0] : "$nstalls offers" |h %> - <% length $bestqty ? $bestprice : '-' %> - <% $median %> - <% $bestqty %> - <% $approxqty %> - <% $cqty %> +
<% $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 %>
+<& tabsort, table => "${bs}_table", sortkeys => "${bs}_sortkeys", + throw => "${bs}_table_thr", 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> } + +<&| script &> + function all_onload() { +<% $onloads %> + } + window.onload= all_onload; +