Browse Source

Added data to excel sheet

development
Godwin 8 years ago
parent
commit
8ffb852b4d
  1. 76
      app/controllers/conferences_controller.rb
  2. 9
      app/views/conferences/stats.xlsx.haml
  3. 10
      config/locales/en.yml

76
app/controllers/conferences_controller.rb

@ -315,42 +315,98 @@ class ConferencesController < ApplicationController
end end
end end
when :stats when :stats
@registrations = ConferenceRegistration.where(:conference_id => @this_conference.id)
if request.format.xlsx? if request.format.xlsx?
@registrations = ConferenceRegistration.where(:conference_id => @this_conference.id).sort { |a,b| (a.user.present? ? (a.user.firstname || '') : '').downcase <=> (b.user.present? ? (b.user.firstname || '') : '').downcase }
logger.info "Generating stats.xls" logger.info "Generating stats.xls"
@excel_data = { @excel_data = {
columns: [:name, :email, :city, :date, :languages], columns: [
column_types: {date: :date}, :name,
:email,
:status,
:registration_fees_paid,
:date,
:city,
:preferred_language,
:languages,
:arrival,
:departure,
:housing,
:bike,
:food,
:companion,
:allergies
],
column_types: {
name: :bold,
date: :date,
arrival: [:date, :day],
departure: [:date, :day],
registration_fees_paid: :money
},
keys: { keys: {
name: 'forms.labels.generic.name', name: 'forms.labels.generic.name',
email: 'forms.labels.generic.email', email: 'forms.labels.generic.email',
status: 'forms.labels.generic.registration_status',
city: 'forms.labels.generic.location', city: 'forms.labels.generic.location',
date: 'articles.conference_registration.terms.Date', date: 'articles.conference_registration.terms.Date',
languages: 'articles.conference_registration.terms.Languages' languages: 'articles.conference_registration.terms.Languages',
preferred_language: 'articles.conference_registration.terms.Preferred_Languages',
arrival: 'forms.labels.generic.arrival',
departure: 'forms.labels.generic.departure',
housing: 'forms.labels.generic.housing',
bike: 'forms.labels.generic.bike',
food: 'forms.labels.generic.food',
companion: 'articles.conference_registration.terms.companion',
allergies: 'forms.labels.generic.allergies',
registration_fees_paid: 'articles.conference_registration.headings.fees_paid'
}, },
data: [], data: []
} }
#@registrations.sort_by! { |a, b| a.title.downcase <=> b.title.downcase }
@registrations.each do | r | @registrations.each do | r |
user = r.user_id ? User.where(id: r.user_id).first : nil user = r.user_id ? User.where(id: r.user_id).first : nil
if user.present? if user.present?
companion = ''
if r.housing_data.present? && r.housing_data['companions'].present?
companion_user = User.find_by_email(r.housing_data['companions'].first)
companion = view_context._'articles.conference_registration.terms.registration_status.unregistered'
if companion_user.present?
cr = ConferenceRegistration.where(user_id: companion_user.id).order(created_at: :desc).limit(1).first
if cr.present? && ((cr.steps_completed || []).include? 'questions')
companion = companion_user.named_email
end
end
end
steps = r.steps_completed || []
@excel_data[:data] << { @excel_data[:data] << {
name: user.firstname || '', name: user.firstname || '',
email: user.email || '', email: user.email || '',
status: (view_context._"articles.conference_registration.terms.registration_status.#{(steps.include? 'questions') ? 'registered' : ((steps.include? 'contact_info') ? 'preregistered' : 'unregistered')}"),
date: r.created_at ? r.created_at.strftime("%F %T") : '', date: r.created_at ? r.created_at.strftime("%F %T") : '',
city: r.city || '', city: r.city || '',
languages: ((r.languages || []).map { |x| view_context.language x }).join(', ').to_s preferred_language: user.locale.present? ? (view_context.language user.locale) : '',
languages: ((r.languages || []).map { |x| view_context.language x }).join(', ').to_s,
arrival: r.arrival ? r.arrival.strftime("%F %T") : '',
departure: r.departure ? r.departure.strftime("%F %T") : '',
housing: r.housing || '',
bike: r.bike.present? ? (view_context._"articles.conference_registration.questions.bike.#{r.bike}") : '',
food: r.food.present? ? (view_context._"articles.conference_registration.questions.food.#{r.food}") : '',
companion: companion,
allergies: r.allergies,
registration_fees_paid: r.registration_fees_paid
} }
end end
end end
return respond_to do | format | return respond_to do | format |
# format.html
format.xlsx { render xlsx: :stats, filename: "stats-#{DateTime.now.strftime('%Y-%m-%d')}" } format.xlsx { render xlsx: :stats, filename: "stats-#{DateTime.now.strftime('%Y-%m-%d')}" }
end end
else else
@registrations = ConferenceRegistration.where(:conference_id => @this_conference.id)
@registration_count = @registrations.size @registration_count = @registrations.size
@completed_registrations = 0 @completed_registrations = 0
@bikes = 0#@registrations.count { |r| r.bike == 'yes' } @bikes = 0
@donation_count = 0 @donation_count = 0
@donations = 0 @donations = 0
@food = { meat: 0, vegan: 0, vegetarian: 0, all: 0 } @food = { meat: 0, vegan: 0, vegetarian: 0, all: 0 }
@ -360,10 +416,8 @@ class ConferencesController < ApplicationController
@bikes += 1 if r.bike == 'yes' @bikes += 1 if r.bike == 'yes'
#if r.food.present?
@food[r.food.to_sym] += 1 @food[r.food.to_sym] += 1
@food[:all] += 1 @food[:all] += 1
#end
if r.registration_fees_paid.present? && r.registration_fees_paid > 0 if r.registration_fees_paid.present? && r.registration_fees_paid > 0
@donation_count += 1 @donation_count += 1

