chiark / gitweb /
Break process_yppedia_graphs into multiple subs
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 27 Aug 2009 16:46:33 +0000 (17:46 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 27 Aug 2009 16:46:33 +0000 (17:46 +0100)
yarrg/yppedia-chart-parser

index e3150611cb36eb75a6a3eb117e276982ad5aebd0..09e8fe8b1b82aa22e7140bf5b6ff3069310a499d 100755 (executable)
@@ -55,7 +55,7 @@ sub nn_xy ($$) {
     return $n;
 }
 
-sub parse_yppedia_map () {
+sub yppedia_chart_parse () {
     # We don't even bother with tag soup; instead we do line-oriented parsing.
 
     while (<>) {
@@ -111,7 +111,7 @@ sub parse_yppedia_map () {
     }
 }
 
-sub parse_database_map () {
+sub database_fetch_ocean () {
     my ($row,$sth);
     $sth= $dbh->prepare('SELECT islandname, archipelago FROM islands');
     $sth->execute();
@@ -130,26 +130,22 @@ sub parse_database_map () {
     }
 }                       
 
-sub process_yppedia_graphs () {
-
+sub yppedia_graphs_prune_boring () {
     # Prune the LP database by eliminating boring intermediate vertices
-    #
     foreach my $delete ($widists->vertices()) {
        next if exists $winode2island{$delete};
        my @neigh= $widists->neighbours($delete);
        next unless @neigh==2;
-#      my @aneigh= $wiarchs->has_vertex($delete)
-#          ? $wiarchs->neighbours($delete) : ();
-#      next unless @aneigh==0 || @aneigh==2;
        my $weight= 0;
        map { $weight += $widists->get_edge_weight($delete, $_) } @neigh;
        $widists->add_weighted_edge(@neigh, $weight);
        $widists->delete_vertex($delete);
        printf DEBUG "%-5s elide %5s %-5s %2d\n", $delete, @neigh, $weight;
     }
+}
 
+sub yppedia_graphs_check () {
     # Check that it's connected.
-    #
     foreach my $cc ($widists->connected_components()) {
        next if 2*@$cc > $widists->vertices();
        my $m= "disconnected league point(s):";
@@ -159,9 +155,10 @@ sub process_yppedia_graphs () {
        }
        warning($m);
     }
+}
 
+sub yppedia_archs_sourceinfo () {
     # Assign archipelagoes according to the source-info file
-    #
     foreach my $arch (sort keys %{ $oceans{$ocean} }) {
        foreach my $islename (sort keys %{ $oceans{$ocean}{$arch} }) {
            my $islenode= $wiisland2node{$islename};
@@ -177,12 +174,9 @@ sub process_yppedia_graphs () {
            $wiccix2arch{$ccix}= $arch;
        }
     }
+}
 
-    # Compute all-pairs-shortest-paths on dist, which is the
-    # actual distances between all LPs.
-    #
-    $wialldists= $widists->APSP_Floyd_Warshall();
-
+sub yppedia_archs_chart_labels () {
     # Assign archipelago labels to groups of islands
     #
     foreach my $label (@wiarchlabels) {
@@ -230,7 +224,9 @@ sub process_yppedia_graphs () {
        $wiccix2arch{$ccix}= $arch;
 #      print "$ccix $arch ::\n$desc\n";
     }
+}
 
+sub yppedia_archs_fillbynearest() {
     # Assign islands not labelled above to archipelagoes.
     #
     # We do this by, for each connected component (set of islands
@@ -359,11 +355,18 @@ sub compare_distances () {
 }
 
 parse_info_serverside();
+
 db_setocean($ocean);
 db_connect();
-parse_yppedia_map();
-parse_database_map();
-process_yppedia_graphs();
+database_fetch_ocean();
+
+yppedia_chart_parse();
+yppedia_graphs_prune_boring();
+yppedia_graphs_check();
+yppedia_archs_sourceinfo();
+$wialldists= $widists->APSP_Floyd_Warshall();
+yppedia_archs_chart_labels();
+yppedia_archs_fillbynearest();
 
 compare_island_lists();
 compare_distances();