Compute ticket statistics
And exclude admin/ConferencesController from rubocop_todo.yml
This commit is contained in:
parent
c2184c1c4f
commit
41503bb7a0
4 changed files with 122 additions and 0 deletions
|
|
@ -184,6 +184,59 @@ class Conference < ActiveRecord::Base
|
|||
result
|
||||
end
|
||||
|
||||
##
|
||||
# Returns an array with the summarized ticket sales per week.
|
||||
#
|
||||
# ====Returns
|
||||
# * +Array+ -> e.g. [0, 3, 3, 5] -> first week 0, second week 3 tickets sold
|
||||
def get_tickets_sold_per_week
|
||||
result = []
|
||||
|
||||
if tickets && ticket_purchases && registration_period
|
||||
tickets_sold = ticket_purchases.paid.group(:week).sum(:quantity)
|
||||
start_week = get_registration_start_week
|
||||
weeks = registration_weeks
|
||||
result = calculate_items_per_week(start_week, weeks, tickets_sold)
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
##
|
||||
# Returns an hash with ticket sales by ticket title
|
||||
# per week.
|
||||
#
|
||||
# ====Returns
|
||||
# * +Array+ -> e.g. 'Free Access' => [0, 3, 3, 5] -> first week 0 tickets sold, second week 3 tickets sold.
|
||||
def get_tickets_data
|
||||
result = {}
|
||||
if tickets && ticket_purchases && registration_period
|
||||
tickets_per_ticket_id_and_week = ticket_purchases.paid.group(:ticket_id, :week).sum(:quantity)
|
||||
|
||||
start_week = get_registration_start_week
|
||||
weeks = registration_weeks
|
||||
|
||||
tickets_by_id_per_week = {}
|
||||
|
||||
tickets.each do |ticket|
|
||||
tickets_by_id_per_week[ticket.id] = {}
|
||||
(start_week...(start_week + weeks)).each do |week|
|
||||
tickets_by_id_per_week[ticket.id][week] = 0
|
||||
end
|
||||
end
|
||||
|
||||
tickets_per_ticket_id_and_week.each do |ticket_week, value|
|
||||
tickets_by_id_per_week[ticket_week[0]][ticket_week[1]] = value
|
||||
end
|
||||
|
||||
tickets_by_id_per_week.each do |ticket, values|
|
||||
result[Ticket.find(ticket).title] = pad_array_left_not_kumulative(start_week, values)
|
||||
end
|
||||
|
||||
result['Weeks'] = weeks > 0 ? (1..weeks).to_a : 0
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
##
|
||||
# Calculates how many weeks the registration is.
|
||||
#
|
||||
|
|
@ -396,6 +449,46 @@ class Conference < ActiveRecord::Base
|
|||
calculate_user_distribution_hash(active_user, unconfirmed_user, dead_user)
|
||||
end
|
||||
|
||||
##
|
||||
# Returns a hash with per ticket sales => { "Title" => { value: number of tickets sold,
|
||||
# color: generated from the title using a hash function }, ...}
|
||||
#
|
||||
# ====Returns
|
||||
# * +hash+ -> hash
|
||||
def tickets_sold_distribution
|
||||
result = {}
|
||||
|
||||
if tickets && ticket_purchases
|
||||
tickets.each do |ticket|
|
||||
result[ticket.title] = {
|
||||
'value' => ApplicationController.helpers.humanized_money(ticket.tickets_sold).delete(',').to_i,
|
||||
'color' => "\##{Digest::MD5.hexdigest(ticket.title)[0..5]}"
|
||||
}
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
##
|
||||
# Returns a hash with per ticket turnover => { "Title" => { value: ticket turnover,
|
||||
# color: generated from the title using a hash function }, ...}
|
||||
#
|
||||
# ====Returns
|
||||
# * +hash+ -> hash
|
||||
def tickets_turnover_distribution
|
||||
result = {}
|
||||
|
||||
if tickets && ticket_purchases
|
||||
tickets.each do |ticket|
|
||||
result[ticket.title] = {
|
||||
'value' => ApplicationController.helpers.humanized_money(ticket.tickets_turnover).delete(',').to_i,
|
||||
'color' => "\##{Digest::MD5.hexdigest(ticket.title)[0..5]}"
|
||||
}
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
##
|
||||
# Calculates the overall program minutes
|
||||
#
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue