beginnings of document scrapers mark 2
beginnings of document scrapers mark 2


Former-commit-id: fc862f3bada775436406e0ee8adcd4e7d04ac8f6

--- a/.gitmodules
+++ b/.gitmodules
@@ -10,16 +10,22 @@
 [submodule "lib/Requests"]
 	path = lib/Requests
 	url = https://github.com/rmccue/Requests.git
-[submodule "javascripts/flotr2"]
-	path = javascripts/flotr2
+[submodule "js/flotr2"]
+	path = js/flotr2
 	url = https://github.com/HumbleSoftware/Flotr2.git
 [submodule "lib/phpquery"]
 	path = lib/phpquery
 	url = https://github.com/TobiaszCudnik/phpquery.git
-[submodule "javascripts/sigma"]
-	path = javascripts/sigma
+[submodule "js/sigma"]
+	path = js/sigma
 	url = https://github.com/jacomyal/sigma.js.git
-[submodule "javascripts/bubbletree"]
-	path = javascripts/bubbletree
+[submodule "js/bubbletree"]
+	path = js/bubbletree
 	url = https://github.com/okfn/bubbletree.git
+[submodule "lib/querypath"]
+	path = lib/querypath
+	url = https://github.com/technosophos/querypath.git
+[submodule "lib/amon-php"]
+	path = lib/amon-php
+	url = https://github.com/martinrusev/amon-php.git
 

file:a/about.php -> file:b/about.php
--- a/about.php
+++ b/about.php
@@ -8,10 +8,12 @@
 </div>
 <h2> What is this? </h2>
 Disclo.gs is a project to monitor Australian Federal Government agencies 
-compliance with their <a href="http://www.oaic.gov.au/publications/other_operational/foi_policy_frequently_asked_questions.html#_Toc291837571">"proactive disclosure requirements"</a>.
+compliance with their <a href="http://www.oaic.gov.au/publications/other_operational/foi_policy_frequently_asked_questions.html#_Toc291837571">"proactive disclosure requirements" to make a transparency league table as suggested by gov2 taskforce http://gov2.net.au/blog/2009/09/19/a-league-ladder-of-psi-openness/</a>.
 <h2> Attributions </h2>
-National Archives of Australia, Australian Governments’ Interactive Functions Thesaurus, 2nd edition, September 2005, published at http://www.naa.gov.au/recordkeeping/thesaurus/index.htm.
-
+National Archives of Australia, Australian Governments’ Interactive Functions Thesaurus, 2nd edition, September 2005, published at http://www.naa.gov.au/recordkeeping/thesaurus/index.htm <br/>
+data.gov.au http://data.gov.au/dataset/directory-gov-au-full-data-export/ <br/>
+directory.gov.au <br/>
+australia.gov.au http://australia.gov.au/about/copyright <br/>
 <h2> Open everything </h2>
 All documents released CC-BY 3 AU
 Open source git @

file:b/admin/agls.php (new)
--- /dev/null
+++ b/admin/agls.php
@@ -1,1 +1,35 @@
+<?php
 
+include_once('include/common.inc.php');
+include_header('Webserver and Accessiblity');
+
+echo "<table>
+    <tr><th>name</th><th>function</th></tr>";
+$db = $server->get_db('disclosr-agencies');
+try {
+     $agencies = $db->get_view("app", "byCanonicalName", null, true)->rows;
+
+
+    if ($agencies) {
+        foreach ($agencies as $row) {
+
+            echo "<tr><td>" . $row->value->name . "</td>";
+            if (isset($row->value->metaTags)) {
+                if (is_array($row->value->metaTags)) {
+                        $tags =$row->value->metaTags;
+                } else {
+			$tags = object_to_array($row->value->metaTags);
+                }
+                if (isset($tags['AGLS.Function'])) {
+                    echo "<td>" . $tags['AGLS.Function'] . "</td>";
+                }
+            }
+            echo "</tr>";
+        }
+    }
+} catch (SetteeRestClientException $e) {
+    setteErrorHandler($e);
+}
+include_footer();
+?>
+

--- a/admin/conflicts.php
+++ b/admin/conflicts.php
@@ -1,7 +1,7 @@
 <?php
 
 include_once('../include/common.inc.php');
-include_header();
+include_header('Fix Conflicts');
                 require_once '../lib/php-diff/lib/Diff.php';
                 require_once '../lib/php-diff/lib/Diff/Renderer/Html/SideBySide.php';
 

