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=8ede37166a7c1215731769ccab8993437259634d;hp=de65f1b903be775ea4e331e46206bc552b0b7ceb;hb=2aa3a575e41e6c9ed3b58e822dde0cf73502012b;hpb=6dd7f2e34ba640442ad61000ecb6558116ceb656 diff --git a/yarrg/commod-results-processor b/yarrg/commod-results-processor index de65f1b..8ede371 100755 --- a/yarrg/commod-results-processor +++ b/yarrg/commod-results-processor @@ -51,6 +51,7 @@ sub bs_read ($$) { return if @v <= $c; my ($price,$qty) = @v[$c..$c+1]; return if !length($price) && !length($qty); + die "$price ?" unless $price =~ m/^\d/; die "$_ ?" unless length($price) && length($qty); $commod{$commod}{$bs}{$stall}= { Stall => $stall, @@ -63,6 +64,10 @@ while (<>) { chomp; @v= split /\t/; #print STDERR "[".join("|",@v)."]\n"; + foreach (@v[2..$#v]) { + s/\,//g; + die "$_ ?" if m/.\D/; + } ($commod,$stall) = @v; push @commods_inorder, $commod unless exists $commod{$commod}; bs_read(Buy, 2); @@ -205,8 +210,8 @@ sub bs_p_tsv ($$) { } } -sub write_tsv ($) { - my ($f) = @_; +sub write_tsv ($$) { + my ($f,$showhold) = @_; foreach $commod (sort keys %commod) { $current= $commod{$commod}; my %stalls; @@ -216,6 +221,9 @@ sub write_tsv ($) { printf($f "%s\t%s", $commod, $stall) or die $!; bs_p_tsv($f, Buy); bs_p_tsv($f, Sell); + if ($showhold && $commod{$commod}{Hold}) { + printf($f "\t%s", $commod{$commod}{Hold}) or die $!; + } print($f "\n") or die $!; } } @@ -224,7 +232,19 @@ sub write_tsv ($) { } sub main__tsv () { - write_tsv(\*STDOUT); + write_tsv(\*STDOUT,1); +} + +sub undef_printable { my ($ov)= @_; defined $ov ? $ov : '?'; }; + +sub commodsinorder_print1 ($$) { + my ($keyword,$commod) = @_; + printf("%s\t%-40s %10s %s", + $keyword, + $commod, + undef_printable($commods{$commod}{Ordval}), + undef_printable($commods{$commod}{Class})) + or die $!; } sub main__commodsinorder () { @@ -232,10 +252,7 @@ sub main__commodsinorder () { my $last_ov; foreach my $commod (@commods_inorder) { my $ov= $commods{$commod}{Ordval}; - printf("found\t%-40s %10s", - $commod, - defined $ov ? $ov : '?') - or die $!; + commodsinorder_print1('found',$commod); if (defined $ov) { if (defined $last_ov && $ov <= $last_ov) { print " out-of-order" or die $!; @@ -244,9 +261,13 @@ sub main__commodsinorder () { } print "\n" or die $!; } - foreach my $commod (sort keys %commods) { + foreach my $commod (sort { + undef_printable($commods{$a}{Ordval}) cmp + undef_printable($commods{$b}{Ordval}) + } keys %commods) { next if exists $commod{$commod}; - printf "missing\t%s\n", $commod or die $!; + commodsinorder_print1('none',$commod); + print "\n" or die $!; } } @@ -472,7 +493,7 @@ sub main__uploadyarrg () { $o{'timestamp'}= $ENV{'YPPSC_DATA_TIMESTAMP'} or die; my $tf= pipethrough_prep(); - write_tsv($tf); + write_tsv($tf,0); my $oz= pipethrough_run_gzip($tf); $o{'data'}= [ undef, 'deduped.tsv.gz', Content_Type => 'application/octet-stream',