Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 23a49e3325caf624651c7872f59ad6f94165f93a @rosario committed Apr 21, 2009
Showing with 30,543 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. +12 −0 README
  3. +12 −0 Rakefile
  4. 0 TODO
  5. +34 −0 app/controllers/application.rb
  6. +69 −0 app/controllers/dashboard_controller.rb
  7. +82 −0 app/controllers/graphs_controller.rb
  8. +172 −0 app/controllers/javascripts_controller.rb
  9. +47 −0 app/controllers/login_controller.rb
  10. +24 −0 app/controllers/projects_controller.rb
  11. +97 −0 app/controllers/referers_controller.rb
  12. +27 −0 app/controllers/users_controller.rb
  13. +6 −0 app/helpers/application_helper.rb
  14. +2 −0 app/helpers/graphs_helper.rb
  15. +2 −0 app/helpers/javascripts_helper.rb
  16. +2 −0 app/helpers/login_helper.rb
  17. +2 −0 app/helpers/projects_helper.rb
  18. +2 −0 app/helpers/users_helper.rb
  19. +72 −0 app/models/action.rb
  20. +4 −0 app/models/click.rb
  21. +75 −0 app/models/project.rb
  22. +160 −0 app/models/tracker.rb
  23. +51 −0 app/models/user.rb
  24. +6 −0 app/models/visit.rb
  25. +1,564 −0 app/models/visitor.rb
  26. +11 −0 app/views/dashboard/index.html.erb
  27. +12 −0 app/views/dashboard/setup.html.erb
  28. +57 −0 app/views/graphs/_bar_graph.html.erb
  29. +54 −0 app/views/graphs/_line_plot.html.erb
  30. +77 −0 app/views/graphs/graph1.html.erb
  31. +109 −0 app/views/javascripts/clickmap.js.erb
  32. 0 app/views/javascripts/log.js.erb
  33. +96 −0 app/views/javascripts/overlay.js.erb
  34. +276 −0 app/views/javascripts/piwik.js.erb
  35. +28 −0 app/views/layouts/dashboard.html.erb
  36. +41 −0 app/views/layouts/graphs.html.erb
  37. +20 −0 app/views/layouts/login.html.erb
  38. +50 −0 app/views/layouts/projects.html.erb
  39. +29 −0 app/views/layouts/referers.html.erb
  40. +27 −0 app/views/layouts/users.html.erb
  41. +2 −0 app/views/login/delete_user.html.erb
  42. +33 −0 app/views/login/login.html.erb
  43. +2 −0 app/views/login/logout.html.erb
  44. +20 −0 app/views/projects/overview.html.erb
  45. +29 −0 app/views/referers/_table_panel.html.erb
  46. +39 −0 app/views/referers/queries.html.erb
  47. +27 −0 app/views/users/add_user.html.erb
  48. +22 −0 app/views/users/list_users.html.erb
  49. +109 −0 config/boot.rb
  50. +19 −0 config/database.yml
  51. +69 −0 config/environment.rb
  52. +17 −0 config/environments/development.rb
  53. +22 −0 config/environments/production.rb
  54. +22 −0 config/environments/test.rb
  55. +10 −0 config/initializers/inflections.rb
  56. +5 −0 config/initializers/mime_types.rb
  57. +15 −0 config/initializers/new_rails_defaults.rb
  58. +62 −0 config/routes.rb
  59. +100 −0 db/schema.rb
  60. +39 −0 doc/README_FOR_APP
  61. +243 −0 doc/app/classes/Action.html
  62. +119 −0 doc/app/classes/ApplicationController.html
  63. +147 −0 doc/app/classes/ApplicationHelper.html
  64. +166 −0 doc/app/classes/DashboardController.html
  65. +214 −0 doc/app/classes/GraphsController.html
  66. +105 −0 doc/app/classes/GraphsHelper.html
  67. +223 −0 doc/app/classes/JavascriptsController.html
  68. +105 −0 doc/app/classes/JavascriptsHelper.html
  69. +239 −0 doc/app/classes/LoginController.html
  70. +105 −0 doc/app/classes/LoginHelper.html
  71. +122 −0 doc/app/classes/Parser.html
  72. +206 −0 doc/app/classes/Parser/Keyword.html
  73. +269 −0 doc/app/classes/Parser/Language.html
  74. +173 −0 doc/app/classes/Parser/Robot.html
  75. +268 −0 doc/app/classes/Parser/UserAgent.html
  76. +118 −0 doc/app/classes/Project.html
  77. +247 −0 doc/app/classes/ProjectsController.html
  78. +105 −0 doc/app/classes/ProjectsHelper.html
  79. +221 −0 doc/app/classes/Tracker.html
  80. +243 −0 doc/app/classes/User.html
  81. +205 −0 doc/app/classes/UsersController.html
  82. +105 −0 doc/app/classes/UsersHelper.html
  83. +1,759 −0 doc/app/classes/Visitor.html
  84. +1 −0 doc/app/created.rid
  85. +109 −0 doc/app/files/app/controllers/application_rb.html
  86. +107 −0 doc/app/files/app/controllers/dashboard_controller_rb.html
  87. +101 −0 doc/app/files/app/controllers/graphs_controller_rb.html
  88. +107 −0 doc/app/files/app/controllers/javascripts_controller_rb.html
  89. +101 −0 doc/app/files/app/controllers/login_controller_rb.html
  90. +101 −0 doc/app/files/app/controllers/projects_controller_rb.html
  91. +101 −0 doc/app/files/app/controllers/users_controller_rb.html
  92. +108 −0 doc/app/files/app/helpers/application_helper_rb.html
  93. +101 −0 doc/app/files/app/helpers/graphs_helper_rb.html
  94. +101 −0 doc/app/files/app/helpers/javascripts_helper_rb.html
  95. +101 −0 doc/app/files/app/helpers/login_helper_rb.html
  96. +101 −0 doc/app/files/app/helpers/projects_helper_rb.html
  97. +101 −0 doc/app/files/app/helpers/users_helper_rb.html
  98. +115 −0 doc/app/files/app/models/action_rb.html
  99. +108 −0 doc/app/files/app/models/project_rb.html
  100. +108 −0 doc/app/files/app/models/tracker_rb.html
  101. +108 −0 doc/app/files/app/models/user_rb.html
  102. +114 −0 doc/app/files/app/models/visitor_rb.html
  103. +167 −0 doc/app/files/doc/README_FOR_APP.html
  104. +141 −0 doc/app/files/lib/parser_rb.html
  105. +49 −0 doc/app/fr_class_index.html
  106. +46 −0 doc/app/fr_file_index.html
  107. +64 −0 doc/app/fr_method_index.html
  108. +24 −0 doc/app/index.html
  109. +208 −0 doc/app/rdoc-style.css
  110. BIN lib/bolilla.png
  111. BIN lib/bolilla2.png
  112. BIN lib/bolilla3.png
  113. BIN lib/bolilla4.png
  114. BIN lib/bolillamia.png
  115. BIN lib/bolillamia16.png
  116. BIN lib/bolillamia32.png
  117. BIN lib/bolillamia8.png
  118. BIN lib/colors.png
  119. BIN lib/colors2.png
  120. BIN lib/colors3.png
  121. BIN lib/gradient_levels.png
  122. +143 −0 lib/heatmap.rb
  123. +4 −0 lib/log.txt
  124. +483 −0 lib/parser.rb
  125. 0 log/.gitignore
  126. +30 −0 public/404.html
  127. +30 −0 public/422.html
  128. +30 −0 public/500.html
  129. +10 −0 public/dispatch.cgi
  130. +24 −0 public/dispatch.fcgi
  131. +10 −0 public/dispatch.rb
  132. 0 public/favicon.ico
  133. BIN public/images/bg-tab.png
  134. BIN public/images/gradient_ice-sea.jpg
  135. BIN public/images/rails.png
  136. BIN public/images/right-bg.gif
  137. BIN public/images/testo.png
  138. +274 −0 public/index.ruby
  139. +2 −0 public/javascripts/application.js
  140. +963 −0 public/javascripts/controls.js
  141. +972 −0 public/javascripts/dragdrop.js
  142. +1,120 −0 public/javascripts/effects.js
  143. +701 −0 public/javascripts/flot/API.txt
  144. +165 −0 public/javascripts/flot/NEWS.txt
  145. +80 −0 public/javascripts/flot/README.txt
  146. +36 −0 public/javascripts/flot/TODO
  147. +38 −0 public/javascripts/flot/examples/basic.html
  148. +38 −0 public/javascripts/flot/examples/dual-axis.html
  149. +67 −0 public/javascripts/flot/examples/graph-types.html
  150. +26 −0 public/javascripts/flot/examples/index.html
  151. +92 −0 public/javascripts/flot/examples/interacting.html
  152. +5 −0 public/javascripts/flot/examples/layout.css
  153. +107 −0 public/javascripts/flot/examples/selection.html
  154. +63 −0 public/javascripts/flot/examples/setting-options.html
  155. +67 −0 public/javascripts/flot/examples/time.html
  156. +96 −0 public/javascripts/flot/examples/turning-series.html
  157. +87 −0 public/javascripts/flot/examples/visitors.html
  158. +91 −0 public/javascripts/flot/examples/zooming.html
  159. +785 −0 public/javascripts/flot/excanvas.js
  160. +1 −0 public/javascripts/flot/excanvas.pack.js
  161. +2,136 −0 public/javascripts/flot/jquery.flot.js
  162. +1 −0 public/javascripts/flot/jquery.flot.pack.js
  163. +3,408 −0 public/javascripts/flot/jquery.js
  164. +4,225 −0 public/javascripts/prototype.js
  165. +233 −0 public/javascripts/resizable.js
  166. +275 −0 public/javascripts/slider.js
  167. +1 −0 public/pictures/.html
  168. +2 −0 public/pictures/.txt
  169. +5 −0 public/robots.txt
  170. +111 −0 public/stylesheets/login.css
  171. +42 −0 public/stylesheets/overlay.css
  172. BIN public/stylesheets/progress_bar.gif
  173. +575 −0 public/stylesheets/screen.css
  174. +272 −0 public/stylesheets/screen2.css
  175. +3 −0 script/about
  176. +3 −0 script/console
  177. +3 −0 script/dbconsole
  178. +3 −0 script/destroy
  179. +3 −0 script/generate
  180. +3 −0 script/performance/benchmarker
  181. +3 −0 script/performance/profiler
  182. +3 −0 script/performance/request
  183. +3 −0 script/plugin
  184. +3 −0 script/process/inspector
  185. +3 −0 script/process/reaper
  186. +3 −0 script/process/spawner
  187. +3 −0 script/runner
  188. +3 −0 script/server
  189. +11 −0 test/fixtures/actions.yml
  190. +13 −0 test/fixtures/clicks.yml
  191. +11 −0 test/fixtures/projects.yml
  192. +11 −0 test/fixtures/users.yml
  193. +7 −0 test/fixtures/visitors.yml
  194. +9 −0 test/fixtures/visits.yml
  195. +8 −0 test/functional/expenses_controller_test.rb
  196. +8 −0 test/functional/graphs_controller_test.rb
  197. +8 −0 test/functional/javascripts_controller_test.rb
  198. +8 −0 test/functional/login_controller_test.rb
  199. +8 −0 test/functional/projects_controller_test.rb
  200. +8 −0 test/functional/users_controller_test.rb
  201. +38 −0 test/test_helper.rb
  202. +8 −0 test/unit/action_test.rb
  203. +8 −0 test/unit/click_test.rb
  204. +8 −0 test/unit/project_test.rb
  205. +8 −0 test/unit/user_test.rb
  206. +8 −0 test/unit/visit_test.rb
  207. +8 −0 test/unit/visitor_test.rb
  208. 0 tmp/.gitignore
  209. 0 vendor/.gitignore
