iTunes Listening Stats

I always have a hard time choosing favorite songs or bands so I usually default to my current addiction. Right now that happens to be Chimp Spanner. Recently I decided to try to analyze my listening habits a little bit more and figure out what bands have really stuck with me.  iTunes keeps track of a decent amount of listening information and makes this very accessible so I thought it would be interesting to use this to calculate some stats. To do this, I wrote a Python script that parses the iTunes music library file and gets statistics on what artists and albums I listen to the most.

Parsing the iTunes music library file in Python turned out to be pretty easy. It is stored as a property list which can be completely parsed using the standard python library plistlib. Plistlib stores the whole file as a dictionary so access is fast and easy. I simply had to iterate through the dictionary and pull the information I needed.

As it turns out I have spent about 84 days listening to my music over the last 3 years or so. I have 28,000 plays and my most listened to bands along with their total listening time and percentage of all iTunes music listening are:

Top played artists by time
| Symphony X                   | 11:7:55:57.489  | 13.35% |
| Nightwish                    | 10:13:17:58.603 | 12.43% |
| Queens of the Stone Age      | 5:18:2:32.704   | 6.78%  |
| Cloud Cult                   | 5:8:53:43.777   | 6.33%  |
| Kamelot                      | 3:22:2:50.529   | 4.62%  |
| Dethklok                     | 2:14:23:1.718   | 3.06%  |
| Arjen A. Lucassen's Star One | 2:14:15:51.818  | 3.06%  |
| Muse                         | 2:12:40:48.849  | 2.98%  |
| Blind Guardian               | 2:12:29:12.134  | 2.97%  |
| Leaves' Eyes                 | 2:8:5:58.55     | 2.75%  |

I pretty much just listen to a lot of power metal. Probably the most interesting result from this is how much I am willing to listen to the same stuff on repeat. This script is currently living at Github if you want to try it out. It should run without modification on any Mac and will run on PC if you change the path to the iTunes Music Library XML file.

Let me know what your results are!

Run-Time Analysis Using MatPlotLib

In my algorithms classes I was always disappointed that there was no coding involved. We wrote out lots of pseudo code, but never anything more tangible. I decided to code up some of the algorithms for fun and to solidify the differences between run-times for the algorithms we were working on. This direct comparison helped a lot with my understanding of the algorithms, but the problem I kept having was it was kind of difficult to visualize the results. I wanted something that would let me run my algorithms in whatever language I wanted and just spit out a nice graph of the results. I decided to make a tool to do this and the result is pyGraph.

How it works

PyGraph is a simple script made to easily graph the output of any program in real time. It takes another program as an argument and reads through the output to determine what information to graph. PyGraph uses MatPlotLib from the SciPy toolkit to construct the graphs. The way values are graphed is by prefixing each printed value with “#>” followed by the label on the graph, and then the x and y coordinates. For example:

#>Algorithm1,10,10
#>Algorithm2,12,15
#>Algorithm1,11,11
#>Algorithm2,14,17

This example would create two bars, one called Algorithm1, one called Algorithm2 as well as two points for each algorithm. Any number of labels can be created so I’m not limited to comparing just two algorithms. The title of the graph as well as the x and y axis can be specified in a similar way.

#>Title,Closest Point
#>xAxis,Number of Points
#>yAxis,Time in Seconds

An important note is that this method requires that stdout needs to be flushed every so often otherwise the graph will not update. The examples in the Github repository show how to do this in Python and C++.

Example

One of the problems we covered in my algorithms class is the closest pair of points problem. The goal is given a set of points, find the two points that are closest together. Wikipedia has a great description of this problem as well as an overview of both algorithms I have implemented. The Brute force algorithm has a run-time of O(n^2) while the divide and conquer approach as a run-time of O(n logn).

Closest Pair of Points Graph

There are plenty of other uses for this little script other than run-time analysis and the uses should expand as I add new features. Let me know if you are interested in adding anything! Check out pyGraph on Github.