mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Implements user and event state distribution
This commit is contained in:
parent
069cc0eb4c
commit
b25ae50908
12 changed files with 344 additions and 14 deletions
|
|
@ -278,8 +278,88 @@ class Conference < ActiveRecord::Base
|
|||
Conference.calculate_person_submission_hash(submitter, counter)
|
||||
end
|
||||
|
||||
##
|
||||
# Returns a hash with event state => {value: count of event states, color: color}.
|
||||
# The result is calculated over all conferences.
|
||||
#
|
||||
# ====Returns
|
||||
# * +hash+ -> hash
|
||||
def self.event_distribution
|
||||
calculate_event_distribution_hash(Event.group(:state).count)
|
||||
end
|
||||
|
||||
##
|
||||
# Returns a hash with event state => {value: count of event states, color: color}
|
||||
#
|
||||
# ====Returns
|
||||
# * +hash+ -> hash
|
||||
def event_distribution
|
||||
Conference.calculate_event_distribution_hash(events.group(:state).count)
|
||||
end
|
||||
|
||||
##
|
||||
# Returns a hash with user distribution => {value: count of user state, color: color}
|
||||
# active: signed in during the last 3 months
|
||||
# unconfirmed: registered but not confirmed
|
||||
# dead: not signed in during the last year
|
||||
#
|
||||
# ====Returns
|
||||
# * +hash+ -> hash
|
||||
def self.user_distribution
|
||||
active_user = User.where('last_sign_in_at > ?', Date.today - 3.months).count
|
||||
unconfirmed_user = User.where('confirmed_at IS NULL').count
|
||||
dead_user = User.where('last_sign_in_at < ?', Date.today - 1.year).count
|
||||
|
||||
calculate_user_distribution_hash(active_user, unconfirmed_user, dead_user)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
##
|
||||
# Helper method for calculating hash with corresponding colors of user distribution states.
|
||||
#
|
||||
# ====Returns
|
||||
# * +hash+ -> hash
|
||||
def self.calculate_user_distribution_hash(active_user, unconfirmed_user, dead_user)
|
||||
result = {}
|
||||
if active_user > 0
|
||||
result['Active'] = {
|
||||
'color' => 'green',
|
||||
'value' => active_user
|
||||
}
|
||||
end
|
||||
if unconfirmed_user > 0
|
||||
result['Unconfirmed'] = {
|
||||
'color' => 'red',
|
||||
'value' => unconfirmed_user
|
||||
}
|
||||
end
|
||||
if dead_user > 0
|
||||
result['Dead'] = {
|
||||
'color' => 'black',
|
||||
'value' => dead_user
|
||||
}
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
##
|
||||
# Helper method. Calculates hash with corresponding colors of event state distribution.
|
||||
#
|
||||
# ====Returns
|
||||
# * +hash+ -> hash
|
||||
def self.calculate_event_distribution_hash(states)
|
||||
result = {}
|
||||
states.each do |key, value|
|
||||
result[key.capitalize] =
|
||||
{
|
||||
'value' => value,
|
||||
'color' => Event.get_state_color(key)
|
||||
}
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
##
|
||||
# Returns a hash with person => submissions ordered by submissions for all conferences
|
||||
#
|
||||
|
|
|
|||
|
|
@ -154,6 +154,26 @@ class Event < ActiveRecord::Base
|
|||
created_at.strftime('%W').to_i
|
||||
end
|
||||
|
||||
def self.get_state_color(state)
|
||||
# default azure
|
||||
result = '#00FFFF'
|
||||
case state
|
||||
when 'new' # blue
|
||||
result = '#0000FF'
|
||||
when 'withdrawn' # orange
|
||||
result = '#FF8000'
|
||||
when 'confirmed' # green
|
||||
result = '#00FF00'
|
||||
when 'unconfirmed' # yellow
|
||||
result = '#FFFF00'
|
||||
when 'rejected' # red
|
||||
result = '#FF0000'
|
||||
when 'canceled' # grey
|
||||
result = '#848484'
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def abstract_limit
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue