X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=blobdiff_plain;f=yarrg%2Fcommod-results-processor;h=de65f1b903be775ea4e331e46206bc552b0b7ceb;hp=7cd4e0457b6f438398ffa55f46dcdb035d834ed7;hb=9d3e8bb667d766722a70099d1af9e8eb80cdbcf4;hpb=877b0ba6b2d72d7957e2a8015520b87371cba6c9 diff --git a/yarrg/commod-results-processor b/yarrg/commod-results-processor index 7cd4e04..de65f1b 100755 --- a/yarrg/commod-results-processor +++ b/yarrg/commod-results-processor @@ -29,7 +29,6 @@ use strict (qw(vars)); use HTTP::Request; use IO::File; use POSIX; -use LWP::UserAgent; use XML::Parser; use Commods; @@ -40,7 +39,7 @@ use Commods; # $commod{'Hemp'}{Hold} our @v; -our ($commod,$stall,%commod); +our ($commod,$stall,%commod,@commods_inorder); @ARGV==1 or die "You probably don't want to run this program directly.\n"; our ($mode) = shift @ARGV; @@ -65,6 +64,7 @@ while (<>) { @v= split /\t/; #print STDERR "[".join("|",@v)."]\n"; ($commod,$stall) = @v; + push @commods_inorder, $commod unless exists $commod{$commod}; bs_read(Buy, 2); bs_read(Sell, 4); $commod{$commod}{Hold}= $v[6]+0 if @v>6; @@ -129,16 +129,18 @@ sub main__arbitrage () { $info.= sprintf("%-13.13s| %-19.19s %4d| %-19.19s %4d|%3d x%3d =%3d\n", $commod, - $buys[0]{Stall},$buys[0]{Price}, $sells[0]{Stall},$sells[0]{Price}, + $buys[0]{Stall},$buys[0]{Price}, $qty, $pricediff, $tprofit); sub arb_subtract_qty (\@) { my ($verbs) = @_; my $verb= shift @$verbs; + my $vqty= $verb->{Qty}; + $vqty =~ s/^\>//; unshift @$verbs, { Stall => $verb->{Stall}, Price => $verb->{Price}, - Qty => $verb->{Qty} - $qty + Qty => $vqty - $qty }; } arb_subtract_qty(@buys); @@ -225,10 +227,32 @@ sub main__tsv () { write_tsv(\*STDOUT); } +sub main__commodsinorder () { + parse_info_serverside(); + my $last_ov; + foreach my $commod (@commods_inorder) { + my $ov= $commods{$commod}{Ordval}; + printf("found\t%-40s %10s", + $commod, + defined $ov ? $ov : '?') + or die $!; + if (defined $ov) { + if (defined $last_ov && $ov <= $last_ov) { + print " out-of-order" or die $!; + } + $last_ov= $ov; + } + print "\n" or die $!; + } + foreach my $commod (sort keys %commods) { + next if exists $commod{$commod}; + printf "missing\t%s\n", $commod or die $!; + } +} our ($pctb) = $ENV{'YPPSC_YARRG_PCTB'}; -our ($ua)= LWP::UserAgent->new; +our ($ua)= http_useragent("commod-results-processor $mode"); sub refresh_commodmap() { die unless $pctb; @@ -286,7 +310,16 @@ sub refresh_commodmap() { my $content= $resp->content; # print STDERR "[[[$content]]]\n"; - $xp->parse($content); + my $commodmapxmltmp= '_commodmap.xml'; + if (!eval { + $xp->parse($content); 1; + }) { + open R, ">./$commodmapxmltmp" or die $!; + print R $content or die $!; + close R or die $!; + die "$@ parsing commodmap"; + } + unlink $commodmapxmltmp or $!==&ENOENT or die $!; close $o or die $!; rename "_commodmap.tsv.tmp","_commodmap.tsv" or die $!; } @@ -429,15 +462,14 @@ sub gzip ($) { return pipethrough_run($tf,undef,'gzip','gzip'); } -sub main__uploadyaarg () { +sub main__uploadyarrg () { my %o; parse_info_clientside(); $o{'ocean'}= $ENV{'YPPSC_OCEAN'} or die; $o{'island'}= $ENV{'YPPSC_ISLAND'} or die; - $o{'timestamp'}= 10; - get_our_version(\%o, 'client'); + $o{'timestamp'}= $ENV{'YPPSC_DATA_TIMESTAMP'} or die; my $tf= pipethrough_prep(); write_tsv($tf); @@ -446,10 +478,10 @@ sub main__uploadyaarg () { Content_Type => 'application/octet-stream', Content => $oz ]; - my $dest= $ENV{'YPPSC_YARRG_YARRG'}; - - my $respcontent= cgipostform($ua, "$dest/commod-update-receiver", \%o); + my $respcontent= yarrgpostform($ua, \%o); $respcontent =~ m/^OK\b/ or die "$respcontent ?"; + $respcontent =~ s/^/ /mg; + print $respcontent,"\n"; } sub main__uploadpctb () {