<?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/"
	>

<channel>
	<title>Trouble With Dreams &#187; scrobbler</title>
	<atom:link href="http://troublewithdreams.com/category/code/scrobbler/feed/" rel="self" type="application/rss+xml" />
	<link>http://troublewithdreams.com</link>
	<description></description>
	<lastBuildDate>Wed, 07 Jul 2010 22:36:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Django experiments</title>
		<link>http://troublewithdreams.com/2010/04/05/django-experiments/</link>
		<comments>http://troublewithdreams.com/2010/04/05/django-experiments/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 22:44:53 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[last.fm]]></category>
		<category><![CDATA[scrobbler]]></category>
		<category><![CDATA[twd]]></category>

		<guid isPermaLink="false">http://troublewithdreams.com/?p=337</guid>
		<description><![CDATA[I&#8217;ve been playing about with Django and Last.fm data, intended as an eventual upgrade to historical charts.  It&#8217;s fun .. I now know I play most music in March and November (university deadline time!), that my top three artists of 2010 so far are Animal Collective, Grizzly Bear and The Delgados, and that my [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing about with Django and Last.fm data, intended as an eventual upgrade to <a href="/scrobbler"/>historical charts</a>.  It&#8217;s fun .. I now know I play most music in March and November (university deadline time!), that my top three artists of 2010 so far are <a href="http://www.last.fm/music/Animal Collective">Animal Collective</a>, <a href="http://www.last.fm/music/Grizzly Bear">Grizzly Bear</a> and <a href="http://www.last.fm/music/The Delgados">The Delgados</a>, and that my favourite three discoveries are <a href="http://www.last.fm/music/Starless &#038; Bible Black">Starless &amp; Bible Black</a>, <a href="http://www.last.fm/music/RM Hubbert">RM Hubbert</a> and <a href="http://www.last.fm/music/Soweto Kinch">Soweto Kinch</a>.</p>
<p>I also discovered that using a foreign key of an object returned by a Django QuerySet as a dictionary key prompts Django to look the actual data up.  I had something like the following:</p>
<blockquote><p><code>class WeekData(models.Model):<br />
&nbsp;&nbsp;&nbsp;&nbsp;artist = models.ForeignKey(Artist)<br />
&nbsp;&nbsp;&nbsp;&nbsp;plays  = models.PositiveIntegerField()<br />
&nbsp;&nbsp;&nbsp;&nbsp;..</code><br />
<code><br />
tracking = defaultdict(int)<br />
for week in WeekData.objects.all():<br />
&nbsp;&nbsp;&nbsp;&nbsp;tracking[week.artist] += week.plays<br />
</code>
</p></blockquote>
<p>The dictionary update was taking <em>ages</em>.  Confused, I enabled Mysql&#8217;s logging and discovered 25,000 lines of the following..</p>
<blockquote><p>
<code>SELECT `id`, `name` FROM `muncher_artist` WHERE `id` = 22<br />
SELECT `id`, `name` FROM `muncher_artist` WHERE `id` = 23<br />
SELECT `id`, `name` FROM `muncher_artist` WHERE `id` = 24<br />
SELECT `id`, `name` FROM `muncher_artist` WHERE `id` = 25</code>
</p></blockquote>
<p>At which point I realised that using <code>week.artist</code> as the key here looks up the artist <em>every</em> time, meaning 25,000 useless database queries and a really, really slow function.  Perhaps I was being too hopeful in my expectation that Django would be clever.</p>
<p>Changing the last line to:</p>
<blockquote><p>
<code>tracking[week.artist_id] += week.plays</code></p></blockquote>
<p>sped the function up by a factor of ten and lets me produce images like this in reasonable time:</p>
<p><img src="http://troublewithdreams.com/sometimesiwrite/wp-content/uploads/2010/04/tophist-snippet.png" alt="" title="tophist-snippet" class="aligncenter size-full wp-image-345" /></p>
<p>It&#8217;s showing which artists occupy which chart positions as the weeks go by.  The dark black line is for Fleet Foxes .. seems I went pretty mad for them :o</p>
]]></content:encoded>
			<wfw:commentRss>http://troublewithdreams.com/2010/04/05/django-experiments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sunburn</title>
		<link>http://troublewithdreams.com/2009/06/11/sunburn/</link>
		<comments>http://troublewithdreams.com/2009/06/11/sunburn/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 22:05:35 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[last.fm]]></category>
		<category><![CDATA[scrobbler]]></category>

		<guid isPermaLink="false">http://troublewithdreams.com/?p=271</guid>
		<description><![CDATA[Exams are over, the sun came and went, I got a first (hurrah!), a job for a couple of months and now it&#8217;s just .. working out what now? Completing Chrono Trigger is my first priority :D
Spent some time moving the last.fm charts thing to Python, because Python is tasty, PHP is clumsy, and matplotlib [...]]]></description>
			<content:encoded><![CDATA[<p>Exams are over, the sun came and went, I got a first (hurrah!), a job for a couple of months and now it&#8217;s just .. working out what now? Completing Chrono Trigger is my first priority :D</p>
<p>Spent some time moving the <a href="/scrobbler">last.fm charts</a> thing to Python, because Python is tasty, PHP is clumsy, and <a href="http://matplotlib.sourceforge.net/">matplotlib</a> is a superb piece of kit.</p>
<p>Here&#8217;s a histogram of the number of tracks I&#8217;ve listened to each week for the last few years:</p>
<p><img src="http://troublewithdreams.com/sometimesiwrite/wp-content/uploads/2009/06/last-fm-histogrampng.png" alt="last-fm-histogrampng" title="last-fm-histogrampng" width="516" height="394" class="aligncenter size-full wp-image-285" /></p>
<p>(<em>x</em> is the number of tracks in a week.)  I looked at a few friends&#8217; and there seemed quite a split between those roughly following a Gaussian distribution and those following something rather more exponential.  I should experiment with different features of matplotlib, maybe narrow those bins a little.  I&#8217;ve lots of little plans for other graphs and combinations.</p>
<hr />
<p>Finally, there&#8217;s a great little piece about a quirk of the number 1/89 <a href="http://www.geom.uiuc.edu/~rminer/1over89/">here</a>.  Sum the numbers of the Fibonacci Sequence in the following manner:</p>
<blockquote>
<pre>  .01
  .001
  .0002
  .00003
  .000005
  .0000008
  .00000013
  .000000021
  .0000000034
  .00000000055
  .000000000089
  .0000000000144
        .
    +   .
        .
----------------
  .01123595505...    = 1/89</pre>
</blockquote>
<p>The link has an outline proof about why it&#8217;s true.</p>
]]></content:encoded>
			<wfw:commentRss>http://troublewithdreams.com/2009/06/11/sunburn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Charts update</title>
		<link>http://troublewithdreams.com/2009/03/24/charts-update/</link>
		<comments>http://troublewithdreams.com/2009/03/24/charts-update/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 13:15:09 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[last.fm]]></category>
		<category><![CDATA[scrobbler]]></category>

		<guid isPermaLink="false">http://troublewithdreams.com/?p=256</guid>
		<description><![CDATA[Just a note to say I updated Historical Charts to take advantage of Last.fm automatically correcting misspelled info.
]]></description>
			<content:encoded><![CDATA[<p>Just a note to say I updated <a href="/scrobbler">Historical Charts</a> to take advantage of Last.fm automatically correcting misspelled info.</p>
]]></content:encoded>
			<wfw:commentRss>http://troublewithdreams.com/2009/03/24/charts-update/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Extremely Slow Track Chart Updating</title>
		<link>http://troublewithdreams.com/2009/01/05/extremely-slow-track-chart-updating/</link>
		<comments>http://troublewithdreams.com/2009/01/05/extremely-slow-track-chart-updating/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 14:04:00 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[scrobbler]]></category>

		<guid isPermaLink="false">http://troublewithdreams.com/?p=223</guid>
		<description><![CDATA[Should be alleviated &#8211; an unindexed query called for each track in a chart list was returning close to a million rows = ouch and hurrah for indexes.
]]></description>
			<content:encoded><![CDATA[<p>Should be alleviated &#8211; an unindexed query called for each track in a chart list was returning close to a million rows = ouch and hurrah for indexes.</p>
]]></content:encoded>
			<wfw:commentRss>http://troublewithdreams.com/2009/01/05/extremely-slow-track-chart-updating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Last.fm Historical Charts v2</title>
		<link>http://troublewithdreams.com/2008/08/21/lastfm-historical-charts-v2/</link>
		<comments>http://troublewithdreams.com/2008/08/21/lastfm-historical-charts-v2/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 23:21:34 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[last.fm]]></category>
		<category><![CDATA[scrobbler]]></category>

		<guid isPermaLink="false">http://troublewithdreams.com/?p=200</guid>
		<description><![CDATA[I updated my historical charts program to allow album and track charts, make it utf8 compatible and give it a graphical overhaul too, hurrahs all round.
Same process as before &#8211; when you first create each kind of chart it&#8217;ll take a while to fetch your data, subsequent charts will be created a whole lot faster. [...]]]></description>
			<content:encoded><![CDATA[<p>I updated my historical charts program to allow album and track charts, make it utf8 compatible and give it a graphical overhaul too, hurrahs all round.</p>
<p>Same process as before &#8211; when you first create each kind of chart it&#8217;ll take a while to fetch your data, subsequent charts will be created a whole lot faster.  Eventually I&#8217;ll make a script to purge the data stored for anybody who hasn&#8217;t used the program in a couple of months so keep popping back if you get fed up with the waits.</p>
<p>As always comments are welcome.  Oh and suggestions for a better name too..</p>
]]></content:encoded>
			<wfw:commentRss>http://troublewithdreams.com/2008/08/21/lastfm-historical-charts-v2/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>LastFM Charts</title>
		<link>http://troublewithdreams.com/2008/03/18/lastfm-charts/</link>
		<comments>http://troublewithdreams.com/2008/03/18/lastfm-charts/#comments</comments>
		<pubDate>Tue, 18 Mar 2008 03:05:34 +0000</pubDate>
		<dc:creator>sam</dc:creator>
				<category><![CDATA[last.fm]]></category>
		<category><![CDATA[scrobbler]]></category>

		<guid isPermaLink="false">http://troublewithdreams.com/2008/03/18/lastfm-charts/</guid>
		<description><![CDATA[I made my program to generate charts for any date range from LastFM data available to anybody a few weeks ago and it&#8217;s had a positive response, being included on build.last.fm as an interesting extra kindofthing.  Though still nobody has feedback or suggestions.  Maybe in itself it&#8217;s relatively complete and I should think [...]]]></description>
			<content:encoded><![CDATA[<p>I made my <a href="/scrobbler/">program to generate charts for any date range</a> from LastFM data <a href="http://www.last.fm/user/aradnuk/journal/2008/02/23/656429/">available to anybody</a> a few weeks ago and it&#8217;s had a positive response, being included on <a href="http://build.last.fm">build.last.fm</a> as an interesting extra kindofthing.  Though still nobody has feedback or suggestions.  Maybe in itself it&#8217;s relatively complete and I should think of other, related bits and pieces.  Anybody?</p>
<p>I&#8217;ve made it automatically updating, so you only need to add your data once the very first time you visit, and after that it&#8217;ll check whether there should be new charts available.  Maybe it should only happen a few days into the week &#8211; LastFM never get the charts out on time after all..</p>
<p>That and I added a few extra quick links, to 3/6/12/24 months previous.  No more &#8216;wait a month for charts to refresh&#8217; ;-).  I should totally see if I can make this into a greasemonkey script..</p>
<p>PHP&#8217;s <code>strtotime</code> function is no end of brilliance &#8211; <code>strtotime("-6 months")</code> and <code>strtotime("last sunday")</code> are genius conceptions.</p>
]]></content:encoded>
			<wfw:commentRss>http://troublewithdreams.com/2008/03/18/lastfm-charts/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>