--- /dev/null
+++ b/admin/genericAgencyFixer.php
@@ -1,1 +1,44 @@
+<?php
 
+include_once("../include/common.inc.php");
+require($basePath . 'lib/phpquery/phpQuery/phpQuery.php');
+
+setlocale(LC_CTYPE, 'C');
+
+
+$db = $server->get_db('disclosr-agencies');
+
+try {
+    $agencies = $db->get_view("app", "byCanonicalName", null, true)->rows;
+    //print_r($rows);
+    foreach ($agencies as $agency) {
+        //echo $agency->value->name . " ".$agency->value->website."<br />\n";
+         // print_r($agency);
+        //hasRestricitiveLicence"	hasRestrictiveLicense -> has Restrictive Licence
+        // "hasYoutube" -> Tube
+        // "comment" -> "comments"
+        if (!isset($agency->value->metaTags) && isset($agency->value->website)) {
+                echo $agency->value->name . " ".$agency->value->website."<br />\n";
+            $agency->value->metaTags = Array();
+            $request = Requests::get($agency->value->website);
+            $html = phpQuery::newDocumentHTML($request->body);
+            phpQuery::selectDocument($html);
+            foreach (pq('meta')->elements as $meta) {
+                $tagName = $meta->getAttribute('name');;
+                $content = $meta->getAttribute('content');
+                if ($tagName != "") {
+echo "$tagName == $content <br>\n";
+                 $agency->value->metaTags[$tagName] = $content;
+                }
+            }
+            //print_r($agency->value->metaTags);
+            $db->save($agency->value);
+            echo "<hr>";
+            flush();
+        }
+    }
+} catch (SetteeRestClientException $e) {
+    setteErrorHandler($e);
+}
+?>
+

--- a/admin/naa-agift-tree.php
+++ b/admin/naa-agift-tree.php
@@ -31,9 +31,9 @@
 <div id="tree-container"></div>
  <div id="viz"></div>
 