9
app/views/conferences/stats.xlsx.haml

@ -8,13 +8,14 @@
- @excel_data[:data].each do |row| - @excel_data[:data].each do |row|
%tr %tr
- @excel_data[:columns].each do |column| - @excel_data[:columns].each do |column|
%td{class: (@excel_data[:column_types].present? && @excel_data[:column_types][column].present?) ? @excel_data[:column_types][column].to_s : nil} %td{class: (@excel_data[:column_types].present? && @excel_data[:column_types][column].present?) ? @excel_data[:column_types][column] : nil}=(row[column].present? ? (_!row[column]) : '')
- if row[column].present?
=_!row[column]
- format_xls 'table' do - format_xls 'table' do
- workbook use_autowidth: true - workbook use_autowidth: true
- format bg_color: '333333' - format bg_color: '333333'
- format 'td', font_name: 'Calibri', bg_color: 'ffffff', fg_color: '333333' - format 'td', font_name: 'Calibri', bg_color: 'ffffff', fg_color: '333333'
- format 'th', font_name: 'Calibri', b: true, bg_color: '333333', fg_color: 'ffffff' - format 'th', font_name: 'Calibri', b: true, bg_color: '333333', fg_color: 'ffffff'
- format 'td.date', num_fmt: 22, font_name: 'Courier New', sz: 10 - format 'td.date', num_fmt: 22, font_name: 'Courier New', sz: 10, bg_color: 'ffffff', fg_color: '333333'
- format 'td.date.day', num_fmt: 14, font_name: 'Courier New', sz: 10, bg_color: 'ffffff', fg_color: '333333'
- format 'td.money', num_fmt: 2, font_name: 'Courier New', sz: 10, bg_color: 'ffffff', fg_color: '333333'
- format 'td.bold', font_name: 'Calibri', bg_color: 'ffffff', fg_color: '333333', b: true

10
config/locales/en.yml

@ -1061,6 +1061,11 @@ en:
Total_Donations: Total Donations Total_Donations: Total Donations
Total_Registrations: Total Registrations Total_Registrations: Total Registrations
Date: Registration Date Date: Registration Date
registration_status:
unregistered: Unregistered
preregistered: Preregistered
registered: Registered
companion: Companion
about_bikebike: about_bikebike:
paragraphs: paragraphs:
bicycle_project_paragraph: 'From collectives that use the bicycle as an excuse to change society, economy and the environment. Non-profit groups that have a community bike shops, cooperatives and other projects that promote the use of the bicycle and that come together to turn their communities into a place where riding is easier, more inclusive, safer and more fun. The list below uses the criteria found in the old Bicycle Organization Organization Project for what constitutes a community bike shop. The bike project need not meet all these criteria. Rather, it is a general list of qualities which are common among many bicycle projects.' bicycle_project_paragraph: 'From collectives that use the bicycle as an excuse to change society, economy and the environment. Non-profit groups that have a community bike shops, cooperatives and other projects that promote the use of the bicycle and that come together to turn their communities into a place where riding is easier, more inclusive, safer and more fun. The list below uses the criteria found in the old Bicycle Organization Organization Project for what constitutes a community bike shop. The bike project need not meet all these criteria. Rather, it is a general list of qualities which are common among many bicycle projects.'
@ -1207,7 +1212,10 @@ en:
subregion: State / Province subregion: State / Province
country: Country country: Country
postal_code: Postal Code postal_code: Postal Code
status: Status status: Status,
bike: Bike
food: Food
housing: Housing
actions: actions:
generic: generic:
login: Sign In login: Sign In

Loading…
Cancel
Save