Skip to content

Commit

Permalink
Merge remote branch 'core/pimp' into pimp
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed Sep 13, 2010
2 parents e15daa7 + 3080935 commit 242d19b
Show file tree
Hide file tree
Showing 22 changed files with 366 additions and 120 deletions.
25 changes: 2 additions & 23 deletions app/controllers/emarketing_controller.rb
Expand Up @@ -233,17 +233,13 @@ def real_time_stats_request
def real_time_charts_request
range = (params[:range] || 5).to_i
intervals = (params[:intervals] || 10).to_i
update_only = (params[:update] || 0).to_i == 1
update_only = params[:update]
site_node_id = params[:site_node_id]

now = Time.now
now = now.to_i - (now.to_i % range.minutes)
to = now
from = now - (range*intervals).minutes

uniques = []
hits = []
labels = []
groups = []
if site_node_id
site_node = SiteNode.find_by_id site_node_id
Expand All @@ -252,23 +248,6 @@ def real_time_charts_request
groups = DomainLogEntry.traffic Time.at(from), range.minutes, intervals
end

groups.sort { |a,b| b.started_at <=> a.started_at }.each do |group|
stat = group.domain_log_stats[0]
if stat
uniques << stat.visits
hits << stat.hits
else
uniques << 0
hits << 0
end
labels << group.ended_at.strftime('%I:%M')
break if update_only
end

from = to - (range*intervals).minutes

format = '%b %e, %Y %I:%M%P'
data = { :range => range, :from => Time.at(from).strftime(format), :to => Time.at(to).strftime(format), :uniques => uniques, :hits => hits, :labels => labels }
return render :json => data
return render :json => DomainLogGroup.traffic_chart_data(groups, :desc => true, :update_only => update_only).merge(:range => range)
end
end
7 changes: 4 additions & 3 deletions app/helpers/cms_helper.rb
Expand Up @@ -276,11 +276,12 @@ def custom(options = {},&block )
# This class usually isn't instantiated directly, see CmsHelper#ajax_tabs for usage
class AjaxTabBuilder
include ActionView::Helpers::TextHelper
def initialize(view,tab_cnt,selected) # :nodoc:
def initialize(view,tab_cnt,selected,opts={}) # :nodoc:
@view = view
@tab_num = 0
@selected = selected
@tab_cnt = tab_cnt
@tab_cnt = tab_cnt
@opts = opts
end

# Creates a tab inside of the ajax_tabs
Expand Down Expand Up @@ -367,7 +368,7 @@ def ajax_tabs(options,selected,&block) # :yields: ActionTabBuilder.new
concat("<td #{opt==selected ? 'class="selected"' : 'class="normal"'}> <a class='ajax_link' onclick='SCMS.select_tab(this); #{js}' href='javascript:void(0);'>#{opt.t}</a></td>")
end
concat("<td class='extra'> &nbsp; </td> </tr>")
yield AjaxTabBuilder.new(self,options.length,selected_id)
yield AjaxTabBuilder.new(self,options.length,selected_id) if block_given?
concat("</table>")
end

Expand Down
28 changes: 28 additions & 0 deletions app/models/domain_log_group.rb
Expand Up @@ -101,4 +101,32 @@ def self.update_hits(group, opts={})
stat.update_attribute :hits, page_counts[target_id]
end
end

def self.traffic_chart_data(groups, opts={})
to = groups[0].started_at
from = groups[-1].ended_at

opts[:label] ||= '%I:%M'

groups = groups.sort { |a,b| b.started_at <=> a.started_at } if opts[:desc]

uniques = []
hits = []
labels = []
groups.each do |group|
stat = group.domain_log_stats[0]
if stat
uniques << stat.visits
hits << stat.hits
else
uniques << 0
hits << 0
end
labels << group.ended_at.strftime(opts[:label])
break if opts[:update_only]
end

format = opts[:format] || '%b %e, %Y %I:%M%P'
data = { :from => from.strftime(format), :to => to.strftime(format), :uniques => uniques, :visits => uniques, :hits => hits, :labels => labels }
end
end
6 changes: 4 additions & 2 deletions app/models/experiment_version.rb
Expand Up @@ -9,10 +9,12 @@ class ExperimentVersion < DomainModel
validates_presence_of :weight
validates_presence_of :experiment_id

