<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>OUseful.Info, the blog... &#187; Using Aggregated Local Council Spending Data for Reverse Spending (Payments to) Lookups</title>
	<atom:link href="http://blog.ouseful.info/2012/05/28/using-aggregated-local-council-spending-data-for-reverse-spending-payments-to-lookups/feed/?withoutcomments=1" rel="self" type="application/rss+xml" />
	<link>http://blog.ouseful.info</link>
	<description>Trying to find useful things to do with emerging technologies in open education</description>
	<lastBuildDate>Wed, 22 May 2013 08:17:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.ouseful.info' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>OUseful.Info, the blog... &#187; Using Aggregated Local Council Spending Data for Reverse Spending (Payments to) Lookups</title>
		<link>http://blog.ouseful.info</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.ouseful.info/osd.xml" title="OUseful.Info, the blog..." />
	<atom:link rel='hub' href='http://blog.ouseful.info/?pushpress=hub'/>
		<item>
		<title>Using Aggregated Local Council Spending Data for Reverse Spending (Payments to) Lookups</title>
		<link>http://blog.ouseful.info/2012/05/28/using-aggregated-local-council-spending-data-for-reverse-spending-payments-to-lookups/</link>
		<comments>http://blog.ouseful.info/2012/05/28/using-aggregated-local-council-spending-data-for-reverse-spending-payments-to-lookups/#comments</comments>
		<pubDate>Mon, 28 May 2012 15:40:27 +0000</pubDate>
		<dc:creator>Tony Hirst</dc:creator>
				<category><![CDATA[Anything you want]]></category>

		<guid isPermaLink="false">http://blog.ouseful.info/?p=7933</guid>
		<description><![CDATA[Knowing how much a council spent on this or that activity may contribute to transparency, but it also provides us with an opportunity for tracking the extent to which a council may provide services to other councils in exchange for payment (a &#8220;reverse spend&#8221;, if you will&#8230;) In Inter-Council Payments and the Google Fusion Tables [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ouseful.info&#038;blog=325417&#038;post=7933&#038;subd=ouseful&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Knowing how much a council spent on this or that activity may contribute to transparency, but it also provides us with an opportunity for tracking the extent to which a council may provide services to other councils in exchange for payment (a &#8220;reverse spend&#8221;, if you will&#8230;)</p>
<p>In <a href="http://blog.ouseful.info/2012/05/21/inter-council-payments-in-the-new-look-google-fusion-tables/">Inter-Council Payments and the Google Fusion Tables Network Graph</a>, I demonstrated a recipe for graphing the extent to which county councils made payments to each other using data scraped from OpenlyLocal. But how about if we stick with a tabular view, and just work directly with the data contained in the Scraperwiki database?</p>
<p>One of the nice things about Scraperwiki is that it provides us with API access to the datatables in each scraper. Here&#8217;s the <a href="https://scraperwiki.com/docs/api?name=local_spend_on_corporates#sqlite">API for my &#8220;local spend&#8221; scraper</a>:</p>
<p><a href="https://scraperwiki.com/docs/api?name=local_spend_on_corporates#sqlite"><img src="http://ouseful.files.wordpress.com/2012/05/scraperwiki-api.png?w=700&#038;h=406" alt="" title="scraperwiki api" width="700" height="406" class="alignnone size-full wp-image-7934" /></a></p>
<p>We can use the API explorer to generate URLs to HTML tables containing the results of a query, or JSON or CSV feeds of the results. We can also preview the result of a query:</p>
<p><a href="http://ouseful.files.wordpress.com/2012/05/scraperwikiapi-previw-table.png"><img src="http://ouseful.files.wordpress.com/2012/05/scraperwikiapi-previw-table.png?w=700" alt="" title="scraperwikiapi previw table"   class="alignnone size-full wp-image-7935" /></a></p>
<p>So what sorts of query can we run? As the database behind Scraperwiki scrapers is SQLite, the way in is through SQL like queries. SQL (<em>Structured Query Language</em>) is a query language for making very powerful searches over database tables (it also provides the basis for queries that treat Google spreadsheets or Google Fusion Tables as a database).</p>
<p>Here&#8217;s a sample of some queries we can run over the local spending data on my Scraperwiki scraper. The table I&#8217;m calling (think of a table like a particular worksheet in a spreadsheet) is <em>publicMesh</em>, where I have aggregated data from OpenlyLocal that relates to total spend made to various public bodies from other public bodies. <em>supplier</em> is the entity that received a sum from another body; <em>payer</em> and <em>supplyingTo</em> both relate to the entity that paid another body. (I guess &#8220;supplier&#8221; is not necessarily always the right term, e.g. when a payer is making a grant or award payment?)</p>
<p>The queries are structured as follows: <tt>select oneThing, anotherThing from 'table'</tt> says &#8220;grab the columns &#8216;oneThing&#8217; and &#8216;anotherThing&#8217; from the database table &#8216;table&#8217;&#8221;; <tt>where item relation condition</tt> lets us limit the results to those where the value of the &#8216;item&#8217; column meets some condition (such as, <em>total &gt; 1000</em>, which only selects results where the corresponding value in the total column is greater than 1000; or <em>thing like &#8216;%term%&#8217;</em> which searches for rows where the contents of the &#8216;thing&#8217; column contains &#8216;term&#8217; (the % is like a wildcard character)).</p>
<ul>
<li><tt>select supplier,supplyingTo,total from `publicMesh` where normsupplier like '%county hampshire%' and normsupplyingTo like '%arts%' order by total desc</tt> &#8211; look (crudely) for Arts Council payments to Hampshire County Council (<a href="https://api.scraperwiki.com/api/1.0/datastore/sqlite?format=htmltable&amp;name=local_spend_on_corporates&amp;query=select%20supplier%2CsupplyingTo%2Ctotal%20from%20%60publicMesh%60%20where%20normsupplier%20like%20'%25county%20hampshire%25'%20and%20normsupplyingTo%20like%20'%25arts%25'%20order%20by%20total%20desc">result</a>)</li>
<li><tt>select supplier,supplyingTo,total from `publicMesh` where normsupplier like '%county hampshire%' and normsupplyingTo like '%county%' order by total desc</tt> &#8211; see which other County Councils Hampshire is providing service to (<a href="https://api.scraperwiki.com/api/1.0/datastore/sqlite?format=htmltable&amp;name=local_spend_on_corporates&amp;query=select%20supplier%2CsupplyingTo%2Ctotal%20from%20%60publicMesh%60%20where%20normsupplier%20like%20'%25county%20hampshire%25'%20and%20normsupplyingTo%20like%20'%25county%25'%20order%20by%20total%20desc">result</a>)</li>
<li><tt>select supplier,supplyingTo,total from `publicMesh` where normsupplier like '%county hampshire%' and normsupplyingTo like '%borough%' order by total desc</tt> &#8211; alternatively, what councils with &#8216;Borough&#8221; in their name has Hampshire County Council received funding from?  (<a href="https://api.scraperwiki.com/api/1.0/datastore/sqlite?format=htmltable&amp;name=local_spend_on_corporates&amp;query=select%20supplier%2CsupplyingTo%2Ctotal%20from%20%60publicMesh%60%20where%20normsupplier%20like%20'%25county%20hampshire%25'%20and%20normsupplyingTo%20like%20'%25borough%25'%20order%20by%20total%20desc">result</a>)</li>
<li><tt>select supplyingTo,sum(total) as amount,count(payer) from `publicMesh` where normsupplier like '%county hampshire%' group by payer order by amount desc</tt> &#8211; if you click through on the &#8220;arts&#8221; link above, you&#8217;ll see that the Arts Council makes various payments to different entities associated with Hampshire County Council (Hampshire County Council; Arts Service, Hampshire County Council; Hampshire County Council &#8211; Schools Landscape Programme; Hampshire County Council Music Service). It&#8217;s possible aggregate the separate totals for each of this under a single &#8220;Hampshire County Council&#8221; banner (though note that it may not always make sense to do this sort of grouping operation. The <em>sum</em> operator adds together (sums) all the totals from items that are grouped together by the <em>group by payer</em> statement, that bundles together items with the same payer. count(payer) counts just how many lines from the same payer are grouped together (<a href="https://api.scraperwiki.com/api/1.0/datastore/sqlite?format=htmltable&amp;name=local_spend_on_corporates&amp;query=select%20supplyingTo%2Csum(total)%20as%20amount%2Ccount(payer)%20from%20%60publicMesh%60%20where%20normsupplier%20like%20'%25county%20hampshire%25'%20group%20by%20payer%20order%20by%20amount%20desc">result</a>)</li>
</ul>
<p>Hmm&#8230;methinks there may be an opportunity here for an tutorial on writing SQL queries&#8230;? Maybe this would be a good context for a pathway on SocialLearn&#8230;?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ouseful.wordpress.com/7933/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ouseful.wordpress.com/7933/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ouseful.info&#038;blog=325417&#038;post=7933&#038;subd=ouseful&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.ouseful.info/2012/05/28/using-aggregated-local-council-spending-data-for-reverse-spending-payments-to-lookups/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/abbd9f90565ce9ae4d065d93a81d8c03?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">Tony Hirst</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/05/scraperwiki-api.png" medium="image">
			<media:title type="html">scraperwiki api</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/05/scraperwikiapi-previw-table.png" medium="image">
			<media:title type="html">scraperwikiapi previw table</media:title>
		</media:content>
	</item>
	</channel>
</rss>
