<?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; ergastAPI</title>
	<atom:link href="http://blog.ouseful.info/tag/ergastapi/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>Mon, 20 May 2013 17:48:41 +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; ergastAPI</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>More Shiny Goodness &#8211; Tinkering With the Ergast Motor Racing Data API</title>
		<link>http://blog.ouseful.info/2012/12/04/more-shiny-goodness-tinkering-with-the-ergast-motor-racing-data-api/</link>
		<comments>http://blog.ouseful.info/2012/12/04/more-shiny-goodness-tinkering-with-the-ergast-motor-racing-data-api/#comments</comments>
		<pubDate>Tue, 04 Dec 2012 14:14:40 +0000</pubDate>
		<dc:creator>Tony Hirst</dc:creator>
				<category><![CDATA[Rstats]]></category>
		<category><![CDATA[Tinkering]]></category>
		<category><![CDATA[ergastAPI]]></category>
		<category><![CDATA[f1datajunkie]]></category>
		<category><![CDATA[Rstudio]]></category>
		<category><![CDATA[Shiny]]></category>

		<guid isPermaLink="false">http://blog.ouseful.info/?p=9230</guid>
		<description><![CDATA[I had a bit of a play with Shiny over the weekend, using the Ergast Motor Racing Data API and the magical Shiny library for R, that makes building interactive, browser based applications around R a breeze. As this is just a quick heads-up/review post, I&#8217;ll largely limit myself to a few screenshots. When I [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ouseful.info&#038;blog=325417&#038;post=9230&#038;subd=ouseful&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I had a bit of a play with Shiny over the weekend, using the <a href="http://ergast.com/mrd/">Ergast Motor Racing Data API</a> and the magical <a href="http://www.rstudio.com/shiny/">Shiny library for R</a>, that makes building interactive, browser based applications around R a breeze.</p>
<p>As this is just a quick heads-up/review post, I&#8217;ll largely limit myself to a few screenshots. When I get a chance, I&#8217;ll try to do a bit more of a write-up, though this may actually just take the form of more elaborate documentation of the app, both within the code and in the form of explanatory text in the app itself.</p>
<p>If you want to try ou the app, you can find an instance here: <a href="http://glimmer.rstudio.com/psychemedia/f1ergastdemo">F1 2012 Laptime Explorer</a>. The <a href="https://gist.github.com/4188912">code is also available</a>.</p>
<p>Here&#8217;s the initial view &#8211; the frist race of the season is selected as a default and data loaded in. The driver list is for all drivers represented during the season.</p>
<p><img src="http://ouseful.files.wordpress.com/2012/12/f1-2012-shiny-ergast-explorer.png?w=700&#038;h=404" alt="f1 2012 shiny ergast explorer" width="700" height="404" class="alignnone size-full wp-image-9254" /></p>
<p>THe driver selectors allow us to just display traces for selected drivers.</p>
<p>The <em>Race History chart</em> is a classic results chart. It show the difference between the race time to date for each driver, by lap, compared to the average lap time for the winner times the lap number. (As such, this is an offline statistic &#8211; it is calculated when the winner&#8217;s overall average laptime is known).</p>
<p><img src="http://ouseful.files.wordpress.com/2012/12/race-hisotry-classic-chart.png?w=700&#038;h=350" alt="race hisotry - classic chart" width="700" height="350" class="alignnone size-full wp-image-9253" /></p>
<p>Variants of the classic Race History chart are possible, for example, using different base line times, but I haven&#8217;t implemented any of them  &#8211; or the necessary UI controls. Yet&#8230;</p>
<p>The <em>Lap Chart</em> is another classic:</p>
<p><img src="http://ouseful.files.wordpress.com/2012/12/lap-chart-another-classic.png?w=700&#038;h=356" alt="Lap chart - another classic" width="700" height="356" class="alignnone size-full wp-image-9252" /></p>
<p>Annotations for this chart are also supported, describing all drivers who final status was not &#8220;Finished&#8221;.</p>
<p><img src="http://ouseful.files.wordpress.com/2012/12/lap-chart-with-annotations.png?w=700&#038;h=344" alt="lap chart with annotations" width="700" height="344" class="alignnone size-full wp-image-9251" /></p>
<p>The <em>Lap Evolution chart</em> shows how each driver&#8217;s laptime evolved over the course of the race compared with the fastest overall recorded laptime.</p>
<p><img src="http://ouseful.files.wordpress.com/2012/12/lap-evolution.png?w=700&#038;h=348" alt="Lap evolution" width="700" height="348" class="alignnone size-full wp-image-9250" /></p>
<p>The <em>Personal Lap Evolution</em> chart shows how each driver&#8217;s laptime evolved over the course of the race compared with their personal fastest laptime.</p>
<p><img src="http://ouseful.files.wordpress.com/2012/12/personal-lap-evolution.png?w=700&#038;h=349" alt="Personal lap evolution" width="700" height="349" class="alignnone size-full wp-image-9249" /></p>
<p>The <em>Personal Deltas Chart</em> shows the difference between one laptime and the next for each driver.</p>
<p><img src="http://ouseful.files.wordpress.com/2012/12/personal-deltas.png?w=700&#038;h=366" alt="Personal deltas" width="700" height="366" class="alignnone size-full wp-image-9248" /></p>
<p>The <em>Race Summary Chart</em> is a chart of my own design that tries to capture notable features relating to race position &#8211; the grid position (blue circle), final classification (red circle), position at the end of the first lap (the + or horizontal bar). The violin plot shows the distribution of how many laps the driver spent in each race position. Where the chart is wide, the driver spent a large number of laps in that position.</p>
<p><img src="http://ouseful.files.wordpress.com/2012/12/race-summary.png?w=700&#038;h=422" alt="race summary" width="700" height="422" class="alignnone size-full wp-image-9247" /></p>
<p>The x-axis ordering pulls out different features about how the race progressed. I need to add in a control that lets the user select different orderings.</p>
<p>Finally, the <em>Fast Lap text scatterplot</em> shows the fastest laptime for each driver and the lap at which they recorded it.</p>
<p><img src="http://ouseful.files.wordpress.com/2012/12/fastlaps.png?w=700&#038;h=357" alt="fastlaps" width="700" height="357" class="alignnone size-full wp-image-9246" /></p>
<p>So &#8211; that&#8217;s a quick review of the app. All in all it took maybe 3 hours getting my head round the data parsing, 2-3 hours figuring what I wanted to do and learning how to do it in Shiny, and a couple of hours doing it/starting to document/annotate it. Next time, it&#8217;ll be much quicker&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ouseful.wordpress.com/9230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ouseful.wordpress.com/9230/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ouseful.info&#038;blog=325417&#038;post=9230&#038;subd=ouseful&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.ouseful.info/2012/12/04/more-shiny-goodness-tinkering-with-the-ergast-motor-racing-data-api/feed/</wfw:commentRss>
		<slash:comments>3</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/12/f1-2012-shiny-ergast-explorer.png" medium="image">
			<media:title type="html">f1 2012 shiny ergast explorer</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/12/race-hisotry-classic-chart.png" medium="image">
			<media:title type="html">race hisotry - classic chart</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/12/lap-chart-another-classic.png" medium="image">
			<media:title type="html">Lap chart - another classic</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/12/lap-chart-with-annotations.png" medium="image">
			<media:title type="html">lap chart with annotations</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/12/lap-evolution.png" medium="image">
			<media:title type="html">Lap evolution</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/12/personal-lap-evolution.png" medium="image">
			<media:title type="html">Personal lap evolution</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/12/personal-deltas.png" medium="image">
			<media:title type="html">Personal deltas</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/12/race-summary.png" medium="image">
			<media:title type="html">race summary</media:title>
		</media:content>

		<media:content url="http://ouseful.files.wordpress.com/2012/12/fastlaps.png" medium="image">
			<media:title type="html">fastlaps</media:title>
		</media:content>
	</item>
		<item>
		<title>F1 Championship Points as a d3.js Powered Sankey Diagram</title>
		<link>http://blog.ouseful.info/2012/05/24/f1-championship-points-as-a-d3-js-powered-sankey-diagram/</link>
		<comments>http://blog.ouseful.info/2012/05/24/f1-championship-points-as-a-d3-js-powered-sankey-diagram/#comments</comments>
		<pubDate>Thu, 24 May 2012 08:39:26 +0000</pubDate>
		<dc:creator>Tony Hirst</dc:creator>
				<category><![CDATA[Anything you want]]></category>
		<category><![CDATA[onlinejournalismblog]]></category>
		<category><![CDATA[ergastAPI]]></category>
		<category><![CDATA[f1datajunkie]]></category>

		<guid isPermaLink="false">http://blog.ouseful.info/?p=7899</guid>
		<description><![CDATA[d3.js crossed my path a couple of times yesterday: firstly, in the form of an enquiry about whether I&#8217;d be interested in writing a book on d3.js (I&#8217;m not sure I&#8217;m qualified: as I responded, I&#8217;m more of a script kiddie who sees things I can reuse, rather than have any understanding at all about [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ouseful.info&#038;blog=325417&#038;post=7899&#038;subd=ouseful&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>d3.js crossed my path a couple of times yesterday: firstly, in the form of an enquiry about whether I&#8217;d be interested in writing a book on d3.js (I&#8217;m not sure I&#8217;m qualified: as I responded, I&#8217;m more of a script kiddie who sees things I can reuse, rather than have any understanding at all about how d3.js does what it does&#8230;); secondly, via a link to d3.js creator Mike Bostock&#8217;s new demo of <a href="http://bost.ocks.org/mike/sankey/">Sankey diagrams built using d3.js</a>:</p>
<p><a href="http://bost.ocks.org/mike/sankey/"><img src="http://ouseful.files.wordpress.com/2012/05/sankeydiagram-d3js.png?w=700&#038;h=560" alt="" title="sankeyDiagram-d3js" width="700" height="560" class="alignnone size-full wp-image-7901" /></a></p>
<p>Hmm&#8230; Sankey diagrams are good for visualising flow, so to get to grips myself with seeing if I could plug-and-play with the component, I needed an appropriate data set. F1 related data is usually my first thought as far as testbed data goes (no confidences to break, the STEM/innovation outreach/tech transfer context, etc etc) so what things flow in F1? What quantities are conserved whilst being passed between different classes of entity? How about points&#8230; points are awarded on a per race basis to drivers who are members of teams. It&#8217;s also a championship sport, run over several races. The individual Driver Championship is a competition between drivers to accumulate the most points over the course of the season, and the Constructor Chanmpionship is a battle between teams. Which suggests to me that a Sankey plot of points from races to drivers and then constructors might work?</p>
<p>So what do we need to do? First up, look at the source code for the demo using View Source. Here&#8217;s the relevant bit:</p>
<p><a href="http://ouseful.files.wordpress.com/2012/05/sankey-get-data.png"><img src="http://ouseful.files.wordpress.com/2012/05/sankey-get-data.png?w=700" alt="" title="sankey get data"   class="alignnone size-full wp-image-7903" /></a></p>
<p>Data is being pulled in from a relatively addressed file, <em>energy.json</em>. Let&#8217;s see what it looks like:</p>
<p><a href="http://ouseful.files.wordpress.com/2012/05/sanky-data.png"><img src="http://ouseful.files.wordpress.com/2012/05/sanky-data.png?w=700" alt="" title="sankey data"   class="alignnone size-full wp-image-7902" /></a></p>
<p>Okay &#8211; a node list and an edge list. From previous experience, I know that there is a d3.js <a href="http://networkx.lanl.gov/reference/readwrite.json_graph.html">JSON exporter</a> built into the Python networkx library, so maybe we can generate the data file from a network representation of the data in networkx?</p>
<p>Here we are: <a href="http://networkx.lanl.gov/reference/generated/networkx.readwrite.json_graph.node_link_data.html#networkx.readwrite.json_graph.node_link_data">node_link_data(G)</a> &#8220;[r]eturn data in node-link format that is suitable for JSON serialization and use in Javascript documents.&#8221;</p>
<p>Next step &#8211; getting the data. I&#8217;ve already done a demo of visualising <a href="https://views.scraperwiki.com/run/treemap_demo_-_multi-round_sports_event/?">F1 championship points sourced from the Ergast motor racing API as a treemap</a> (but not blogged it? Hmmm&#8230;. must fix that) that draws on a JSON data feed <a href="https://scraperwiki.com/views/ergast_championship_gviz/">constructed from data extracted from the Ergast API</a> so I can clone that code and use it as the basis for constructing a directed graph that represents points allocations: race nodes are linked to driver nodes with edges weighted by points scored in that race, and driver nodes are connected to teams by edges weighted according to the total number of points the driver has earned so far. (Hmm, that gives me an idea for a better way of coding the weight for that edge&#8230;)</p>
<p>I don&#8217;t have time to blog the how to of the code right now &#8211; train and boat to catch &#8211; but will do so later. If you want to look at the code, it&#8217;s here: <a href="https://scraperwiki.com/views/ergast_championship_nodelist/">Ergast Championship nodelist</a>. And here&#8217;s the result &#8211; <a href="https://views.scraperwiki.com/run/f1_championship_sankey_demo/">F1 Chanpionship 2012 Points as a Sankey Diagram</a>:</p>
<p><a href="http://ouseful.files.wordpress.com/2012/05/f1-points-sankey-diagram.png"><img src="http://ouseful.files.wordpress.com/2012/05/f1-points-sankey-diagram.png?w=700&#038;h=369" alt="" title="F1 points sankey diagram" width="700" height="369" class="alignnone size-full wp-image-7900" /></a></p>
<p>See what I mean about being a cut and paste script kiddie?!;-)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ouseful.wordpress.com/7899/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ouseful.wordpress.com/7899/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ouseful.info&#038;blog=325417&#038;post=7899&#038;subd=ouseful&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.ouseful.info/2012/05/24/f1-championship-points-as-a-d3-js-powered-sankey-diagram/feed/</wfw:commentRss>
		<slash:comments>4</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/sankeydiagram-d3js.png" medium="image">
			<media:title type="html">sankeyDiagram-d3js</media:title>
		</media:content>

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

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

		<media:content url="http://ouseful.files.wordpress.com/2012/05/f1-points-sankey-diagram.png" medium="image">
			<media:title type="html">F1 points sankey diagram</media:title>
		</media:content>
	</item>
	</channel>
</rss>
