% cache "proposals_stats,event_#{@event.slug}" do @tracks = @event.tracks @session_types = @event.session_types @proposals = @event.proposals_for_stats proposals_for_track = @proposals.inject({}){|result, proposal| (result[proposal.track] ||= []) << proposal; result} proposals_for_session_type = @proposals.inject({}){|result, proposal| (result[proposal.session_type] ||= []) << proposal; result} proposals_for_status = @proposals.inject({}){|result, proposal| (result[proposal.status] ||= []) << proposal; result} proposals_over_time = GoogleChart::LineChart.new('650x400',"Proposals over time",false) data_sets = { 'All Proposals' => { :color => "000000", :records => @proposals } } @tracks.each do |track| data_sets[track.title] = { :color => track.color.html, :records => proposals_for_track[track] } end data_sets.keys.sort.each do |key| set = data_sets[key] date_cursor = @proposals.first.created_at.to_date data = [0] previous_date = nil if set[:records].present? set[:records].each_with_index do |proposal,i| proposal_date = proposal.created_at.to_date if proposal_date != previous_date || i == set[:records].size-1 while date_cursor != proposal_date data << i+1 date_cursor += 1 end end previous_date = proposal_date end end proposals_over_time.data key, data, set[:color].gsub('#','') end proposals_over_time.axis :y, :range => [0,@proposals.size] proposals_over_time.axis :x, :labels => [@proposals.first.submitted_at.to_date, @proposals.last.submitted_at.to_date] track_distribution = GoogleChart::PieChart.new("650x400","Proposals by Track",false) @tracks.each do |track| count = proposals_for_track[track].try(:size) || 0 track_distribution.data "#{track.title} (#{count})", count, track.color.html.gsub('#','') end session_type_distribution = GoogleChart::PieChart.new("650x400","Proposals by Session Type",false) @session_types.each do |type| count = proposals_for_session_type[type].try(:size) || 0 session_type_distribution.data "#{type.title} (#{count})", count end session_status_distribution = GoogleChart::PieChart.new("650x400","Proposals by Status",false) proposals_for_status.keys.each do |status| count = proposals_for_status[status].try(:size) || 0 session_status_distribution.data "#{status.titleize} (#{count})", count end %>
Total proposals: <%= @proposals.count %>
<% end %><%# cache %>