chiark / gitweb /
Merge branch 'test-install'
[ypp-sc-tools.db-live.git] / yarrg / db-idempotent-populate
index 80ded466aefeb4ab89899fae5218dd7da2537e72..143e2ef9d518e2e733d221365c372971b3ad29e0 100755 (executable)
@@ -1,5 +1,8 @@
 #!/usr/bin/perl -w
 #
+# Normally run from
+#  update-master-info
+#
 # usage: ./db-idempotent-populate <Oceanname>
 #  creates or updates OCEAN-Oceanname.db
 #  from master-master.txt
@@ -39,8 +42,6 @@ my ($oceanname) = @ARGV;
 #---------- setup ----------
 
 parse_info_serverside();
-parse_info_serverside_ocean($oceanname);
-our $ocean= $oceans{$oceanname};
 
 db_setocean($oceanname);
 db_writer();
@@ -95,6 +96,12 @@ db_doall(<<END)
        dist            INTEGER                 NOT NULL,
        PRIMARY KEY (aiid, biid)
  );
+ CREATE TABLE IF NOT EXISTS routes (
+       aiid            INTEGER                 NOT NULL,
+       biid            INTEGER                 NOT NULL,
+       dist            INTEGER                 NOT NULL,
+       PRIMARY KEY (aiid, biid)
+ );
 END
     ;
 
@@ -120,6 +127,8 @@ END
     ;
     foreach my $commod (sort keys %commods) {
        my $c= $commods{$commod};
+        die "no mass for $commod" unless defined $c->{Mass};
+        die "no colume for $commod" unless defined $c->{Volume};
        my @qa= ($c->{Mass}, $c->{Volume}, $commod);
        $insert->execute(@qa);
        $update->execute(@qa);
@@ -128,101 +137,7 @@ END
 }
 
 #---------- island list ----------
-
-{
-    my $sth= $dbh->prepare(<<'END')
- INSERT OR IGNORE INTO islands (islandname, archipelago) VALUES (?, ?);
-END
-    ;
-    foreach my $archname (sort keys %$ocean) {
-       my $arch= $ocean->{$archname};
-       foreach my $islandname (sort keys %$arch) {
-           $sth->execute($islandname, $archname);
-       }
-    }
-    $dbh->commit;
-}
-
 #---------- routes ----------
-
-{
-    foreach my $islandname (sort keys %{ $route_mysteries{$oceanname} }) {
-       warn "$route_mysteries{$oceanname}{$islandname} routes".
-           " for unknown island $islandname\n";
-    }
-
-    my $allroutes= $routes{$oceanname};
-
-    my @propqueue= ();
-
-    sub distance_set_propagate ($$$$) {
-       my ($lev, $start, $upto, $start2upto) = @_;
-       $allroutes->{$start}{$upto}= $start2upto;
-       push @propqueue, [ $lev, $start, $upto ];
-    }
-
-    sub distance_propagate_now {
-       my ($lev, $start, $upto) = @_;
-       my $startref= $allroutes->{$start};
-       my $start2upto= $startref->{$upto};
-       my $uptoref=  $allroutes->{$upto};
-
-       for my $next (keys %$uptoref) {
-           next if $next eq $upto;
-           my $unext= $uptoref->{$next};
-           next unless defined $unext;
-           distance_update("${lev}p", $start, $next, $start2upto + $unext);
-       }
-    }
-
-    sub distance_update ($$$$) {
-       my ($lev, $x, $y, $newdist) = @_;
-       distance_update_one("${lev}x",$x,$y,$newdist);
-       distance_update_one("${lev}y",$y,$x,$newdist);
-    }
-
-    sub distance_update_one ($$$$) {
-       my ($lev, $x, $y, $newdist) = @_;
-       my $xref= $allroutes->{$x};
-       my $currently= $xref->{$y};
-       return if defined($currently) and $currently <= $newdist;
-       distance_set_propagate("${lev}o",$x,$y,$newdist);
-    }
-
-    foreach my $xn (keys %$allroutes) {
-       my $routes= $allroutes->{$xn};
-       distance_set_propagate('0', $xn, $xn, 0);
-       foreach my $yn (keys %$routes) {
-           distance_set_propagate('0', $yn, $yn, 0);
-           distance_set_propagate('X', $xn, $yn, $routes->{$yn});
-           distance_set_propagate('Y', $yn, $xn, $routes->{$yn});
-       }
-    }
-    my $ref;
-    while ($ref= shift @propqueue) {
-       distance_propagate_now(@$ref);
-    }
-
-    db_doall(<<END)
- DELETE FROM dists;
-END
-    ;
-    my $sth= $dbh->prepare(<<'END')
- INSERT INTO dists VALUES
-       ((SELECT islandid FROM islands WHERE islandname == ?),
-        (SELECT islandid FROM islands WHERE islandname == ?),
-        ?);
-END
-    ;
-    foreach my $xn (keys %$allroutes) {
-       my $routes= $allroutes->{$xn};
-       foreach my $yn (keys %$routes) {
-           $sth->execute($xn, $yn, $routes->{$yn});
-       }
-    }
-    $dbh->commit();
-
-    # select ia.islandname, ib.islandname,dists.dist from dists, islands as ia on dists.aiid = ia.islandid, islands as ib on dists.biid = ib.islandid order by ia.islandname, ib.islandname;
-}
+# now done by yppedia-chart-parser
 
 __DATA__