-<script type="text/javascript" src="../javascripts/jquery-1.6.2.min.js"></script>
-<script type="text/javascript" src="../javascripts/d3.min.js"></script>
-<script type="text/javascript" src="../javascripts/d3.layout.min.js"></script>
+<script type="text/javascript" src="../js/jquery-1.6.2.min.js"></script>
+<script type="text/javascript" src="../js/d3.min.js"></script>
+<script type="text/javascript" src="../js/d3.layout.min.js"></script>
 
 <script>
     /**

--- a/alaveteli/exportAgencies.csv.php
+++ b/alaveteli/exportAgencies.csv.php
@@ -1,20 +1,6 @@
 <?php
 
 include_once("../include/common.inc.php");
-
-function shortName($name) {
-    $name = trim($name);
-    if (strstr($name,"Minister ") || strstr($name,"Treasurer") || strstr($name,"Parliamentary Secretary")) {
-        $badWords = Array ("Assisting the Prime Minister on","Assisting on"," the "," of "," for "," on "," and "," to ",","," ","'","`");
-        return str_replace($badWords,"",$name);
-    }
-            
-    else {
-    $out = Array();
-    preg_match_all('/[A-Z]/', $name, $out);
-    return implode("", $out[0]);
-    }
-}
 
 setlocale(LC_CTYPE, 'C');
 
@@ -63,38 +49,36 @@
                 $row = Array();
                 $row["#id"] = $agency->id;
                 $row["name"] = trim($agency->value->name);
-                if (isset($agency->value->foiEmail)) {
-                    $row["request_email"] = $agency->value->foiEmail;
-                } else {
-                    if ($agency->value->orgType == "FMA-DepartmentOfState") {
-                        $row["request_email"] = "foi@" . GetDomain($agency->value->website);
-                    } else {
-                        $row["request_email"] = $foiEmail[$agency->value->parentOrg];
+                $row["request_email"] = (isset($agency->value->foiEmail) ? $agency->value->foiEmail : "");
+                $row["short_name"] = (isset($agency->value->shortName) ? $agency->value->shortName : "");
+                $row["notes"] = (isset($agency->value->description) ? $agency->value->description : "");
+
+                $otherBodies = Array();
+                if (isset($agency->value->foiBodies)) {
+                    $otherBodies = array_merge($otherBodies, $agency->value->foiBodies);
+                }
+                if (isset($agency->value->positions)) {
+                    $positions = Array();
+                    foreach ($agency->value->positions as $position) {
+                        $positions[] = "Office of the ".$position;
                     }
+                    $otherBodies = array_merge($otherBodies, $positions);
                 }
-                if (isset($agency->value->shortName)) {
-                    $row["short_name"] = $agency->value->shortName;
-                } else {
-                    $row["short_name"] = shortName($agency->value->name);
+                sort($otherBodies);
+                if (count($otherBodies) > 0) {
+                    $row["notes"] .= "<br/> This department also responds to requests for information held by " . implode(", ", $otherBodies);
                 }
-                $row["notes"] = "";
+
                 $row["publication_scheme"] = (isset($agency->value->infoPublicationSchemeURL) ? $agency->value->infoPublicationSchemeURL : "");
                 $row["home_page"] = (isset($agency->value->website) ? $agency->value->website : "");
                 if ($agency->value->orgType == "FMA-DepartmentOfState") {
-                    $row["tag_string"] = $tag[$agency->value->_id] . " " . $agency->value->orgType;
+                    $row["tag_string"] = $tag[$agency->value->_id];
                 } else {
-                    $row["tag_string"] = $tag[$agency->value->parentOrg] . " " . $agency->value->orgType;
+                    $row["tag_string"] = $tag[$agency->value->parentOrg];
                 }
-
+                $row["tag_string"] .= " " . $agency->value->orgType;
+                $row["tag_string"] .= " federal";
                 fputcsv($fp, array_values($row));
-
-                if (isset($agency->value->foiBodies)) {
-                    foreach ($agency->value->foiBodies as $foiBody) {
-                        $row['name'] = iconv("UTF-8", "ASCII//TRANSLIT",$foiBody);
-                        $row["short_name"] = shortName($foiBody);
-                        fputcsv($fp, array_values($row));
-                    }
-                }
             }
         }
     } catch (SetteeRestClientException $e) {

--- a/bubbletree.php
+++ b/bubbletree.php
@@ -5,13 +5,13 @@
         <meta charset="UTF-8"/> 
         <title>Minimal BubbleTree Demo</title> 
         <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script> 
-        <script type="text/javascript" src="javascripts/bubbletree/lib/jquery.history.js"></script> 
-        <script type="text/javascript" src="javascripts/bubbletree/lib/raphael.js"></script> 
-        <script type="text/javascript" src="javascripts/bubbletree/lib/vis4.js"></script> 
-        <script type="text/javascript" src="javascripts/bubbletree/lib/Tween.js"></script> 
-        <script type="text/javascript" src="javascripts/bubbletree/build/bubbletree.js"></script> 
-        <link rel="stylesheet" type="text/css" href="javascripts/bubbletree/build/bubbletree.css" /> 
-        <script type="text/javascript" src="javascripts/bubbletree/styles/cofog.js"></script> 
+        <script type="text/javascript" src="js/bubbletree/lib/jquery.history.js"></script> 
+        <script type="text/javascript" src="js/bubbletree/lib/raphael.js"></script> 
+        <script type="text/javascript" src="js/bubbletree/lib/vis4.js"></script> 
+        <script type="text/javascript" src="js/bubbletree/lib/Tween.js"></script> 
+        <script type="text/javascript" src="js/bubbletree/build/bubbletree.js"></script> 
+        <link rel="stylesheet" type="text/css" href="js/bubbletree/build/bubbletree.css" /> 
+        <script type="text/javascript" src="js/bubbletree/styles/cofog.js"></script> 
 
 
         <script type="text/javascript"> 

--- /dev/null
+++ b/documents/google676a414ad086cefb.html
@@ -1,1 +1,2 @@
+google-site-verification: google676a414ad086cefb.html
 

--- /dev/null
+++ b/documents/index.php
@@ -1,1 +1,15 @@
+australian disclosure logs
 
+are you looking for more information about:
+contracts
+gov orgs
+lobbyists
+
+1/1/11 title (Dept dfggdfgdf)
+description:
+source link:
+documents:
+    #1 title link
+
+
+rss feed here

--- /dev/null
+++ b/documents/rss.xml.php
@@ -1,1 +1,30 @@
+<?php
 
+// Agency X updated Y,  new files, diff of plain text/link text,
+// feed for just one agency or all
+// This is a minimum example of using the Universal Feed Generator Class
+include("lib/FeedWriter.php");
+//Creating an instance of FeedWriter class.
+$TestFeed = new FeedWriter(RSS2);
+//Setting the channel elements
+//Use wrapper functions for common channelelements
+$TestFeed->setTitle('Last Modified - All');
+$TestFeed->setLink('http://disclosr.lambdacomplex.org/rss.xml.php');
+$TestFeed->setDescription('This is test of creating a RSS 2.0 feed Universal Feed Writer');
+//Retriving informations from database
+$rows = $db->get_view("app", "byLastModified")->rows;
+//print_r($rows);
+foreach ($rows as $row) {
+    //Create an empty FeedItem
+    $newItem = $TestFeed->createNewItem();
+    //Add elements to the feed item
+    $newItem->setTitle($row['name']);
+    $newItem->setLink($row['id']);
+    $newItem->setDate(date("c", $row['metadata']['lastModified']));
+    $newItem->setDescription($row['name']);
+    //Now add the feed item
+    $TestFeed->addItem($newItem);
+}
+//OK. Everything is done. Now genarate the feed.
+$TestFeed->genarateFeed();
+?>

--- /dev/null
+++ b/documents/runScrapers.php

--- /dev/null
+++ b/documents/scrapers/3cd40b1240e987cbcd3f0e67054ce259.py
@@ -1,1 +1,1 @@
-
+http://www.apvma.gov.au/rss/disclosure.rss

--- /dev/null
+++ b/documents/scrapers/8c9421f852c441910bf1d93a57b31d64.py
@@ -1,1 +1,1 @@
-
+http://www.daff.gov.au/about/foi/ips/disclosure_log

--- /dev/null
+++ b/documents/scrapers/be9996f0ac58f71f23d074e82d44ead3.py
@@ -1,1 +1,2 @@
+http://foi.deewr.gov.au/disclosure-log/rss
 

--- /dev/null
+++ b/documents/scrapers/e2a845e55bc9986e6c75c5ad2c508b8d.py
@@ -1,1 +1,1 @@
-
+www.finance.gov.au/foi/disclosure-log/foi-rss.xml

--- /dev/null
+++ b/documents/scrapers/rtk.py
@@ -1,1 +1,1 @@
-
+http://www.righttoknow.org.au/feed/search/%20(latest_status:successful%20OR%20latest_status:partially_successful)

--- /dev/null
+++ b/documents/search.php
@@ -1,1 +1,25 @@
+<?php
+include_once('include/common.inc.php');
+include_header('Search');
+?>
+<div class="foundation-header">
+    <h1><a href="search.php">Search</a></h1>
+</div>
+<form>
+    <input type="text" name="q" value="<?php if (isset($_REQUEST['q']))echo $_REQUEST['q'];?>"/>
+    <input type="submit"/>
+</form>
 
+<?php
+if (isset($_REQUEST['q'])) {
+    $request = Requests::get($serverAddr."disclosr-documents/_fti/_design/lucene/by_all?include_docs=true&q=".$_REQUEST['q']);
+    $results = json_decode($request->body);
+    $db = $server->get_db('disclosr-documents');
+    foreach ($results->rows as $result) {
+        //print_r($result);
+         //$row = $db->get($result->id);
+        echo $result->doc->_id." ".$result->doc->url."<br>".PHP_EOL;
+    }
+}
+include_footer();
+?>

--- a/getAgency.php
+++ b/getAgency.php
@@ -9,7 +9,11 @@
 if (strpos($key, "_") === 0 || $key== "metadata") return;
         echo "<tr>";
 
-        echo "<td>" . $schemas['agency']["properties"][$key]['x-title'] . "<br><small>" . $schemas['agency']["properties"][$key]['description'] . "</small></td><td>";
+        echo "<td>";
+        if (isset($schemas['agency']["properties"][$key])) {
+             echo $schemas['agency']["properties"][$key]['x-title'] . "<br><small>" . $schemas['agency']["properties"][$key]['description']."</small>";
+        }
+         echo                "</td><td>";
         if (is_array($value)) {
             echo "<ol>";
             foreach ($value as $subkey => $subvalue) {

file:a/graph.php -> file:b/graph.php
--- a/graph.php
+++ b/graph.php
@@ -86,9 +86,9 @@
 if ($format == "html") {
     ?>
  <div id="sigma-example" width="960" style="min-height:800px;background-color: #333;"></div>
-  <script src="javascripts/sigma.min.js"></script>
-  <script src="javascripts/sigma/plugins/sigma.parseGexf.js"></script>
-  <script src="javascripts/sigma/plugins/sigma.forceatlas2.js"></script>
+  <script src="js/sigma.min.js"></script>
+  <script src="js/sigma/plugins/sigma.parseGexf.js"></script>
+  <script src="js/sigma/plugins/sigma.forceatlas2.js"></script>
   <script type="text/javascript">function init() {
   // Instanciate sigma.js and customize rendering :
   var sigInst = sigma.init(document.getElementById('sigma-example')).drawingProperties({

--- a/include/common.inc.php
+++ b/include/common.inc.php
@@ -14,6 +14,11 @@
 require_once $basePath.'lib/Requests/library/Requests.php';
 
 Requests::register_autoloader();
+require $basePath."lib/amon-php/amon.php";
+Amon::config(array('address'=> 'http://127.0.0.1:2464', 
+		'protocol' => 'http', 
+		'secret_key' => "I2LJ6dOMmlnXgVAkTPFXd5M3ejkga8Gd2FbBt6iqZdw"));
+Amon::setup_exception_handler();
 # Convert a stdClass to an Array. http://www.php.net/manual/en/language.types.object.php#102735
 
 function object_to_array(stdClass $Class) {

--- a/include/couchdb.inc.php
+++ b/include/couchdb.inc.php
@@ -168,6 +168,7 @@
 $server = new SetteeServer($serverAddr);
 
 function setteErrorHandler($e) {
+    Amon::log($e->getMessage() . " " . print_r($_SERVER,true), array('error'));
     echo $e->getMessage() . "<br>" . PHP_EOL;
 }
 

--- a/include/template.inc.php
+++ b/include/template.inc.php
@@ -66,11 +66,11 @@
 
 
             <!-- Included JS Files -->
-            <script src="<?php echo $basePath; ?>javascripts/foundation.js"></script>
-            <script src="<?php echo $basePath; ?>javascripts/app.js"></script>
+            <script src="<?php echo $basePath; ?>js/foundation.js"></script>
+            <script src="<?php echo $basePath; ?>js/app.js"></script>
            <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
             
-    <script type="text/javascript" src="javascripts/flotr2/flotr2.js"></script>
+    <script type="text/javascript" src="<?php echo $basePath ?>js/flotr2/flotr2.js"></script>
         <?php
         if (strpos($_SERVER['SERVER_NAME'], ".gs")) {
             ?>

file:a/javascripts/app.js (deleted)
--- a/javascripts/app.js
+++ /dev/null
@@ -1,95 +1,1 @@
-/* Foundation v2.1.4 http://foundation.zurb.com */
-$(document).ready(function () {
 
-	/* Use this js doc for all application specific JS */
-
-	/* TABS --------------------------------- */
-	/* Remove if you don't need :) */
-
-	function activateTab($tab) {
-		var $activeTab = $tab.closest('dl').find('a.active'),
-				contentLocation = $tab.attr("href") + 'Tab';
-
-		//Make Tab Active
-		$activeTab.removeClass('active');
-		$tab.addClass('active');
-
-    	//Show Tab Content
-		$(contentLocation).closest('.tabs-content').children('li').hide();
-		$(contentLocation).show();
-	}
-
-	$('dl.tabs').each(function () {
-		//Get all tabs
-		var tabs = $(this).children('dd').children('a');
-		tabs.click(function (e) {
-			activateTab($(this));
-		});
-	});
-
-	if (window.location.hash) {
-		activateTab($('a[href="' + window.location.hash + '"]'));
-	}
-
-	/* ALERT BOXES ------------ */
-	$(".alert-box").delegate("a.close", "click", function(event) {
-    event.preventDefault();
-	  $(this).closest(".alert-box").fadeOut(function(event){
-	    $(this).remove();
-	  });
-	});
-
-
-	/* PLACEHOLDER FOR FORMS ------------- */
-	/* Remove this and jquery.placeholder.min.js if you don't need :) */
-
-	//$('input, textarea').placeholder();
-
-
-
-	/* UNCOMMENT THE LINE YOU WANT BELOW IF YOU WANT IE6/7/8 SUPPORT AND ARE USING .block-grids */
-//	$('.block-grid.two-up>li:nth-child(2n+1)').css({clear: 'left'});
-//	$('.block-grid.three-up>li:nth-child(3n+1)').css({clear: 'left'});
-//	$('.block-grid.four-up>li:nth-child(4n+1)').css({clear: 'left'});
-//	$('.block-grid.five-up>li:nth-child(5n+1)').css({clear: 'left'});
-
-
-
-	/* DROPDOWN NAV ------------- */
-
-	var currentFoundationDropdown = null;
-	$('.nav-bar li a, .nav-bar li a:after').each(function() {
-		$(this).data('clicks', 0);
-	});
-	$('.nav-bar li a, .nav-bar li a:after').live('click', function(e) {
-		e.preventDefault();
-		if (currentFoundationDropdown !== $(this).index() || currentFoundationDropdown === null) {
-			$(this).data('clicks', 0);
-			currentFoundationDropdown = $(this).index();
-		}
-		$(this).data('clicks', ($(this).data('clicks') + 1));
-		var f = $(this).siblings('.flyout');
-		if (!f.is(':visible') && $(this).parent('.has-flyout').length > 1) {
-			$('.nav-bar li .flyout').hide();
-			f.show();
-		} else if (($(this).data('clicks') > 1) || ($(this).parent('.has-flyout').length < 1)) {
-			window.location = $(this).attr('href');
-		}
-	});
-	$('.nav-bar').live('click', function(e) {
-		e.stopPropagation();
-		if ($(e.target).parents().is('.flyout') || $(e.target).is('.flyout')) {
-			e.preventDefault();
-		}
-	});
-	// $('body').bind('touchend', function(e) {
-	// 	if (!$(e.target).parents().is('.nav-bar') || !$(e.target).is('.nav-bar')) {
-	// 		$('.nav-bar li .flyout').is(':visible').hide();
-	// 	}
-	// });
-
-	/* DISABLED BUTTONS ------------- */
-	/* Gives elements with a class of 'disabled' a return: false; */
-
-});
-

