From 0a4c9fe7e73cb5802471cbc0d975d3c7daa6513c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 27 Aug 2009 17:46:33 +0100 Subject: [PATCH 1/1] Break process_yppedia_graphs into multiple subs --- yarrg/yppedia-chart-parser | 39 ++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/yarrg/yppedia-chart-parser b/yarrg/yppedia-chart-parser index e315061..09e8fe8 100755 --- a/yarrg/yppedia-chart-parser +++ b/yarrg/yppedia-chart-parser @@ -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(); -- 2.30.2