Statistics on top of Registrations#index
This commit is contained in:
parent
f5701f2e77
commit
62c3ee1631
3 changed files with 83 additions and 2 deletions
|
|
@ -9,6 +9,10 @@ module Admin
|
||||||
@pdf_filename = "#{@conference.title}.pdf"
|
@pdf_filename = "#{@conference.title}.pdf"
|
||||||
@registrations = @conference.registrations.includes(:user).order('registrations.created_at ASC')
|
@registrations = @conference.registrations.includes(:user).order('registrations.created_at ASC')
|
||||||
@attended = @conference.registrations.where('attended = ?', true).count
|
@attended = @conference.registrations.where('attended = ?', true).count
|
||||||
|
|
||||||
|
@new_reg = @conference.registrations.where('created_at > ?', current_user.last_sign_in_at).count
|
||||||
|
@registration_distribution = @conference.registration_distribution
|
||||||
|
@affiliation_distribution = @conference.affiliation_distribution
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit; end
|
def edit; end
|
||||||
|
|
|
||||||
|
|
@ -325,11 +325,58 @@ class Conference < ActiveRecord::Base
|
||||||
# * +hash+ -> hash
|
# * +hash+ -> hash
|
||||||
def scheduled_event_distribution
|
def scheduled_event_distribution
|
||||||
confirmed_events = program.events.where(state: 'confirmed')
|
confirmed_events = program.events.where(state: 'confirmed')
|
||||||
scheduled_value = { 'value' => confirmed_events.where('start_time IS NOT NULL').count, 'color' => 'green' }
|
scheduled_value = { 'value' => confirmed_events.where.not(start_time: nil).count, 'color' => 'green' }
|
||||||
unscheduled_value = { 'value' => confirmed_events.where('start_time IS NULL').count, 'color' => 'red' }
|
unscheduled_value = { 'value' => confirmed_events.where(start_time: nil).count, 'color' => 'red' }
|
||||||
{ 'Scheduled' => scheduled_value, 'Unscheduled' => unscheduled_value }
|
{ 'Scheduled' => scheduled_value, 'Unscheduled' => unscheduled_value }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Returns a hash with Registration attended vs. Registration not attended
|
||||||
|
# { "Attended" => { value: number of registration attended, color: color },
|
||||||
|
# "Not attended" => { value: number of registration not attended, color: color }
|
||||||
|
#
|
||||||
|
# ====Returns
|
||||||
|
# * +hash+ -> hash
|
||||||
|
def registration_distribution
|
||||||
|
reg = registrations.includes(:user)
|
||||||
|
attended_value = { 'value' => reg.where(attended: true).count, 'color' => 'magenta' }
|
||||||
|
not_attended_value = { 'value' => reg.where.not(attended: true).count, 'color' => 'blue' }
|
||||||
|
{ 'Attended' => attended_value, 'Not attended' => not_attended_value }
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Returns a hash with affiliation =>
|
||||||
|
# {value: count of registration whose user has that affilation, color: color}
|
||||||
|
# In case that the affiliation is blank, it groups them in None and
|
||||||
|
# if the number of persons that have an affiliation are less than the 2% of
|
||||||
|
# the total number of registered people, they are grouped in others.
|
||||||
|
#
|
||||||
|
# ====Returns
|
||||||
|
# * +hash+ -> hash
|
||||||
|
def affiliation_distribution
|
||||||
|
counted_affiliations = registrations.joins(:user).group(:affiliation).count
|
||||||
|
result = {}
|
||||||
|
i=1
|
||||||
|
others = 0
|
||||||
|
none = 0
|
||||||
|
counted_affiliations.each do |key, value|
|
||||||
|
if value < 0.02 * registrations.length
|
||||||
|
others += value
|
||||||
|
elsif key.blank?
|
||||||
|
none += value
|
||||||
|
else
|
||||||
|
result[key.capitalize] = { 'value' => value, 'color' => next_color(i) }
|
||||||
|
i += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if others > 0
|
||||||
|
result['Others'] = { 'value' => others, 'color' => next_color(i) }
|
||||||
|
i += 1
|
||||||
|
end
|
||||||
|
result['None'] = { 'value' => none, 'color' => next_color(i) } if none > 0
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Returns a hash with user distribution => {value: count of user state, color: color}
|
# Returns a hash with user distribution => {value: count of user state, color: color}
|
||||||
# active: signed in during the last 3 months
|
# active: signed in during the last 3 months
|
||||||
|
|
@ -550,6 +597,16 @@ class Conference < ActiveRecord::Base
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# Returns a different html colour for every i. We make use of big prime numbers
|
||||||
|
# to avoid repetition and to make consecutive colors clearly different.
|
||||||
|
def next_color(i)
|
||||||
|
color = '#000000'
|
||||||
|
color[1..2] = ((i*113)%239 + 16).to_s(16)
|
||||||
|
color[3..4] = ((i*67)%239 + 16).to_s(16)
|
||||||
|
color[5..6] = ((i*151)%239 + 16).to_s(16)
|
||||||
|
color
|
||||||
|
end
|
||||||
|
|
||||||
after_create do
|
after_create do
|
||||||
self.create_contact
|
self.create_contact
|
||||||
self.create_program
|
self.create_program
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,26 @@
|
||||||
= link_to 'Export XLS', {format: :xlsx}, class: 'btn btn-success'
|
= link_to 'Export XLS', {format: :xlsx}, class: 'btn btn-success'
|
||||||
%p.text-muted
|
%p.text-muted
|
||||||
All the people who registered to your event
|
All the people who registered to your event
|
||||||
|
.row
|
||||||
|
.col-sm-4.col-xs-4
|
||||||
|
.dashbox.text-center
|
||||||
|
%span.fa.fa-user.fa-lg
|
||||||
|
%span.fa.fa-lg
|
||||||
|
= @registrations.length
|
||||||
|
%p
|
||||||
|
%small
|
||||||
|
#{'Registration'.pluralize(@registrations.length)}
|
||||||
|
- if @new_reg
|
||||||
|
%span.label.label-success{title: "+#{@new_reg} since you last logged in!"}
|
||||||
|
+
|
||||||
|
= @new_reg
|
||||||
|
.col-md-4
|
||||||
|
= render partial: 'admin/conference/doughnut_chart', locals: {title: 'Affiliation', data: @affiliation_distribution}
|
||||||
|
- unless @conference.pending?
|
||||||
|
.col-md-4
|
||||||
|
= render partial: 'admin/conference/doughnut_chart', locals: {title: 'Attended registrations', data: @registration_distribution}
|
||||||
|
.row
|
||||||
|
.col-md-12
|
||||||
%table.table.table-hover.datatable#registrations
|
%table.table.table-hover.datatable#registrations
|
||||||
%thead
|
%thead
|
||||||
%tr
|
%tr
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue