Last.fm tool: Level 2 of the musical eclectic test!
The following script takes the 50 top artists in your musical
profile from Last.fm, and finds the collection
of top 20 similar artists (where the artist itself is the #1 most
similar artist) for this top 50. The resulting is a list of artists similar
to your preferred artists. As the list is larger (maximum = 1000),
your musical preference is more diverse.
As a result, with this test it is harder to get a high score, as compared
to the original eclectic test. And because this
score goes up to 1000 (and not to confuse it with the orginal "eclectic
score"), this test is the "super-eclectic" test!
Please be patient, the script may require up to a minute to
process your request because of Last.fm policies. I\'m using extensive
caching of requests to Last.fm\'s web services to minimize computation
time.
';
if( !$type )
$type = "overall";
if( $user ) {
// get user's top artists
$userfilename = "./users/" . $user . ".xml";
$userurl = "http://ws.audioscrobbler.com/1.0/user/$user/topartists.xml";
$xmlroot = "topartists";
if( $type == "weekly" ) {
$userfilename = "./weeklyusers/" . $user . ".xml";
$userurl = "http://ws.audioscrobbler.com/1.0/user/$user/weeklyartistchart.xml";
$xmlroot = "weeklyartistchart";
}
$userdata = getDataFrom( $userfilename, $userurl, 10*60 );
$data = XML_unserialize( $userdata );
// for each of the artistss, analyze his similar artists
$similarartists;
$nrartists = 0;
if( $data[ $xmlroot ] )
if( $data[ $xmlroot ]['artist'] )
if( count( $data[ $xmlroot ]['artist'] ) > 0 )
foreach( $data[ $xmlroot ]['artist'] as $artist ) {
if( $nrartists < 50 ) {
$nrartists++;
$name = substr(strrchr($artist['url'], "/"), 1);
$similarartists[ $artist['name'] ]++;
$playcount = $artist['playcount'];
// print( $name . " -> " . $playcount . "" );
$artistfilename = "./similarartists/" . $name . ".xml";
$artisturl = "http://ws.audioscrobbler.com/1.0/artist/$name/similar.xml";
$artistdata = getDataFrom( $artistfilename, $artisturl );
$data = XML_unserialize( $artistdata );
$similarcount = 0;
if( $data['similarartists'] )
if( $data['similarartists']['artist'] )
if( count( $data['similarartists']['artist'] ) > 1 )
foreach( $data['similarartists']['artist'] as $similarartist ) {
if( $similarcount < 19 ) {
$similarcount++;
$tagname = $similarartist['name'];
$similarartists[ $tagname ] ++;
}
}
if( $similarcount <= 0 )
$nrartists--;
}
}
arsort( $similarartists );
$eclecticscore = count( $similarartists );
$handle = fopen("supereclecticscores.txt", "a");
fwrite($handle, $user."\t".$eclecticscore."\n");
fclose($handle);
echo "
How super-eclectic is the musical preference of $user?
";
echo "
$user's super-eclectic score is
" . count( $similarartists ) . "/1000";
echo "
As this number is larger, you have a more eclectic musical preference. People with scores over 700 have bragging rights. People whose score is below 400 should consider more musical styles!
";
echo "
The following are the artists with the most occurences in your list
";
$count = 0;
foreach( $similarartists as $similarartist => $value ) {
if( $count < 20 ) {
$count++;
$artist_unicode = unicode_to_entities( utf8_to_unicode( $similarartist ) );
if( $value > 1 )
echo "- " . $artist_unicode . " ($value)
";
}
}
echo "
";
echo "
The following is a histogram of computed super-eclectic scores (updated on the hour), so you can compare your score with that of other users. The green line denotes the most representative normal distribution for the histogram (the bash/gnuplot code I wrote to generate this graph is awesome).
";
echo "
BBCode!
";
echo "
The following BBCode can easily be copied to Last.fm forums, journals, ...
";
echo '
'."\n";
echo " Take your top 50 artists. For each of these artists, collect the top 20 similar artists (where the artist itself is the #1 most similar). The resulting number of unique artists is your [b]super-eclectic score[/b]. You can compute your own score at http://anthony.liekens.net/pub/scripts/last.fm/supereclectic.php \n\nMy super-eclectic score is currently\n\n[align=center][size=18][b]$eclecticscore/1000[/b][/size][/align] \n\n";
echo "The most similar artists for my profile are ";
$count = 0;
foreach( $similarartists as $similarartist => $value ) {
if( $count < 10 ) {
$count++;
$artist_unicode = unicode_to_entities( utf8_to_unicode( $similarartist ) );
if( $value > 1 )
echo $artist_unicode . " ($value)";
else
echo $artist_unicode;
if( $count < 10 )
echo ", ";
}
}
echo " ";
echo ' |
'."\n";
echo "
Or, if you computed someone else's super-eclectic score, copy the following to their shoutbox.
";
echo '
'."\n";
echo " Your [url=http://anthony.liekens.net/pub/scripts/last.fm/supereclectic.php] super-eclectic score [/url] is $eclecticscore/1000! \n\n";
echo "";
echo ' |
'."\n";
printLinks( $user, "eclectic" );
echo '
';
}
echo '