I have spent this week entirely with learning more perl/Moose/Template-Toolkit and trying to display the data stored in JSON format. Unfortunately our Splunk license expired on Monday. Robert sent Splunk a mail about it, and I was hoping we would get a new license in a day or so. However, the guys at Splunk are very busy, so we still don’t have a license.

I eventually gave up waiting and used the free license on my own comp to generate an output in JSON format. This is what the output looks like for the “top artists” query:

[
  {
    "mbid": "60f7d020-9580-47c5-8839-a4f25659687d",
    "count": "9",
    "percent": "0.900000",
    "_tc": "1000"
  },
  {
    ...
  },
  ...
]

Of course this was ran on a very small amount of data. This is why the “top artist” has so low view count.

Then I had to upload this  to my database on rika. After parsing the JSON in the perl module I had to find a way to display the data. I had lots of trouble with this. I’m quite new to Moose, and using the type system was troublesome. I was trying to create an attribute with the type “ArrayRef[HashRef[…]]”, but I just couldn’t get it to work.

In the end I decided to create an attribute without a type, and store an array reference in it, that has hash references as values. After this, I had to write code that makes sure “private” values are not displayed. In the JSON above there is a “_tc” key that is not part of the query. Every key-value pair that has a key beginning with “_” should be omitted from the actual table on the website.

Here is the data module that parses JSON, and removed private values:

https://github.com/balidani/musicbrainz-server/blob/master/lib/MusicBrainz/Server/Data/LogStatistic.pm

Here is the modified entity:

https://github.com/balidani/musicbrainz-server/blob/master/lib/MusicBrainz/Server/Entity/LogStatistic.pm

And here is the template:

https://github.com/balidani/musicbrainz-server/blob/master/root/logstatistics/index.tt

I think most of the perl code I wrote needs lots of improvement, but at least it works! Next week I hope we finally get a Splunk license. I will also work on displaying data much more.

Advertisements