chiark / gitweb /
Normalise commodity name case (from uploads)
[ypp-sc-tools.db-test.git] / yarrg / commod-results-processor
index 37484d6ef6ff071172036578b55a1eef3d2bb301..fe05fb8722c207acb14c44f63d0d15b31a20bf17 100755 (executable)
@@ -24,6 +24,7 @@
 # are used without permission.  This program is not endorsed or
 # sponsored by Three Rings.
 
+BEGIN { unshift @INC, qw(.) }
 
 use strict (qw(vars));
 use HTTP::Request;
@@ -39,7 +40,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;
@@ -69,6 +70,7 @@ while (<>) {
        die "$_ ?" if m/.\D/;
     }
     ($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;
@@ -234,6 +236,41 @@ sub main__tsv () {
     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 () {
+    parse_info_serverside();
+    my $last_ov;
+    foreach my $commod (@commods_inorder) {
+       my $ov= $commods{$commod}{Ordval};
+       commodsinorder_print1('found',$commod);
+       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 {
+           undef_printable($commods{$a}{Ordval}) cmp
+           undef_printable($commods{$b}{Ordval})
+       } keys %commods) {
+       next if exists $commod{$commod};
+       commodsinorder_print1('none',$commod);
+       print "\n" or die $!;
+    }
+}
 
 our ($pctb) = $ENV{'YPPSC_YARRG_PCTB'};
 
@@ -514,19 +551,17 @@ sub main__uploadpctb () {
 
     my $islandid;
     while ($resptxt =~
- m/^islands\[\d+\]\[\d+\]\=new\s+option\(\"(.*)\"\,(\d+)\)\s*$/mig
+ m/^islands\[(\d+)\]\[\d+\]\=new\s+option\(\"(.*)\"\,(\d+)\)\s*$/mig
           ) {
-       next unless $1 eq $island;
-       $islandid= $2;
+       next unless $1 eq $oceanids[0];
+       next unless $2 eq $island;
+       $islandid= $3;
     }
     defined $islandid or die;
 
     die "@filenames ?" if grep { $_ ne $filename } @filenames;
     die "@forcerls ?" if grep { $_ ne $forcerl } @forcerls;
 
-    my $setisland= {
-    };
-
     print STDERR "Setting ocean and island...\n";
 
     my $siurl= ($url . "?action=setisland".