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 = Logger.new("sdb.log")
@sdb = RightAws::SdbInterface.new(AWS ACCESS KEY, AWS SECRET KEY, {:multi_thread => true, :logger => $logger})
len = CountryCode.length-1
h = Hash.new
while true
begin
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
end
end
#create_html is function to generate html bases on data in hash h
create_html(h)
sleep 300
rescue Exception=>e
puts e.inspect
end
end
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.
Thanks for sharing such a great information.It really helpful to me.I always search to read the quality content and finally i found this in you post. keep it up! Custom Web Development