myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [2500] branches/dashboard/app/controllers/dashboa


From: noreply
Subject: [myexperiment-hackers] [2500] branches/dashboard/app/controllers/dashboard_controller.rb: workfows , users, contributions
Date: Thu, 19 Aug 2010 11:35:28 -0400 (EDT)

Revision
2500
Author
kkollara
Date
2010-08-19 11:35:28 -0400 (Thu, 19 Aug 2010)

Log Message

workfows, users, contributions

Modified Paths

Diff

Modified: branches/dashboard/app/controllers/dashboard_controller.rb (2499 => 2500)


--- branches/dashboard/app/controllers/dashboard_controller.rb	2010-08-18 17:00:19 UTC (rev 2499)
+++ branches/dashboard/app/controllers/dashboard_controller.rb	2010-08-19 15:35:28 UTC (rev 2500)
@@ -7,33 +7,141 @@
   before_filter :check_admin, :load_stats_dates
 
   def index
+    
+    users=User.find(:all, :conditions => "users.activated_at IS NOT NULL" )
+    workflows=Workflow.find(:all)
+    
     @total_users = User.find(:all).length
     @unactivated_users = User.find(:all).select do |u|
       u.activated_at.nil?
     end.length
+
+    # Additional Stats
+    @user_login_stats={}
+    
+    @user_login_stats["Activated users who never logged in"] = User.count(:conditions =>
+    "users.activated_at IS NOT NULL AND last_seen_at IS NULL")
+    
+    @user_login_stats["Activated users who last logged in within 1 hour of activating"] = User.count(:conditions =>
+    "users.activated_at IS NOT NULL AND last_seen_at IS NOT NULL " +
+    "AND ( ( created_at + interval 1 hour ) > last_seen_at)")
+
+    @user_login_stats["Activated users who last logged in within 1 day of activating"] = User.count(:conditions =>
+    "users.activated_at IS NOT NULL AND last_seen_at IS NOT NULL " +
+    "AND ( ( created_at + interval 1 day ) > last_seen_at)")
+
+    @user_login_stats["Activated users who last logged in within 1 week of activating"] = User.count(:conditions =>
+    "users.activated_at IS NOT NULL AND last_seen_at IS NOT NULL " +
+    "AND ( ( created_at + interval 1 week ) > last_seen_at)")
+
+     @user_login_stats["Activated users who last logged in within 1 month of activating"] = User.count(:conditions =>
+    "users.activated_at IS NOT NULL AND last_seen_at IS NOT NULL " +
+    "AND ( ( created_at + interval 1 month ) > last_seen_at)")
+
+    @user_login_stats["Activated users who last logged in within the last week"] = User.count(:conditions =>
+    "users.activated_at IS NOT NULL AND last_seen_at IS NOT NULL " +
+    "AND ( ( last_seen_at + interval 1 week) > now() )")
+
+    @user_login_stats["Activated users who last logged in within the last month"] = User.count(:conditions =>
+    "users.activated_at IS NOT NULL AND last_seen_at IS NOT NULL " +
+    "AND ( ( last_seen_at + interval 1 month) > now() )")
+
+    
+    # Workflows
+    @workflow_count=Workflow.count()
+    pub=0
+    pubview=0
+    workflows.each do |w|
+    pub+=1 if Authorization.is_authorized?("download", nil, w, nil)
+    pubview+=1 if Authorization.is_authorized?("view", nil, w, nil)
+    end
+    @workflow_pub = pub
+    @workflow_pubview = pubview
+    @workflow_version_distrib = Workflow.find_by_sql ("SELECT current_version, count(current_version) count FROM workflows GROUP BY current_version")
+    @workflow_chart_url = workflow_chart_url(@workflow_count, @workflow_pub, @workflow_pubview) 
+    @workflow_distrib_version_chart_url = workflow_distrib_version_chart_url (@workflow_version_distrib)
+   
+    # Users
     @unactivated_users_pct = ((Float.induced_from(@unactivated_users)/Float.induced_from(@total_users)) * 100).round
     @activated_users = @total_users - @unactivated_users
     @activated_users_pct = ((Float.induced_from(@activated_users)/Float.induced_from(@total_users)) * 100).round
     @user_chart_url = user_chart_url(@activated_users_pct, @unactivated_users_pct)
-
+    @user_login_stats_url = user_login_stats_url(@user_login_stats)
+    
+    @user_history= User.find_by_sql("SELECT year_created, FORMAT(AVG(num),0) AS users_num, MAX(num) as maximum_users FROM ((SELECT YEAR(created_at) AS year_created, MONTH(created_at) AS mca, COUNT(*) AS num FROM users GROUP BY mca, year_created)) AS tmp GROUP BY year_created")
+    @user_history_stats_url = user_history_charts_url @user_history
+    
+    @contribution_charts_avg=User.find_by_sql("SELECT year_created, FORMAT(AVG(num),0) AS contributions_num FROM ((SELECT YEAR(created_at) AS year_created, MONTH(created_at) AS mca, COUNT(*) AS num FROM contributions GROUP BY mca, year_created)) AS tmp GROUP BY year_created")
+    
+    @contribution_charts=User.find_by_sql("select DATE_FORMAT(created_at, '%b') as formated_date, count(contributable_type) as contribution_num,(select count(contributable_type) from contributions c2 where c2.created_at <= c1.created_at) as cumulative_contribution from contributions c1 where c1.created_at > DATE_ADD(NOW(),INTERVAL -12 MONTH) and c1.created_at < DATE_ADD(NOW(),INTERVAL -1 MONTH) group by  year(c1.created_at) ,month(c1.created_at) order by year(c1.created_at)")
+    @contribution_charts_stats_url =  contributions_charts_url(@contribution_charts)
+    
     @top_ten_networks = Network.most_members
     @top_ten_networks_chart_url = network_chart_url @top_ten_networks
