Created
October 24, 2012 15:50
-
-
Save zoomix/3946882 to your computer and use it in GitHub Desktop.
Realtime kissmetrics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'json' | |
set :logging, false | |
get '/log' do | |
$site_stats ||= Hash.new(0) | |
$report_stats ||= Hash.new(0) | |
$report_table_stats ||= Hash.new(0) | |
# params.each do |key,value| | |
# puts " #{key}: #{value}" | |
# end | |
case params[:event] | |
when 'View Report' | |
$site_stats[params[:site]] += 1 | |
$report_stats[params[:report]] += 1 | |
table_dimension = case params[:report] | |
when 'user-experience' then 'Category' | |
when 'visits' then 'Traffic Source' | |
else 'Placement' | |
end | |
$report_table_stats["#{params[:report]}/#{table_dimension}"] += 1 | |
when 'View Report Table Column' | |
$site_stats[params[:site]] += 1 | |
when 'View Report Table' | |
$report_stats[params[:report]] += 1 | |
$report_table_stats["#{params[:report]}/#{params[:table]}"] += 1 | |
end | |
# puts "All the stats: **************** #{[$site_stats, $report_stats, $report_table_stats]}" | |
204 | |
end | |
get '/app' do | |
erb :index | |
end | |
get '/angie' do | |
erb :angie | |
end | |
get '/json/site' do | |
$site_stats.map { |k,v| { :site => k, :count => v } }.to_json | |
end | |
get '/json/report' do | |
$report_stats.map { |k,v| { :report => k, :count => v } }.to_json | |
end | |
get '/json/report_table' do | |
$report_table_stats.map { |k,v| { :report_table => k, :count => v } }.to_json | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment