chiark / gitweb /
Further work on chart parser
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 27 Aug 2009 16:39:39 +0000 (17:39 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 27 Aug 2009 16:39:39 +0000 (17:39 +0100)
yarrg/yppedia-chart-parser

index 7cc0baf5a1991a82f355c8d06d8e3b7d5568f9e6..e3150611cb36eb75a6a3eb117e276982ad5aebd0 100755 (executable)
@@ -17,15 +17,23 @@ my %wiisland2node;
 my %winode2island;
 my %winode2lines;
 my %wiccix2arch;
+my $wialldists;
 
 my $dbdists= Graph::Undirected->new();
 my %dbisland2arch;
 
-my %msgcount;
-sub perr ($$) { print STDERR "$_[0]: $_[1]\n"; $msgcount{$_[0]}++; }
-sub warning ($) { perr("warning",$_[0]); }
-sub error   ($) { perr("error",  $_[0]); }
-sub change  ($) { perr("change", $_[0]); }
+my %msgs;
+sub pmsg ($$) { push @{ $msgs{$_[0]} }, "$_[0]: $_[1]\n"; }
+sub warning ($) { pmsg("warning",$_[0]); }
+sub error   ($) { pmsg("error",  $_[0]); }
+sub change  ($) { pmsg("change", $_[0]); }
+sub print_messages () {
+    foreach my $k (qw(change warning error)) {
+       my $m= $msgs{$k};
+       next unless $m;
+       print sort @$m or die $!;
+    }
+}
 
 if (@ARGV && $ARGV[0] eq '--debug') {
     shift @ARGV;
@@ -173,7 +181,7 @@ sub process_yppedia_graphs () {
     # Compute all-pairs-shortest-paths on dist, which is the
     # actual distances between all LPs.
     #
-    my $wialldists= $widists->APSP_Floyd_Warshall();
+    $wialldists= $widists->APSP_Floyd_Warshall();
 
     # Assign archipelago labels to groups of islands
     #
@@ -329,10 +337,35 @@ sub compare_island_lists () {
     }
 }
 
+sub compare_distances () {
+    foreach my $ia (sort keys %dbisland2arch) {
+       my $na= $wiisland2node{$ia};
+       next unless defined $na;
+       foreach my $ib (sort keys %dbisland2arch) {
+           next unless $ia le $ib; # do every pair only once
+           my $nb= $wiisland2node{$ib};
+           next unless defined $nb;
+           my $dbdist= $dbdists->get_edge_weight($ia,$ib);
+           my $widist= $wialldists->path_length($na,$nb);
+           if (!defined $dbdist) {
+               change(sprintf "define distance %2d for %s..%s",
+                      $widist, $ia,$ib);
+           } elsif ($dbdist != $widist) {
+               change(sprintf "change distance %2d to %2d for %s..%s",
+                      $dbdist, $widist, $ia,$ib);
+           }
+       }
+    }
+}
+
 parse_info_serverside();
 db_setocean($ocean);
 db_connect();
 parse_yppedia_map();
 parse_database_map();
 process_yppedia_graphs();
+
 compare_island_lists();
+compare_distances();
+
+print_messages();