+    
   end
 
   protected
-
+  #Google Charts
+  
+  def workflow_distrib_version_chart_url(workflow_version_distrib)
+    version_number=[]
+    number_of_workflows=[]
+      workflow_version_distrib.each do |n|
+        version_number.push n.current_version.to_i
+        number_of_workflows.push n.count.to_i
+    end
+    "http://chart.apis.google.com/chart?chs=400x250&cht=bvs&chtt=Workflow Version Breakdown&chxt=x,y&chxr=1,0,#{number_of_workflows.max * 1.5}&chds=0,#{number_of_workflows.max * 1.5}&chxl=0:|#{version_number.join "|"}&chd=t:#{number_of_workflows.join ","}&chm=N,000000,0,-1,11"
+  end
+  
+  def workflow_chart_url(workflow_count, workflow_pub, workflow_pubview)
+    "http://chart.apis.google.com/chart?chs=400x150&cht=bhs&chxt=x&chtt=Workflow Breakdown&chds=0,4000&chxr=0,0,4000&chd=t:#{workflow_count},#{workflow_pub},#{workflow_pubview}&chdl=Total Workflow|Publically Viewable Workflow|Publically Downloadable Workflow&chm=N,000000,0,-1,11"
+  end
+  
   def user_chart_url(activated_users_pct, unactivated_users_pct)
     "http://chart.apis.google.com/chart?chs=400x150&cht=p3&chtt=User Breakdown&chco=246090&chdl=Activated (#{activated_users_pct}%)|Unactivated (#{unactivated_users_pct}%)&chd=t:#{activated_users_pct},#{unactivated_users_pct}"
   end
+  
+  def user_login_stats_url (user_login_stats)
+    user_numbers=[]
+    login_status=[]
+    user_login_stats.each do |key, value|
+    user_numbers.push value.to_i
+    login_status.push key
+  end
+   "http://chart.apis.google.com/chart?chs=400x250&cht=bvs&chxr=0,1,7|1,0,#{user_numbers.max * 1.2}&chds=0,#{user_numbers.max * 1.2}&chtt=Login Status&chco=246090&chxt=x,y&chd=t:#{user_numbers.join ","}&chm=N,000000,0,-1,11"
+  end
 
+  def user_history_charts_url(user_history)
+    user_no=[]
+    date_joined=[]
+    user_history.each do |n|
+      user_no.push n.users_num.to_i
+      date_joined.push n.year_created
+    end
+    "http://chart.apis.google.com/chart?chs=400x150&cht=lc&chxr=1,0,#{user_no.max * 1.5}&chds=0,#{user_no.max * 1.5}&chtt=Average Users Per Month&chxl=0:|#{date_joined.join "|"}&chxt=x,y&chd=t:#{user_no.join ","}&chm=N,000000,0,-1,11"
+  end
+  
+  def contributions_charts_url(contribution_charts)
+    cumulative_contribution=[]
+    date_created=[]
+    contribution_charts.each do |n|
+      cumulative_contribution.push n.cumulative_contribution.to_i
+      date_created.push n.formated_date
+    end
+    max_contributions = cumulative_contribution.max * 1.2
+    min_contributions = cumulative_contribution.min * 0.2
+   "http://chart.apis.google.com/chart?chs=400x150&cht=lc&chco=3D7930&chxr=1,#{min_contributions},#{max_contributions}&chds=#{min_contributions},#{max_contributions}&chtt=Overall Contribution For The Past 12 Months&chxl=0:|#{date_created.join "|"}&chxt=x,y&chd=t:#{cumulative_contribution.join ","}&chdl=Contributions&chm=o,000000,0,-1,5"
+  end
+  
   def network_chart_url(networks)
     labels = []
     values = []
     networks.each do |n|
       labels.push ActionView::Helpers::TextHelper.truncate(n.title)
-      values.push n.memberships.length
+      values.push n.memberships.length.to_i
     end
-    "http://chart.apis.google.com/chart?chs=400x150&cht=bvs&chtt=Top Ten User Networks&chco=246090&chxt=x,y&chxr=0,1,10&chd=t:#{values.join ","}&chm=N,000000,0,-1,11"
+    "http://chart.apis.google.com/chart?chs=400x250&cht=bvs&chxr=1,0,#{values.max * 1.2}&chds=0,#{values.max * 1.2}&chtt=Top Ten User Networks&chco=246090&chxt=x,y&chxr=0,1,10&chd=t:#{values.join ","}&chm=N,000000,0,-1,11"
   end
 
   def check_admin

reply via email to

[Prev in Thread] Current Thread [Next in Thread]