From 5c4f4ea818dd0947a4ef28baa6f85d817f0aca44 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 21 Aug 2009 23:07:36 +0100 Subject: [PATCH] Commodity stats --- yarrg/Commods.pm | 26 ++++++- yarrg/db-idempotent-populate | 20 ++++- yarrg/master-info.txt | 142 ++++++++++++++++++----------------- 3 files changed, 114 insertions(+), 74 deletions(-) diff --git a/yarrg/Commods.pm b/yarrg/Commods.pm index f17a8ed..13f5812 100644 --- a/yarrg/Commods.pm +++ b/yarrg/Commods.pm @@ -120,10 +120,30 @@ sub parse_info1 ($$) { $ca= sub { my ($s,$ss) = @_; #print "ca($s)\n"; - if ($s !~ m/\%(\w+)/) { $commods{ucfirst $s}{Srcs} .= $ss; return; } + if ($s !~ m/\%(\w+)/) { + my ($name, $props) = $s =~ + /^(\S[^\t]*\S)\t+(\S[^\t]*\S)$/ + or die "bad commodspec $s"; + my $ucname= ucfirst $name; + $commods{$ucname}{Srcs} .= $ss; + my $c= $commods{$ucname}; + $c->{Volume}= 1000; + foreach my $prop (split /\s+/, $props) { + if ($prop =~ m/^([1-9]\d*)(k?)g$/) { + $c->{Mass}= $1 * ($2 ? 1000 : 1); + } elsif ($prop =~m/^([1-9]\d*)l$/) { + $c->{Volume}= $1 * 1000; + } else { + die "unknown property $prop for $ucname"; + } + } + die "no mass for $ucname" unless defined $c->{Mass}; + return; + } die "unknown $&" unless defined $colours{$1}; - foreach my $c (keys %{ $colours{$1} }) { - &$ca($`.$c.$', $ss .'%'. $colours{$1}{$c}); + my ($lhs,$pctlet,$rhs)= ($`,$1,$'); + foreach my $c (keys %{ $colours{$pctlet} }) { + &$ca($lhs.$c.$rhs, $ss .'%'. $colours{$pctlet}{$c}); } }; foreach (@rawcm) { &$ca($_,$src); } diff --git a/yarrg/db-idempotent-populate b/yarrg/db-idempotent-populate index 96df020..80ded46 100755 --- a/yarrg/db-idempotent-populate +++ b/yarrg/db-idempotent-populate @@ -103,12 +103,26 @@ $dbh->commit; #---------- commodity list ---------- { - my $sth= $dbh->prepare(<<'END') - INSERT OR IGNORE INTO commods (commodname) VALUES (?); + my $insert= $dbh->prepare(<<'END') + INSERT OR IGNORE INTO commods + (unitmass, + unitvolume, + commodname) + VALUES (?,?,?); +END + ; + my $update= $dbh->prepare(<<'END') + UPDATE commods + SET unitmass = ?, + unitvolume = ? + WHERE commodname = ? END ; foreach my $commod (sort keys %commods) { - $sth->execute($commod); + my $c= $commods{$commod}; + my @qa= ($c->{Mass}, $c->{Volume}, $commod); + $insert->execute(@qa); + $update->execute(@qa); } $dbh->commit; } diff --git a/yarrg/master-info.txt b/yarrg/master-info.txt index eb8d666..312e81c 100644 --- a/yarrg/master-info.txt +++ b/yarrg/master-info.txt @@ -1,13 +1,13 @@ commods - %c dye - %c enamel - %c paint + kraken's blood 1kg + %c dye 1kg + %c enamel 5kg + %c paint 1200g 1l - %c cloth - fine %c cloth - - %g gems + %c cloth 700g + fine %c cloth 700g + sail cloth 700g %c aqua @@ -38,6 +38,17 @@ commods white yellow +commods + %g gems 10kg + diamonds 10kg + emeralds 10kg + moonstones 10kg + opals 10kg + pearls 10kg + rubies 10kg + sapphires 10kg + topazes 10kg + %g amber amethyst @@ -51,67 +62,62 @@ commods tigereye commods - bananas - broom flower - butterfly weed - carambolas - chalcocite - coconuts - cowslip - cubanite - diamonds - durians - elderberries - emeralds - fine rum - gold nuggets - gold ore - grog - hemp - hemp oil - indigo - iris root - iron - kraken's blood - lacquer - large cannon balls - leushite - lily of the valley - limes - lobelia - lorandite - madder - mangos - masuyite - medium cannon balls - moonstones - nettle - old man's beard - opals - papagoite - passion fruit - pearls - pineapples - pokeweed berries - pomegranates - rambutan - rubies - sail cloth - sapphires - sassafras - serandite - sincosite - small cannon balls - stone - sugar cane - swill - tellurium - thorianite - topazes - varnish - weld - wood - yarrow + swill 1kg + grog 1kg + fine rum 1kg + + broom flower 200g + butterfly weed 100g + cowslip 700g + elderberries 700g + indigo 700g + iris root 300g + lily of the valley 300g + lobelia 200g + madder 400g + nettle 300g + old man's beard 800g + pokeweed berries 300g + sassafras 500g + weld 300g + yarrow 200g + + bananas 125kg 100l + coconuts 125kg 100l + limes 125kg 100l + mangos 125kg 100l + pineapples 125kg 100l + + carambolas 125kg 100l + durians 125kg 100l + passion fruit 125kg 100l + pomegranates 125kg 100l + rambutan 125kg 100l + + chalcocite 5700g + cubanite 4700g + gold nuggets 400g + leushite 4400g + lorandite 5500g + masuyite 5100g + papagoite 3300g + serandite 3400g + sincosite 3000g + tellurium 6200g + thorianite 100g + + small cannon balls 7100g + medium cannon balls 14200g 2l + large cannon balls 21300g 3l + + hemp 125kg 250l + hemp oil 1kg + iron 7800g + lacquer 1kg + stone 2600g + sugar cane 50kg 100l + varnish 1kg + wood 175kg 250l ocean Midnight Coral -- 2.30.2