@@ -0,0 +1,5 @@
+.DS_Store
+log/*.log
+tmp/**/*
+db/*.sqlite3
+public/datafiles/*
12 README
@@ -0,0 +1,12 @@
+Cannoli is a Click heatmaps generator written in Ruby on Rails 2.2. It's based on the Ruwa analytics
+
+The main features are:
+1) Database used to save clicks
+2) Heatmap can be generated per page
+3) Statistics provided by Ruwa (visitor settings, referers and so on)
+4) Fast Heamap generation in C++
+
+
+To install consult the wiki.
+
+
@@ -0,0 +1,12 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require(File.join(File.dirname(__FILE__), 'config', 'boot'))
+
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+require 'tasks/rails'
+#require 'rubygems'
+#require 'charlie'
0 TODO
No changes.
@@ -0,0 +1,34 @@
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+class ApplicationController < ActionController::Base
+ helper :all # include all helpers, all the time
+
+ # See ActionController::RequestForgeryProtection for details
+ # Uncomment the :secret if you're not using the cookie session store
+ protect_from_forgery :secret => '91316559316113309ae70eb9572fc84f'
+
+ # See ActionController::Base for details
+ # Uncomment this to filter the contents of submitted sensitive data parameters
+ # from your application log (in this case, all fields with names like "password").
+ # filter_parameter_logging :password
+ private
+
+ #Check if a user has logged in
+ def authorize
+ unless User.find_by_id(session[:user_id])
+ flash[:notice] = "Please log in"
+ redirect_to(:controller => "login", :action => "login")
+ end
+ end
+
+
+ # The first user created is the admin
+ def administrator
+ unless session[:user_id] == 1
+ flash[:notice] = "Restricted to admin only"
+ redirect_to(:controller=>"login", :action =>"login")
+ end
+
+ end
+end
@@ -0,0 +1,69 @@
+# Interface controller
+class DashboardController < ApplicationController
+ before_filter :authorize
+
+
+
+
+ # Redirect to projects/setup if the user hasn't got a project yet
+ # otherwise redirect to projects/overview
+ def index
+ u = User.find(session[:user_id])
+ pid = u.project_id
+ if pid.nil?
+ redirect_to :controller =>'dashboard', :action=> 'setup'
+ else
+ session[:project_id] = pid
+ redirect_to project_overview_url(:id =>pid)
+ end
+
+ end
+
+ def setup
+
+
+ end
+
+ def create
+ u = User.find(session[:user_id])
+ project_name = params[:project_name]
+
+
+ if u.project_id.nil?
+ p = Project.create(:name=>project_name)
+ u.project_id = p.id
+ u.save
+
+ # # Testing, add the actions
+ # urls = ["http://0.0.0.0:3000/website/page1",
+ # "http://0.0.0.0:3000/website/page2",
+ # "http://0.0.0.0:3000/website/page3",
+ # "http://0.0.0.0:3000/website/page4",
+ # "http://0.0.0.0:3000/website/page5"]
+ # as = []
+ # for u in urls
+ # p.add_action(Action.new(:url=>"#{u}", :url_id=> Digest::MD5.hexdigest(u), :kind => rand(2)))
+ # end
+ #
+ #
+ # # Randomly create 500 visitors. Useful for graphs generation
+ # 500.times do
+ # v = Visitor.create_random
+ # v.add_random_actions(p.actions)
+ # p.visitors << v
+ # end
+
+
+
+ else
+ p= Project.find(u.project_id)
+ end
+ session[:project_id]= p.id
+
+
+
+ redirect_to project_overview_url(:id => p.id)
+ end
+
+end
+
@@ -0,0 +1,82 @@
+
+class GraphsController < ApplicationController
+ before_filter :authorize
+
+
+
+
+
+ # Graphs are created in this method
+ def graph1
+
+ p = Project.find(session[:project_id])
+
+ @project = p
+
+ bod = Time.parse("2009-01-01").strftime("%Y-%m-%d %H:%M:%S")
+ #eod = Time.parse("2009-01-29").end_of_day.strftime("%Y-%m-%d %H:%M:%S")
+ eod = Time.now.end_of_day.strftime("%Y-%m-%d %H:%M:%S")
+
+ conditions = ["created_at > ? AND created_at < ?", "#{bod}", "#{eod}"]
+
+ vs = p.visitors.find(:all,:conditions=>conditions)
+
+ # This data is used to show how to use the line_plot partial
+ @example = [[0,0],[1,1],[2,2]]
+
+
+ # @total_clicks = p.visitors.count(:id,
+ # :group => 'strftime("%Y/%m/%d",created_at)',
+ # :conditions => conditions)
+
+ @total_clicks = vs.group_by { |v|
+ v.created_at.strftime("%Y/%m/%d")
+ }.map{|k,v| [k,v.size]}.sort_by {|date,x| date}
+
+ # @browsers = p.visitors.count(:id,
+ # :group =>:config_browser_name,
+ # :conditions => conditions).sort_by{|x,y| y}.reverse
+ #
+
+ @browsers =vs.group_by{|v| v.config_browser_name}.map{|k,v| [k,v.size]}.sort_by{|x,y| y}.reverse.first(9)
+
+
+ # @config_os = p.visitors.count(:id,
+ # :group =>:config_os,
+ # :conditions => conditions).sort_by{|x,y| y}.reverse
+ #
+
+ @config_os = vs.group_by{|v| v.config_os}.map{|k,v| [k,v.size]}.sort_by{|x,y| y}.reverse.first(9)
+
+
+ # @hours_by_servertime = p.visitors.count(:id,
+ # :group => 'strftime("%H",created_at)',
+ # :conditions => conditions)
+
+ @hours_by_servertime =vs.group_by{|v| v.created_at.strftime("%H")}.map{|k,v| [k,v.size]}.sort_by {|date,x| date}
+
+
+
+ # @search_engines = p.visitors.count(:id,
+ # :group => 'referer_name',
+ # :conditions => ["referer_type = ? AND created_at > ? AND created_at < ?", "1", "#{bod}", "#{eod}"] ).sort_by{|x,y| y}.reverse
+
+ @search_engines = vs.select{|v| v.referer_type == 1}.group_by{|v| v.referer_name}.map{|k,v| [k,v.size]}.sort_by{|x,y| y}.reverse
+
+
+
+ @time_spent = vs.group_by {|v|v.time_spent_in_words }.map{|k,v| [k,v.size]}.sort_by{|t,s| s}.reverse
+
+ as = p.actions
+
+ @actions = as.map{|a| [a.path,a.visitors.count(:group => :visitor_id).size]}.sort_by{|u,s| s}.reverse
+
+
+ end
+
+
+
+
+
+
+end
@@ -0,0 +1,172 @@
+# Javascript code controller
+
+class JavascriptsController < ApplicationController
+
+
+ # The main javascript tracker function, at the moment it's basically
+ # taken from piwik.org. It registers the visitor informations and pass it
+ # to log
+ def piwik
+
+ # see the views/javascripts/piwik.js.erb
+
+ end
+
+
+
+ def clickmap
+ if session[:user_id]
+ a = Action.find(session[:action_id])
+
+ name = a.url_id
+ @heatmap = "#{SERVER_NAME}/images/#{name}.png"
+ puts "HEATMAP >>>>>>>>>>>>>>>>>>"
+ puts @heatmap
+ puts "ACTION ID <<<<<<<<<<<<<<"
+ puts a.id.to_s
+
+ @overlay_style = "<style type='text/css'>@import url('#{SERVER_NAME}/stylesheets/overlay.css');</style>"
+ render :action => "overlay.js"
+ else
+ @click_url = "#{SERVER_NAME}/javascripts/click.js"
+ render :action => "clickmap.js"
+ end
+
+
+ end
+
+ # It keeps track of the visitor.
+ # It is called from a visitor browser using the tracking javascript code
+
+
+ def log
+
+
+
+ if session[:user_id]
+ # User (not the visitor) is logged in..we dont count his actions
+ puts ">>>>>>>>>>>>>>>> USER LOGGED IN, ACTIONS not counted"
+
+
+ # Questo mi serve per far funzionare la session[:action_id] dentro clickmap!
+ # Clean the URL from the last '/'
+ url = params[:url]
+ if url.last == "/"
+ url.chop!
+ end
+
+ project_id = params[:idsite]
+ p = Project.find(project_id)
+ action = p.actions.find_by_url(url)
+ session[:action_id] = action.id
+
+ render :text => ""
+ else
+
+ project_id = params[:idsite]
+
+ if (session[:project_id]) and (project_id != session[:project_id])
+ # This visitor has already a session open, but using another project
+ session[:visitor_id] = nil
+ end
+
+ session[:project_id] = project_id
+
+
+ p = Project.find(project_id)
+
+ # Check if the params[:idsite] correspond to the right hostname
+ # because we dont want to record stats from other hosts
+
+ hostname = URI.parse(params[:url]).host
+ if hostname.match(p.name)
+ puts " >>>>>>>>>>>>>>>>>> HOSTNAME MATCHES with the correct project_id"
+ visitor_settings = Tracker.get_settings(params,request)
+ if session[:visitor_id]
+ # Se c''e il visitor_id allora e' conosciuto
+ # Vedo se l'ultima azione e' stata fatta in meno di mezzo'ora
+ puts " >>>>>>>>>>>>>>>>> SESSION FOUND"
+ v = Visitor.find(session[:visitor_id])
+ if (Time.now - v.last_action_time) > 30.minutes
+ # Sono passati piu' di 30 minuti, creo un nuovo visitor e lo metto come returning
+ puts ">>>>>>>>>>>>>>>>>>>MORE THAN 30 minutes, create a new visitor"
+ v = Visitor.create_with_settings(visitor_settings)
+ p.visitors << v
+ p.visitor_was_here!(v)
+ end
+
+ else
+
+ puts ">>>>>>>>>>>>>>>>> NO SESSION"
+ # There's no session, check if there was a visitor having the same browser configuration and IP today
+ puts ">>>>>>>>>>> USER SETTINGS" + visitor_settings[:config_md5config]
+ v = p.visitor_here_today?(visitor_settings)
+
+ if v.nil?
+ puts ">>>>>>>>>>>> VISITOR NEW"
+ # The visitor is new, create a new visitor and add him
+ v = Visitor.create_with_settings(visitor_settings)
+ p.visitors << v
+ else
+ p ">>>>>>>>>>>> VISITOR HERE"
+
+ if (Time.now - v.last_action_time) > 30.minutes
+ puts ">>>>>>>>>>>>>> MORE THAN 30 minutes, create new visitor"
+ # Sono passati piu' di 30 minuti, creo un nuovo visitor e lo metto come returning
+ v = Visitor.create_with_settings(visitor_settings)
+ p.visitors << v
+ p.visitor_was_here!(v)
+ end
+
+ end
+
+ end
+
+ session[:visitor_id] = v.id
+
+
+ # Save the action only IF it's not already present.
+ # Kind is used to distinguish between normal actions and goals
+ # Other kinds should be used too, (such as downloads)
+
+ # Clean the URL from the last '/'
+ url = params[:url]
+ if url.last == "/"
+ url.chop!
+ end
+
+ action = Action.new(:url=>"#{url}", :url_id=> Digest::MD5.hexdigest(params[:url]),
+ :kind => params[:action_kind].to_i)
+ # Add the action to the project, only if it's new
+ # Return the old action if present
+ a = p.add_action(action)
+
+ v.add_action(a)
+ #session[:action_id] = action.id
+ session[:action_id] = a.id
+ puts "Setting ACTION ID = " + session[:action_id].to_s
+
+ end
+
+
+ end
+
+ end
+
+
+ def click
+
+ # Note
+ # a.visitors_clicking.find(:all, :group => :visitor_id), returns all visitors that have clicked
+ # a.clicks.find(:all, :visitor_id), returns the clicks, with the different visitor_id counted only once.
+
+
+ a = session[:action_id]
+ v = session[:visitor_id]
+ c = Click.create(:action_id => a, :visitor_id => v, :x => params[:x], :y => params[:y])
+
+ render :text => ""
+ end
+
+
+end
Oops, something went wrong.

0 comments on commit 23a49e3

Please sign in to comment.