def title
def title(opts={})
return @title if @title
return @title = self.revision.to_s unless self.page_revision
@title = "#{self.page_revision.active? ? '*' : ''} #{self.revision} #{self.page_revision.version_name}"
@title = "#{self.revision} #{self.page_revision.version_name}"
@title = "#{self.page_revision.active? ? '*' : ''} #{@title}" unless opts[:name_only]
@title
end

def num_visits
Expand Down
25 changes: 17 additions & 8 deletions app/views/emarketing/_visitor_detail.rhtml
@@ -1,25 +1,28 @@
<% @date_format = "%d %b %T %p".t -%>
<div class="visitor_container">

<b>
<div class="heading">

<h2>
<% if @user -%>
<%= 'User #%s:' / @user.id.to_s -%>
<%= link_to @user.name, url_for(:controller => "/members", :action => 'view', :path => @user.id) -%>
<% else -%>
<%= 'Anonymous user from %s' / @entry.ip_address.to_s -%>
<% end -%>
</b><br/>
<b>IP Address: <%= @entry.ip_address %>, <%= @entry.ip_address_name %>
</h2>

IP Address: <%= @entry.ip_address %>, <%= @entry.ip_address_name %>
<% if @entry.has_location? %>
( <%= @entry.location_display %>
<%= link_to 'Location Estimate', "http://maps.google.com/maps?ll=#{@entry.latitude},#{@entry.longitude}", :target => '_blank' if @entry.latitude %> )
<% end -%>
</b><br/>

<b>Content Viewed last Visit: <b><br/>
<h2 class="inform">Content Viewed last Visit:</h2>
<% @entry.last_session.session_content.each do |content_node| %>
<%= link_to h(content_node.title), content_node.link %><br/>
<% end -%>
<br/>

<br/>

<div class="real-time-stats">
Expand All @@ -28,12 +31,16 @@
<div class="page2">Where / <em>Action</em></div>
</div>
</div>
<div id="vistor_stats" class="real-time-stats real-time-stats-block two-tone-list">

</div>

<div class="visitor_container_body">
<div id="vistor_stats" class="real-time-stats real-time-stats-block">
<% @sessions.each_with_index do |ses,idx| %>
<div class='header'>Session started <%= ses.created_at.to_s(:long) %> from <%= ses.ip_address %></div>
<% ses.domain_log_entries.each_with_index do |entry, index| -%>
<% next unless entry.is_a?(DomainLogEntry) -%>
<div class="row <%= index % 2 == 0 ? 'even' : 'odd'%>">
<div>
<div class="stats clearfix">
<div class="date"><%= entry.occurred_at.localize @date_format %></div>
<div class="page2"><%= link_to entry.url, entry.url, :target => '_blank' %></div>
Expand All @@ -46,3 +53,5 @@
<% end -%>
</div>

</div>
</div>
8 changes: 6 additions & 2 deletions app/views/emarketing/charts.html.erb
Expand Up @@ -18,8 +18,9 @@ end
chart_top = @stats.size > 3 ? ((@stats.size - 3) * 3) : 0
%>
<div class='admin_content'>
<div style="padding-bottom:10px;">
<%= @when_options.collect { |opt| link_to opt[0], {:when => opt[1], :type_id => @type_id, :target_id => @target_id}, :class => @when == opt[1] ? 'selected' : nil }.join(' | ') %>
<div class="visitor_container" style="width:100%;">
<div class="heading" style="padding-bottom:10px;">
<%= @when_options.collect { |opt| link_to opt[0], {:when => opt[1], :type_id => @type_id, :target_id => @target_id}, :class => @when == opt[1] ? 'selected button_link' : 'button_link' }.join(' ') %>
</div>

<% if @type_options -%>
Expand All @@ -31,9 +32,11 @@ chart_top = @stats.size > 3 ? ((@stats.size - 3) * 3) : 0
</div>
<% end -%>

<div class="visitor_container_body">
<div id="chart_div">
<div id="chart_canvas"></div>
</div>
</div>

<script type="text/javascript">

