Merge pull request #18 from differentreality/stats

Stats
This commit is contained in:
Henne Vogelsang 2013-07-12 04:43:23 -07:00
commit 83b20dfc58
6 changed files with 227 additions and 0 deletions

View file

@ -0,0 +1,41 @@
class Admin::StatsController < ApplicationController
before_filter :verify_organizer
def index
@registrations = @conference.registrations.all(:joins => :person,
:order => "registrations.created_at ASC",
:select => "registrations.*,
people.last_name AS last_name,
people.first_name AS first_name,
people.public_name AS public_name,
people.email AS email")
@attendees = @conference.registrations.where("attended = ?", true).count
@registered = @conference.registrations.count
@registered_with_partner = @conference.registrations.where("attending_with_partner = ?", true).count
@attended_with_partner = @conference.registrations.where("attending_with_partner = ? AND attended = ?", true, true).count
@speakers = Person.joins(:events).where("events.conference_id = ? AND events.state LIKE ?", @conference.id, 'confirmed').uniq
@speaker_fields_person = %w[name email affiliation]
@speaker_fields_reg = %w[with_partner need_access other_needs diet arrival departure]
@supporter_levels = @conference.supporter_levels
end
def reg_support(level)
Registration.find_by_sql("select supporter_registrations.* FROM registrations, supporter_registrations, supporter_levels WHERE registrations.id = supporter_registrations.registration_id AND registrations.conference_id = #{@conference.id} AND supporter_registrations.supporter_level_id = #{level.id}")
end
def speaker_reg(speaker)
speaker.registrations.where("conference_id = ? AND person_id = ?", @conference.id, speaker.id).first
end
def speaker_diet(reg)
@conference.dietary_choices.find(reg.dietary_choice_id)
end
helper_method :speaker_reg
helper_method :speaker_diet
helper_method :reg_support
end

View file

@ -1,4 +1,19 @@
module ApplicationHelper
def getdatetime(registration, field)
if registration.send(field.to_sym).kind_of?(String)
DateTime.parse(registration.send(field.to_sym)).strftime("%d %b %H:%M") if registration.send(field.to_sym)
else
registration.send(field.to_sym).strftime("%d %b %H:%M") if registration.send(field.to_sym)
end
end
def getdate(var)
if var.kind_of?(String)
DateTime.parse(var).strftime("%a, %d %b")
else
var.strftime("%a, %d %b")
end
end
def add_association_link(association_name, form_builder, div_class, html_options = {})
link_to_add_association "Add " + association_name.to_s.singularize, form_builder, div_class, html_options.merge(:class => "assoc btn btn-success")

View file

@ -20,6 +20,9 @@ class Person < ActiveRecord::Base
:styles => {:tiny => "16x16>", :small => "32x32>", :large => "128x128>"},
:default_url => "person_:style.png"
validates_attachment_content_type :avatar, :content_type => [/jpg/, /jpeg/, /png/, /gif/]
alias_attribute :affiliation, :company
def to_s
if self.public_name.empty?
self.first_name + " " + self.last_name

View file

@ -0,0 +1,157 @@
.row-fluid
.span12
.pull-left{:style=>"margin-top:20px; margin-bottom:20px;"}
= link_to "Registration Stats", "#", :id => "registrations-stats-link", :class => "btn btn-success"
= link_to "Speakers Stats", "#", :id => "speakers-stats-link", :class => "btn btn-success"
= link_to "Tickets Stats", "#", :id => "tickets-stats-link", :class => "btn btn-success"
#tickets-stats
.row-fluid
.span4
- if @supporter_levels.count > 0
%table.table.table-bordered.table-striped
%thead
%th Support Level
%th #
%th %
- @supporter_levels.each do |level|
- reg_support = reg_support(level)
- if reg_support.count > 0
%tr
%td= level.title
%td
= reg_support.count
%td
= "#{reg_support.count * 100 / @registered}% of registered"
- if @attendees
%br
= "#{reg_support.count * 100 / @attendees}% of attendees"
#registrations-stats
%h3
Registered
- if @registered
= "(#{@registered})"
- if @attendees
= " - Attendees (#{@attendees})"
.row-fluid
.span3
%table.table.table-bordered.table-striped
%thead
%th General Stats
%th #
%tr
%td Registered attended
%td= @registered_attended
%tr
%td Registered not attended
%td= @registered_not_attended
%tr
%td Attended with partner
%td= @attended_with_partner
%tr
%td Registred to attend with partner
%td= @registered_with_partner
%tr
%td Handicapped Access for:
%td= @conference.registrations.where("handicapped_access_required = ?", true).count
%tr
%td Staying at suggested hotel:
%td= @conference.registrations.where("using_affiliated_lodging = ?", true).count
- if @conference.use_dietary_choices == true
- diet_choices = []
- @conference.dietary_choices.each do |d|
- count = @conference.registrations.where("dietary_choice_id = ?", d.id).count
- if count > 0
- diet_choices << [d.title, count]
- if diet_choices.any?
.span4
%table.table.table-bordered.table-striped
%thead
%th Dietary Choice
%th #
%th Percentage
- diet_choices.each do |d|
%tr
%td= d[0]
%td= d[1]
%td
= "#{d[1] * 100 / @registered}% of registered"
- if @attendees
%br
= "#{d[1] * 100 / @attendees}% of attendees"
- if @conference.social_events.count > 0
- social_events = []
- @conference.social_events.each do |social_event|
- count = @conference.registrations.joins(:social_events).where("registrations_social_events.social_event_id = ?", social_event.id).count
- if count > 0
- social_events << [social_event.title, count]
- if social_events.any?
.span4
%table.table.table-bordered.table-striped
%thead
%th Social Event
%th #
- social_events.each do |s|
%tr
%td= s[0]
%td= s[1]
#speakers-stats
- count =0
.row-fluid
%h3
Speakers (#{@speakers.length})
%br
%table.table.table-striped.table-bordered.table-hover#events
%thead
%th
ID
- (@speaker_fields_person + @speaker_fields_reg).each do |field|
%th
= field.capitalize
- @speakers.each do |speaker|
%tr
%td
= count +=1
- @speaker_fields_person.each do |field|
%td
- if field == 'name'
= speaker.first_name
= speaker.last_name
%br
(#{speaker.public_name})
- else
= speaker.send(field.to_sym)
- @speaker_fields_reg.each do |field|
%td
- reg = speaker_reg(speaker)
- if !reg.nil?
- if field == "diet"
- if reg.dietary_choice_id
= speaker_diet(reg).title
%br
= reg.other_dietary_choice
- elsif field == 'arrival' || field == 'departure'
= getdatetime(reg, field)
- else
= reg.send(field.to_sym)
:javascript
$(document).ready( function() {
$("#registrations-stats-link").click(function() {
$("#registrations-stats").toggle();
});
$("#speakers-stats-link").click(function() {
$("#speakers-stats").toggle();
});
$("#tickets-stats-link").click(function() {
$("#tickets-stats").toggle();
});
});

View file

@ -53,6 +53,16 @@
= link_to(admin_conference_events_path(@conference.short_title)) do
%i.icon-comment
Events
- if current_page?(admin_conference_stats_path(@conference.short_title))
%li.active
= link_to('#') do
%i.icon-comment
Stats
- else
%li
= link_to(admin_conference_stats_path(@conference.short_title)) do
%i.icon-comment
Stats
%li
= link_to(admin_conference_schedule_path(@conference.short_title), :target => "_blank") do
%i.icon-tasks

View file

@ -9,6 +9,7 @@ Osem::Application.routes.draw do
resources :conference do
get "/schedule" => "schedule#show"
put "/schedule" => "schedule#update"
get "/stats" => "stats#index"
get "/registrations" => "registrations#show"
get "/registrations/edit" => "registrations#edit"
put "/registrations/edit" => "registrations#update"