chiark / gitweb /
Merge branch 'stable-5.x'
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 31 Oct 2009 20:32:21 +0000 (20:32 +0000)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 31 Oct 2009 20:32:21 +0000 (20:32 +0000)
1  2 
yarrg/Commods.pm
yarrg/TODO
yarrg/commod-results-processor
yarrg/update-master-info

diff --combined yarrg/Commods.pm
index 0d45c5ea70367945bb997c8cdc409ef4caf3afcc,e63126ace25bb25fa65006d4e028bc4c0154969b..5161af2e8a05a121ca690d41662ebd9012bb8c63
@@@ -22,6 -22,7 +22,7 @@@
  
  package Commods;
  use IO::File;
+ use IO::Pipe;
  use HTTP::Request::Common ();
  use POSIX;
  use LWP::UserAgent;
@@@ -45,7 -46,8 +46,8 @@@ BEGIN 
                      &pipethrough_run_gzip &http_useragent &version_core
                      &http_useragent_string_map
                      &cgipostform &yarrgpostform &cgi_get_caller
-                     &set_ctype_utf8 $masterinfoversion);
+                     &set_ctype_utf8 $masterinfoversion
+                     &source_tarball);
      %EXPORT_TAGS = ( );
  
      @EXPORT_OK   = qw();
@@@ -92,16 -94,12 +94,16 @@@ our %commods
  # eg $commods{'Fine black cloth'}{Srcs}= $sources;
  # eg $commods{'Fine black cloth'}{Mass}= 700 [g]
  # eg $commods{'Fine black cloth'}{Volume}= 1000 [ml]
 +# eg $commods{'Fine black cloth'}{Ordval}= 203921
  
  our (%pctb_commodmap,@pctb_commodmap);
  
  my %colours; # eg $colours{'c'}{'black'}= $sources
  my (@rawcm, @nocm); # eg $rawcm[0]='fine rum'; $rawcm[1]='fine %c cloth'
  
 +my %colour_ordvals; # $colour_ordvals{'c'}{'green'}= '30';
 +my %commodclasses; # $commodclasses{'dye'}= '3';
 +
  # IMPORTANT
  #  when extending the format of source-info in a non-backward
  #  compatible way, be sure to update update-master-info too.