Expand All @@ -56,3 +59,4 @@ $j(document).ready(function() {
</script>

</div>
</div>
25 changes: 13 additions & 12 deletions app/views/emarketing/stats.html.erb
@@ -1,30 +1,31 @@
<hr/>
<div class="clearfix admin_content" style="width:1210px;">

<div style="float:left; width:530px; padding-left:10px;">
<div class="clearfix admin_content" style="width:1240px;">

<div style="float:left;">
<div class="visitor_container" style="width:540px;">
<div class="real-time-stats">
<div class="stats headers clearfix">
<div class="who">Who</div>
<div class="when">When</div>
<div class="page">Where / <em>Actions</em></div>
</div>
</div>
<div class="visitor_container_body">
<div id="real_time_stats" class="real-time-stats real-time-stats-block">
</div>
</div>
</div>
</div>

<div style="float:left; width:660px; padding-left:10px;">
<% ajax_tabs [ ['5 Minutes', 'RealTimeStatsViewer.changeChartRange(5);'], [ '30 Minutes', 'RealTimeStatsViewer.changeChartRange(30);' ],['60 Minutes', 'RealTimeStatsViewer.changeChartRange(60);'] ], '5 Minutes' do |t| -%>
<% t.tab do -%>
<% end -%>
<% t.tab do -%>
<% end -%>
<% t.tab do -%>
<% end -%>
<% end -%>
<div style="float:left; width:660px;">
<div class="visitor_container">
<% ajax_tabs [ ['5 Minutes', 'RealTimeStatsViewer.changeChartRange(5);'], [ '30 Minutes', 'RealTimeStatsViewer.changeChartRange(30);' ],['60 Minutes', 'RealTimeStatsViewer.changeChartRange(60);'] ], '5 Minutes' -%>
<div class="visitor_container_body" style="padding-right:10px;">
<div id="real_time_charts"></div>
</div>
</div>
</div>

</div>

<script>
Expand Down
42 changes: 22 additions & 20 deletions app/views/emarketing/visitors.rhtml
Expand Up @@ -54,45 +54,50 @@
return false;
}



}

<%= active_table_javascript %>
</script>
<% action_panel :handler => 'visitors', :more => true do |p| -%>
<% end -%>
<br/>
<br/>
<% ajax_tabs [ 'Site Visitors', 'Google Analytics' ], 'Site Visitors' do |t| -%>
<% more_action_panel :handler => 'visitors' do |p| -%>
<%= p.link "Visitors", {:url => "javascript:void(0);"}, :"j-action" => 'swap', :swap => '#visitors,#google_analytics' %>
<%= p.link "Google Analytics", {:url => "javascript:void(0);"}, :"j-action" => 'swap', :swap => '#google_analytics,#visitors' %>
<% end -%>


<% t.tab do %>
<table>
<hr/>

<tr>
<div id="visitors">
<table>
<tr>
<td style='padding-right:10px;' width='450' valign='top'>
<div id='entries_table'>
<%= render :partial => 'visitor_table' %>
</div>
</td>
<td style='border-left:1px solid #000000; padding-left:10px;' valign='top' >
<td style='padding-left:10px;' valign='top'>
<div id='visitor_detail'>

</div>
</td>
</tr>
</table>
</div>

<% end -%>
<% t.tab do %>
<div id='options_updated' style='display:none;'><b><%= "Options Updated".t %></b></div>
<div id="google_analytics" style="display:none;" class="visitor_container">
<div class="heading"><h2>Google Analytics</h2></div>
<div class="visitor_container_body" style="width:600px;">
<div id='options_updated' style='display:none;'><b><%= "Options Updated".t %></b></div>
<% tabled_form_for :options, @options, :html => { :onsubmit => 'return VisitorViewer.saveOptions(this);' } do |f| %>
<%= f.radio_buttons :google_analytics, [ [ 'Enabled' , 'enabled' ], [ 'Disabled', 'disabled'] ], :label => "Google Analytics", :onchange => 'VisitorViewer.googleRadios()' %>
<%= f.text_field :analytics_code, :disabled => @options.google_analytics == 'enabled' ? false : true %>
<%= f.spacer %>
<%= f.submit_tag 'Update', :id => 'submit_options' %>
<% end -%>

<br/>

<div id='analytics_disabled' <%= "style='display:none;'" if @options.google_analytics == 'enabled'%>>
<%= "Google Analytics is a free service that tracks visitors to your website and allows you to analyze your traffic.".t %>
<%= "You must first".t %> <a target='_blank' href='<%= "http://www.google.com/analytics/".t %>'><%= "Register for Google Analytics".t %></a>.
Expand All @@ -106,13 +111,10 @@
<%= h('
urchinTracker();
</script> ') %>
</pre>
</pre>
</div>
<div id='analytics_enabled' <%= "style='display:none;'" unless @options.google_analytics == 'enabled'%>>
<%= "Goto".t %><a target='_blank' href='http://www.google.com/analytics/'><%= "Your Google Analytics Account".t %></a>
</div>

<% end -%>
<% end -%>

</div>
</div>

0 comments on commit 242d19b

Please sign in to comment.