X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=blobdiff_plain;f=yarrg%2Fdecode-pctb-marketdata;h=df8203c47905a85df290933f4505e6aa3e0ff9a6;hp=f7af70dbf200104883e6b9ce392bd45ca5dd9773;hb=7a0186d4caf09e8ab1175a92fa8d470138103fc8;hpb=8889f1d9d0c97bf7ae741b5af6cfbec3250571b0 diff --git a/yarrg/decode-pctb-marketdata b/yarrg/decode-pctb-marketdata index f7af70d..df8203c 100755 --- a/yarrg/decode-pctb-marketdata +++ b/yarrg/decode-pctb-marketdata @@ -70,11 +70,22 @@ unshift @stalls, undef; $|=1; +sub chk_ascending ($$$) { + my ($this,$lastref,$desc) = @_; + printf "# WARNING - $desc $this < $$lastref\n" + if defined($$lastref) and $this < $$lastref; + $$lastref= $this; +} + foreach my $bs qw(Buy Sell) { my $alloffers_want= getint("Buy ncommods"); my $alloffers_done=0; + my $commodix_last; + my $price_last; while ($alloffers_done < $alloffers_want) { my $commodix= getint("Buy $alloffers_done/$alloffers_want commodix"); + $price_last=undef unless + defined($commodix_last) && $commodix == $commodix_last; my $offers= getint("Buy $commodix offers"); my $offernum; for ($offernum=0; $offernum<$offers; $offernum++) { @@ -85,10 +96,14 @@ foreach my $bs qw(Buy Sell) { $bs, inmap('commod',@pctb_commodmap,$commodix), inmap('stall',@stalls,$stallix)) or die $!; - if ($bs eq 'Sell') { print "\t\t" or die $!; } + my $chk_asc_price_neg; + my $pricesort; + if ($bs eq 'Sell') { $pricesort=1; print "\t\t" or die $!; } printf("\t%d\t%d", $price, $qty) or die $!; - if ($bs eq 'Buy') { print "\t\t" or die $!; } + if ($bs eq 'Buy') { $pricesort=-1; print "\t\t" or die $!; } print "\n" or die $!; + chk_ascending($commodix,\$commodix_last,'commodix'); + chk_ascending($pricesort*$price,\$price_last,'price'); $alloffers_done++; die if $alloffers_done > $alloffers_want; } @@ -188,3 +203,9 @@ $b and die; # 0060 01 00 1e 00 OI 30 # 0070 02 00 qty 2 # +# buy offers need to be sorted first by commodity index, then by +# prices (prices ascending) +# sell offers need to be sorted first by commodity index, then by +# prices (prices descending) +# [ however, it seems that this is wrong and the price sort order is +# supposed to be descending for buy and ascending for sell ]