directory:a/javascripts/bubbletree (deleted)
--- a/javascripts/bubbletree
+++ /dev/null

--- a/javascripts/d3.layout.min.js
+++ /dev/null
@@ -1,1 +1,1 @@
-(function(){function bh(a,b,c){return a._tree.ancestor.parent==b.parent?a._tree.ancestor:c}function bg(a,b,c){a=a._tree,b=b._tree;var d=c/(b.number-a.number);a.change+=d,b.change-=d,b.shift+=c,b.prelim+=c,b.mod+=c}function bf(a){var b=0,c=0,d=a.children,e=d.length,f;while(--e>=0)f=d[e]._tree,f.prelim+=b,f.mod+=b,b+=f.shift+(c+=f.change)}function be(a,b){function c(a,d){var e=a.children;if(e){var f,g=null,h=-1,i=e.length;while(++h<i)f=e[h],c(f,g),g=f}b(a,d)}c(a,null)}function bd(a,b){return a.depth-b.depth}function bc(a,b){return b.x-a.x}function bb(a,b){return a.x-b.x}function ba(a,b){var c=a.children;if(c){var d,e=c.length,f=-1;while(++f<e)b(d=ba(c[f],b),a)>0&&(a=d)}return a}function _(a){return a.children?a.children[a.children.length-1]:a._tree.thread}function $(a){return a.children?a.children[0]:a._tree.thread}function Z(a,b){return a.parent==b.parent?1:2}function Y(a){var b=a.children;return b?Y(b[b.length-1]):a}function X(a){var b=a.children;return b?X(b[0]):a}function W(a){return a.reduce(function(a,b){return a+b.x},0)/a.length}function V(a){return 1+d3.max(a,function(a){return a.y})}function U(a,b,c){var d=b.r+c.r,e=a.r+c.r,f=b.x-a.x,g=b.y-a.y,h=Math.sqrt(f*f+g*g),i=(e*e+h*h-d*d)/(2*e*h),j=Math.acos(i),k=i*e,l=Math.sin(j)*e;f/=h,g/=h,c.x=a.x+k*f+l*g,c.y=a.y+k*g-l*f}function T(a,b,c,d){var e=a.children;a.x=b+=d*a.x,a.y=c+=d*a.y,a.r*=d;if(e){var f=-1,g=e.length;while(++f<g)T(e[f],b,c,d)}}function S(a){var b=a.children;b?(b.forEach(S),a.r=P(b)):a.r=Math.sqrt(a.value)}function R(a){delete a._pack_next,delete a._pack_prev}function Q(a){a._pack_next=a._pack_prev=a}function P(a){function l(a){b=Math.min(a.x-a.r,b),c=Math.max(a.x+a.r,c),d=Math.min(a.y-a.r,d),e=Math.max(a.y+a.r,e)}var b=Infinity,c=-Infinity,d=Infinity,e=-Infinity,f=a.length,g,h,i,j,k;a.forEach(Q),g=a[0],g.x=-g.r,g.y=0,l(g);if(f>1){h=a[1],h.x=h.r,h.y=0,l(h);if(f>2){i=a[2],U(g,h,i),l(i),M(g,i),g._pack_prev=i,M(i,h),h=g._pack_next;for(var m=3;m<f;m++){U(g,h,i=a[m]);var n=0,o=1,p=1;for(j=h._pack_next;j!==h;j=j._pack_next,o++)if(O(j,i)){n=1;break}if(n==1)for(k=g._pack_prev;k!==j._pack_prev;k=k._pack_prev,p++)if(O(k,i)){p<o&&(n=-1,j=k);break}n==0?(M(g,i),h=i,l(i)):n>0?(N(g,j),h=j,m--):(N(j,h),g=j,m--)}}}var q=(b+c)/2,r=(d+e)/2,s=0;for(var m=0;m<f;m++){var t=a[m];t.x-=q,t.y-=r,s=Math.max(s,t.r+Math.sqrt(t.x*t.x+t.y*t.y))}a.forEach(R);return s}function O(a,b){var c=b.x-a.x,d=b.y-a.y,e=a.r+b.r;return e*e-c*c-d*d>.001}function N(a,b){a._pack_next=b,b._pack_prev=a}function M(a,b){var c=a._pack_next;a._pack_next=b,b._pack_prev=a,b._pack_next=c,c._pack_prev=b}function L(a,b){return a.value-b.value}function J(a){return d3.merge(a.map(function(a){return(a.children||[]).map(function(b){return{source:a,target:b}})}))}function I(a,b){return b.value-a.value}function H(a){return a.value}function G(a){return a.children}function F(a,b){a.sort=d3.rebind(a,b.sort),a.children=d3.rebind(a,b.children),a.links=J,a.value=d3.rebind(a,b.value),a.nodes=function(b){K=!0;return(a.nodes=a)(b)};return a}function E(a){return[d3.min(a),d3.max(a)]}function D(a,b){var c=-1,d=+a[0],e=(a[1]-d)/b,f=[];while(++c<=b)f[c]=e*c+d;return f}function C(a,b){return D(a,Math.ceil(Math.log(b.length)/Math.LN2+1))}function B(a,b){return a+b[1]}function A(a){return a.reduce(B,0)}function z(a){var b=1,c=0,d=a[0][1],e,f=a.length;for(;b<f;++b)(e=a[b][1])>d&&(c=b,d=e);return c}function w(a,b,c){a.y0=b,a.y=c}function v(a){return a.y}function u(a){return a.x}function t(a){return 1}function s(a){return 20}function r(a){var b=0,c=0;a.count=0;if(!a.leaf){var d=a.nodes,e=d.length,f=-1,g;while(++f<e){g=d[f];if(g==null)continue;r(g),a.count+=g.count,b+=g.count*g.cx,c+=g.count*g.cy}}a.point&&(a.leaf||(a.point.x+=Math.random()-.5,a.point.y+=Math.random()-.5),a.count++,b+=a.point.x,c+=a.point.y),a.cx=b/a.count,a.cy=c/a.count}function q(){d3.event.stopPropagation(),d3.event.preventDefault()}function p(){i&&(q(),i=!1)}function o(){!f||(g&&(i=!0,q()),d3.event.type==="mouseup"&&n(),f.fixed=!1,e=h=f=j=null)}function n(){if(!!f){var a=j.parentNode;if(!a){f.fixed=!1,h=f=j=null;return}var b=m(a);g=!0,f.px=b[0]-h[0],f.py=b[1]-h[1],q(),e.resume()}}function m(a){return d3.event.touches?d3.svg.touches(a)[0]:d3.svg.mouse(a)}function l(a){a!==f&&(a.fixed=!1)}function k(a){a.fixed=!0}function c(a,c){if(a===c)return a;var d=b