This is the last part in the series ‘Analytics in the Cloud’.

Till part 4, we have seen how we are putting analytics in the cloud. In this part we will see a demo application to use them.

We used Raphaël, a JavaScript library, for plotting graphs that represent analytics. Below is the code, which read data from ‘Analytics’ domain (table) and plots a pie chart. (I omitted create_html function definition, which was basically creating html pages using Raphaël.)

#!/usr/bin/env ruby
require 'rubygems'
require 'right_aws'
require 'logger'

CountryCode = [ ] #Array for country codes
CountryName = [ ] #Array for country names

$logger ="sdb.log")
@sdb = ACCESS KEY, AWS SECRET KEY, {:multi_thread => true, :logger => $logger})

len = CountryCode.length-1
h =

while true
for i in 0..len
#getting data from Analytics domain
res = @sdb.get_attributes('Analytics',CountryCode[i])[:attributes]
if res.length == 3
#printing on screen just for debugging purpose
puts res["country"][0] + " " + CountryName[i] + " " + res["count"][0]
h[res["country"][0]] = res["count"][0].to_i
#create_html is function to generate html bases on data in hash h
sleep 300
rescue Exception=>e
puts e.inspect

Below is the pie chart, which above script produces. We presented value for USA separately as text, coz it was contributing more than 60% in the pie chart and other countries were coming just as a line.

We added following line in the generated html so that html pages refreshes itself every 5 minutes interval.
<meta http-equiv="refresh" content="300">
Below is screenshot for USA last 24 hour data, which we logged in domains ‘Analytics(n)’.

You can use any other tool for visualizing data as per your requirement, we used Raphaël just for it’s visual appeal.

Subscribe - To get an automatic feed of all future posts subscribe here, or to receive them via email go here and enter your email address in the box. You can also like us on facebook and follow me on Twitter @akashag1001.