Statistics on top of Events#index

This commit is contained in:
Ana 2016-06-11 14:09:23 +02:00
parent f5e52e3855
commit f5701f2e77
3 changed files with 24 additions and 0 deletions

View file

@ -316,6 +316,20 @@ class Conference < ActiveRecord::Base
Conference.calculate_event_distribution_hash(program.events.select(:state).group(:state).count)
end
##
# Returns a hash with scheduled vs unscheduled events
# { "Scheduled" => { value: number of confirmed and scheduled events, color: color },
# "Unscheduled" => { value: number of confirmed and unscheduled events, color: color }
#
# ====Returns
# * +hash+ -> hash
def scheduled_event_distribution
confirmed_events = program.events.where(state: 'confirmed')
scheduled_value = { 'value' => confirmed_events.where('start_time IS NOT NULL').count, 'color' => 'green' }
unscheduled_value = { 'value' => confirmed_events.where('start_time IS NULL').count, 'color' => 'red' }
{ 'Scheduled' => scheduled_value, 'Unscheduled' => unscheduled_value }
end
##
# Returns a hash with user distribution => {value: count of user state, color: color}
# active: signed in during the last 3 months