hound fixes

This commit is contained in:
Stella Rouzi 2014-06-26 15:43:24 +03:00
parent e8990bfb12
commit fc753282d3
14 changed files with 180 additions and 144 deletions

View file

@ -3,23 +3,31 @@ module Admin
before_filter :verify_organizer
def index
@registrations = @conference.registrations.includes(:user).order('registrations.created_at ASC')
@registrations = @conference.registrations.includes(:user)
@registrations = @registrations.order('registrations.created_at ASC')
@registered = @conference.registrations.count
@attendees = @conference.registrations.where('attended = ?', true).count
@pre_registered = @conference.registrations.where('created_at < ?', @conference.start_date).count
@pre_registered_attended = @conference.registrations.where('created_at < ? AND attended = ?', @conference.start_date, true).count
@pre_registered = @conference.registrations
@pre_registered = @pre_registered.where('created_at < ?', @conference.start_date).count
@pre_registered_attended = @conference.registrations.where('created_at < ? AND attended = ?',
@conference.start_date, true).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
@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
@handicapped_access = @conference.registrations.where(handicapped_access_required: true).count
@handicapped_access_attended = @conference.registrations.where(handicapped_access_required: true)
@handicapped_access_attended = @conference.registrations.where(handicapped_access_required:
true)
@handicapped_access_attended = @handicapped_access_attended.where(attended: true).count
@suggested_hotel_stay = @conference.registrations.where('using_affiliated_lodging = ?', true).count
@suggested_hotel_stay = @conference.registrations.where('using_affiliated_lodging = ?',
true).count
@events = @conference.events
# Events charts
@machine_states = [['confirmed'], ['cancelled'], ['rejected'], ['withdrawn'], ['new', 'review'], ['unconfirmed', 'accepted']]
@machine_states = [['confirmed'], ['cancelled'], ['rejected'], ['withdrawn'],
['new', 'review'], ['unconfirmed', 'accepted']]
# Types distribution per state
@type_state = {}
@machine_states.each do |state|
@ -40,7 +48,7 @@ module Admin
if @events.count > 0
start_date = @events.minimum('created_at').strftime('%Y-%m-%d')
end_date = @events.maximum('created_at').strftime('%Y-%m-%d')
if start_date != nil && end_date != nil
unless start_date == nil || end_date == nil
@events_time = var_time(start_date, end_date, @events, 'created_at')
end
end
@ -79,8 +87,13 @@ module Admin
typelength += myevent.event_type.length
@totallength += myevent.event_type.length
end
@eventstats[mytype.title] = { 'count' => events_mytype.count, 'length' => events_mytype.count * mytype.length } if @eventstats[mytype.title] == nil
tmp = { "#{mystate.name}" => { 'type_state_count' => events_mytype_mystate.count, 'type_state_length' => typelength } }
if @eventstats[mytype.title] == nil
@eventstats[mytype.title] = { 'count' => events_mytype.count,
'length' => events_mytype.count * mytype.length }
end
tmp = { "#{mystate.name}" => { 'type_state_count' => events_mytype_mystate.count,
'type_state_length' => typelength } }
@eventstats[mytype.title].merge!(tmp)
end
end
@ -88,7 +101,8 @@ module Admin
@eventstats['totallength'] = @totallength
# SPEAKERS stats
@speakers = User.joins(:events).where('events.conference_id = ? AND events.state LIKE ?', @conference.id, 'confirmed').uniq
@speakers = User.joins(:events).where('events.conference_id = ? AND events.state LIKE ?',
@conference.id, 'confirmed').uniq
@speaker_fields_user = %w(name email affiliation)
@speaker_fields_reg = %w(arrival departure)
# TICKETS stats
@ -98,7 +112,7 @@ module Admin
@tickets_time = []
if @conference.registration_start_date and @conference.end_date and @registered > 0 and @supporter_levels
if @conference.registration_start_date && @conference.end_date && @registered > 0 && @supporter_levels
start_date = @conference.registration_start_date
end_date = @conference.end_date
levels = []
@ -108,10 +122,13 @@ module Admin
end
(start_date..end_date).each do |day|
if @tickets.where('supporter_registrations.created_at LIKE ?', "%#{day}%").where('supporter_levels.title' => levels).count != 0
if @tickets.where('supporter_registrations.created_at LIKE ?', "%#{day}%").where(
'supporter_levels.title' => levels).count != 0
@conference.supporter_levels.each do |level|
day_ticket_count = @tickets.where('supporter_registrations.created_at LIKE ? AND supporter_levels.title LIKE ?', "%#{day}%", "%#{level.title}%").count
day_ticket_count = @tickets.where('supporter_registrations.created_at LIKE ?
AND supporter_levels.title LIKE ?',
"%#{day}%", "%#{level.title}%").count
index = @tickets_time.index { |v| v['key'] == "#{level.title}" }
@tickets_time[index]['values'] << { 'label' => "#{day}", 'value' => day_ticket_count }
@ -123,7 +140,8 @@ module Admin
@tickets_time.each do |ticket|
value = ticket['values'].map { |x| x['value'] }.sum
percent = (value.to_f / @tickets.count * 100).round(2)
@tickets_distribution << { 'status' => ticket['key'], 'value' => value, 'percent' => percent }
@tickets_distribution << { 'status' => ticket['key'],
'value' => value, 'percent' => percent }
end
# OTHER_INFO chart / To be 'Questions'
@ -136,7 +154,7 @@ module Admin
]
# REGISTRATIONS, registered_time
if @conference.registration_start_date and @conference.end_date and @registered > 0
if @conference.registration_start_date && @conference.end_date && @registered > 0
start_date = @conference.registration_start_date
end_date = @conference.end_date
@registered_time = var_time(start_date, end_date, @registrations, 'created_at')
@ -156,39 +174,39 @@ module Admin
result << { 'status' => "#{day}", 'value' => day_var_count }
end
end
return result
result
end
def var_state_func(vars, field, mystate)
result = []
for myvar in vars do
vars.each do |myvar|
# Find events per track and state
value = @conference.events.where("#{field}_id" => myvar.id).where(state: mystate).count
# Find all events in that state
total = @conference.events.where(state: mystate).count
status = "#{myvar.name}"
percent = 0
if value != 0
percent = (value.to_f / total * 100).round(2)
result << { 'status' => status, 'value' => value, 'percent' => percent }
else
percent = 0
end
end
# Get no of events for which the field is not set (Needed so that the pie shows half piece for 50%)
sum = result.inject(0) { |sum, hash| sum + hash['value'] }
value = total - sum if total and sum
# Get no of events for which the field is not set (So that pie shows half piece for 50%)
sum = result.inject(0) { |s, hash| s + hash['value'] }
value = total - sum
if sum != 0 && value != 0
percent = (value.to_f / total * 100).round(2)
result << { 'status' => "no #{field} set", 'value' => value, 'percent' => percent }
end
return result
result
end
def speaker_reg(speaker)
speaker.registrations.where('conference_id = ? AND user_id = ?', @conference.id, speaker.id).first
speaker.registrations.where('conference_id = ? AND user_id = ?',
@conference.id, speaker.id).first
end
def speaker_diet(reg)
@ -200,7 +218,8 @@ module Admin
end
def social_event_count(event)
@conference.registrations.joins(:social_events).where('registrations_social_events.social_event_id = ?', event).count
@conference.registrations.joins(:social_events).where(
'registrations_social_events.social_event_id = ?', event).count
end
helper_method :speaker_reg