@@@ -120,24 -118,11 +122,24 @@@ sub parse_info1 ($$$) 
        s/\s+$//;
        if (m/^\%(\w+)$/) {
            my $colourkind= $1;
 -          @ctx= (sub { $colours{$colourkind}{lc $_} .= $src; });
 +          @ctx= (sub {
 +              m/^(\S[^\t@]*\S)(?:\t+\@(\d+\+?))?$/ or die "$_ ?";
 +              my ($colour,$order)=($1,$2);
 +              $colours{$colourkind}{$colour} .= $src;
 +              if (defined $order) {
 +                  $order =~ s/^(\d+)\+$/ $1  + $. * 10 /e;
 +                  $colour_ordvals{$colourkind}{$colour}= $order;
 +              }
 +          });
        } elsif (m/^commods$/) {
            @ctx= (sub { push @rawcm, lc $_; });
        } elsif (m/^nocommods$/) {
            @ctx= (sub { push @nocm, lc $_; });
 +      } elsif (m/^commodclasses$/) {
 +          @ctx= (sub {
 +              die unless m/^\*([-a-z]+)$/;
 +              $commodclasses{$1}= scalar keys %commodclasses;
 +          });
        } elsif (m/^ocean (\w+)$/) {
            my $ocean= $1;
            keys %{ $oceans{$ocean} };
        
      %commods= ();
      my $ca;
 +    my $lnoix=0;
      $ca= sub {
 -      my ($s,$ss) = @_;
 -#print "ca($s)\n";
 +      my ($s,$ss,$ordbase) = @_;
 +#print STDERR "ca($s,,".(defined $ordbase ? $ordbase : '?').")\n";
        if ($s !~ m/\%(\w+)/) {
            my ($name, $props) = $s =~
 -              /^(\S[^\t]*\S)(?:\t+(\S[^\t]*\S))?$/
 +              /^(\S[^\t]*\S)(?:\t+(\S.*\S))?$/
                or die "bad commodspec $s";
            return if grep { $name eq $_ } @nocm;
            my $ucname= ucfirst $name;
            $commods{$ucname}{Srcs} .= $ss;
            my $c= $commods{$ucname};
            $c->{Volume}= 1000;
 +          my ($ordval, $ordclassval);
            foreach my $prop (defined $props ? split /\s+/, $props : ()) {
                if ($prop =~ m/^([1-9]\d*)(k?)g$/) {
                    $c->{Mass}= $1 * ($2 ? 1000 : 1);
 -              } elsif ($prop =~m/^([1-9]\d*)l$/) {
 +              } elsif ($prop =~ m/^([1-9]\d*)l$/) {
                    $c->{Volume}= $1 * 1000;
 +              } elsif ($prop =~ m/^\*([-a-z]+)$/) {
 +                  $c->{Class}= $1;
 +                  die "$1" unless exists $commodclasses{$1};
 +                  $ordclassval= 1e7 + $commodclasses{$1} * 1e7;
 +              } elsif ($prop =~ m/^\@(\d+\+?)$/) {
 +                  $ordval= $1;
 +                  $ordval =~ s/^(\d+)\+$/ $1 + $lnoix * 10 /e;
                } else {
                    die "unknown property $prop for $ucname";
                }
            }
 +          if (defined $ordbase && defined $ordval && defined $ordclassval) {
 +              my $ordvalout= $ordbase + $ordval + $ordclassval;
 +              $c->{Ordval}= $ordvalout;
 +#print STDERR "ordval $ordvalout $name OV=$ordval OB=$ordbase OCV=$ordclassval\n";
 +          } else {
 +#print STDERR "ordval NONE $name\n";
 +            }
            return;
        }
        die "unknown $&" unless defined $colours{$1};
        my ($lhs,$pctlet,$rhs)= ($`,$1,$');
        foreach my $c (keys %{ $colours{$pctlet} }) {
 -          &$ca($lhs.$c.$rhs, $ss .'%'. $colours{$pctlet}{$c});
 +          my $ordcolour= $colour_ordvals{$pctlet}{$c};
 +          &$ca($lhs.$c.$rhs,
 +               $ss .'%'. $colours{$pctlet}{$c},
 +               defined($ordbase) && defined($ordcolour)
 +                   ? $ordbase+$ordcolour : undef);
        }
      };
 -    foreach (@rawcm) { &$ca($_,$src); }
 +    foreach (@rawcm) { $lnoix++; &$ca($_,$src,0); }
  }
  
  sub parse_info_clientside () {
@@@ -268,6 -233,7 +270,7 @@@ sub fetch_with_rsync ($) 
  
  sub parse_info_serverside () {
      parse_info1('source-info.txt','s',0);
+     parse_info1('tree-info.txt','t',1);
  }
  sub parse_info_serverside_ocean ($) {
      my ($oceanname) = @_;
@@@ -472,4 -438,38 +475,38 @@@ sub http_useragent ($) 
      return $ua;
  }
  
+ sub source_tarball ($$) {
+     my ($sourcebasedir,$spitoutfn) = @_;
+     my $pipe= new IO::Pipe or die $!;
+     my $pid= fork();  defined $pid or die $!;
+     if (!$pid) {
+       $ENV{'YPPSC_YARRG_SRCBASE'}= $sourcebasedir;
+       $pipe->writer();
+       exec '/bin/sh','-c','
+               cd -P "$YPPSC_YARRG_SRCBASE"
+               (
+                git-ls-files -z;
+                git-ls-files -z --others --exclude-from=.gitignore;
+                if test -d .git; then find .git -print0; fi
+               ) | (
+                cpio -Hustar -o --quiet -0 -R 1000:1000 || \
+                cpio -Hustar -o --quiet -0
+               ) | gzip
+       ';
+       die $!;
+     }
+     $pipe->reader();
+     my ($d, $l);
+     while ($l= read $pipe, $d, 65536) {
+       $spitoutfn->($d);
+     }
+     waitpid $pid,0;
+     defined $l or die "read pipe $!";
+     $pipe->error and die "pipe error $!";
+     close $pipe;
+     # deliberately ignore errors
+ }
  1;
diff --combined yarrg/TODO
index be9fda0917a56e018fed9c1bb987440c7b14aa35,8e85c933e1d1bd44204fb3df18771c9916d5c153..1648c6d664c757d85cfb830f8a47a2a4ee665e06
@@@ -1,6 -1,3 +1,3 @@@
- unticking trades doesn't work?!
  UPLOADER
  --------
  
@@@ -31,21 -28,3 +28,21 @@@ initial/final stocks featur
  
  query_routesearch should show capital for each voyage
  query_routesearch should support ending in specific place(s)
 +
 +
 +USEFUL WEBSITE UI SUGGESTIONS
 +-----------------------------
 +
 +Change loss per league to always be percentage and not to require % to
 +be typed.  Put % sign in HTML after the entry box ?
 +
 +Intro page.
 +"what can this tool do for me"
 +Howto page.
 +
 +15:59 <fivemack> font size=-3 for the license info at the bottom
 +would also be good
 +
 +For `arbitrage' `capital' `net cash flow'
 +16:13 <steph> Diziet: make them hover links where tooltips define the term?
 +
index 9525330652b02051e35921a7feae25789faafce7,37484d6ef6ff071172036578b55a1eef3d2bb301..8ede37166a7c1215731769ccab8993437259634d
@@@ -39,7 -39,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;
@@@ -51,6 -51,7 +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,8 -64,11 +64,12 @@@ 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);
      bs_read(Sell, 4);
      $commod{$commod}{Hold}= $v[6]+0 if @v>6;
@@@ -205,8 -209,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;
            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 $!;
        }
      }
  }
  
  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 () {
 +    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'};
  
@@@ -485,7 -457,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',
diff --combined yarrg/update-master-info
index c668745c5b6e023bbb2ee016c696112548092624,f7574555d88069356991fe261f7d675c148f3098..adad34c81f42fbd29dbc2d0f9b24a7a392bda272
  #         ./update-master-info -b -d ~ftp/users/ijackson/yarrg/ -a
  #         ./update-master-info -b -d ~ftp/users/ijackson/yarrg/ -O ...
  
- # This is part of ypp-sc-tools, a set of third-party tools for assisting
- # players of Yohoho Puzzle Pirates.
+ # This is part of the YARRG website.  YARRG is a tool and website
+ # for assisting players of Yohoho Puzzle Pirates.
  #
  # Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
  #
  # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
+ # it under the terms of the GNU Affero General Public License as
+ # published by the Free Software Foundation, either version 3 of the
+ # License, or (at your option) any later version.
  #
  # This program is distributed in the hope that it will be useful,
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- # GNU General Public License for more details.
+ # GNU Affero General Public License for more details.
  #
- # You should have received a copy of the GNU General Public License
+ # You should have received a copy of the GNU Affero General Public License
  # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  #
  # Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
@@@ -95,7 -95,7 +95,7 @@@ sub process_some_info ($$$) 
            next if $h =~ m/^nocommods/;
        }
        next if $sfn =~ m/source-info/ && $h =~ m/^ocean\b/;
 -      next if $h =~ m/^client|^vessels|^shot\b/;
 +      next if $h =~ m/^client|^vessels|^shot\b|^commodclasses/;
  
        print $df $_, "\n" or die $!;
      }