Implements user and event state distribution
This commit is contained in:
parent
069cc0eb4c
commit
b25ae50908
12 changed files with 344 additions and 14 deletions
|
|
@ -11,7 +11,14 @@ $(function() {
|
|||
"width":$(el).parent().width(),
|
||||
"height":$(el).parent().outerHeight()
|
||||
});
|
||||
redraw(animate, $(this));
|
||||
});
|
||||
|
||||
$(".line_chart").each(function(){
|
||||
draw_line_chart(animate, $(this));
|
||||
});
|
||||
|
||||
$(".doughnut_chart").each(function(){
|
||||
draw_doughnut_chart(animate, $(this));
|
||||
});
|
||||
|
||||
var m = 0;
|
||||
|
|
@ -21,13 +28,37 @@ $(function() {
|
|||
}, 30);
|
||||
}
|
||||
|
||||
function redraw(animation, $this){
|
||||
var options = {};
|
||||
function draw_doughnut_chart(animation, $this){
|
||||
var options = get_animation({}, animation);
|
||||
var tmp = $this.data('chart');
|
||||
|
||||
if(jQuery.isEmptyObject(tmp)){
|
||||
// Append error message if there is no data
|
||||
$this.parent().append("<h4 class=\"text-warning\">No data!</h4>");
|
||||
// Remove canvas
|
||||
$this.remove();
|
||||
}else{
|
||||
var data = [];
|
||||
for (var key in tmp) {
|
||||
data.push(tmp[key]);
|
||||
}
|
||||
|
||||
var ctx = $this.get(0).getContext("2d");
|
||||
new Chart(ctx).Doughnut(data, options);
|
||||
}
|
||||
}
|
||||
|
||||
function get_animation(options, animation){
|
||||
if (!animation){
|
||||
options.animation = false;
|
||||
} else {
|
||||
options.animation = true;
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
function draw_line_chart(animation, $this){
|
||||
var options = get_animation({}, animation);
|
||||
|
||||
var chart_data = create_dataset($this);
|
||||
var weeks = $this.parent().data('weeks');
|
||||
|
|
@ -36,8 +67,7 @@ $(function() {
|
|||
datasets : chart_data
|
||||
}
|
||||
|
||||
var canvas = $this[0];
|
||||
var ctx = canvas.getContext("2d");
|
||||
var ctx = $this.get(0).getContext("2d");
|
||||
new Chart(ctx).Line(data, options);
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +104,7 @@ $(function() {
|
|||
$('.conferenceCheckboxes input').change(function(){
|
||||
var chart = $(this).parent().data('chart');
|
||||
var $canvas = $('#' + chart + 'Chart');
|
||||
redraw(false, $canvas);
|
||||
draw_line_chart(false, $canvas);
|
||||
});
|
||||
|
||||
$(window).on('resize', function(){ size(false); });
|
||||
|
|
|
|||
|
|
@ -2,6 +2,12 @@ class Admin::ConferenceController < ApplicationController
|
|||
before_filter :verify_organizer
|
||||
|
||||
def index
|
||||
# Redirect to new form if there is no conference
|
||||
if Conference.count == 0
|
||||
redirect_to new_admin_conference_path
|
||||
return
|
||||
end
|
||||
|
||||
@total_user = User.count
|
||||
@new_user = User.where('created_at > ?', current_user.last_sign_in_at).count
|
||||
|
||||
|
|
@ -44,11 +50,8 @@ class Admin::ConferenceController < ApplicationController
|
|||
@registrations = normalize_array_length(@registrations, @registration_weeks)
|
||||
@registration_weeks = @registration_weeks > 0 ? (1..@registration_weeks).to_a : 1
|
||||
|
||||
# Redirect to new form if there is no conference
|
||||
if Conference.count == 0
|
||||
redirect_to new_admin_conference_path
|
||||
return
|
||||
end
|
||||
@event_distribution = Conference.event_distribution
|
||||
@user_distribution = Conference.user_distribution
|
||||
end
|
||||
|
||||
def new
|
||||
|
|
@ -85,6 +88,8 @@ class Admin::ConferenceController < ApplicationController
|
|||
@conference = Conference.find_by(short_title: params[:id])
|
||||
@conference_progress = @conference.get_status
|
||||
@top_submitter = @conference.get_top_submitter
|
||||
@event_distribution = @conference.event_distribution
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json { render json: @conference.to_json }
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
8
app/views/admin/conference/_event_distribution.html.haml
Normal file
8
app/views/admin/conference/_event_distribution.html.haml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
.well
|
||||
.text-center
|
||||
%h4 Event distribution
|
||||
%canvas.doughnut_chart{"data-chart"=>@event_distribution.to_json}
|
||||
.row
|
||||
- if @event_distribution
|
||||
- @event_distribution.each do |key, value|
|
||||
%span{"style"=>"border-bottom: 3px solid #{value['color']}"} #{key}: #{value['value']}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
%h4 Conference registrations over time
|
||||
.row
|
||||
.registrationsChart{"data-chart"=>"#{registrations.to_json}", "data-conferences"=>"#{conferences.to_json}", "data-weeks"=>"#{registration_weeks.to_json}"}
|
||||
%canvas#registrationsChart{"data-name"=>"registrations"}
|
||||
%canvas.line_chart#registrationsChart{"data-name"=>"registrations"}
|
||||
.row
|
||||
.text-center
|
||||
weeks
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
%h4 Event submissions over time
|
||||
.row
|
||||
.submissionsChart{"data-chart"=>"#{submissions.to_json}", "data-conferences"=>"#{conferences.to_json}", "data-weeks"=>"#{cfp_weeks.to_json}"}
|
||||
%canvas#submissionsChart{"data-name"=>"submissions"}
|
||||
%canvas.line_chart#submissionsChart{"data-name"=>"submissions"}
|
||||
.row
|
||||
.text-center
|
||||
weeks
|
||||
|
|
|
|||
8
app/views/admin/conference/_user_distribution.html.haml
Normal file
8
app/views/admin/conference/_user_distribution.html.haml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
.well
|
||||
.text-center
|
||||
%h4 User distribution
|
||||
%canvas.doughnut_chart{"data-chart"=>user_distribution.to_json}
|
||||
.row
|
||||
- if user_distribution
|
||||
- user_distribution.each do |key, value|
|
||||
%span{"style"=>"border-bottom: 3px solid #{value['color']}"} #{key}: #{value['value']}
|
||||
|
|
@ -6,11 +6,13 @@
|
|||
= render partial: 'submissions', locals: { conferences: @conferences, submissions: @submissions,
|
||||
cfp_weeks: @cfp_weeks }
|
||||
.col-md-4
|
||||
= render partial: 'event_distribution', locals: { event_distribution: @event_distribution }
|
||||
.row
|
||||
.col-md-8
|
||||
= render partial: 'registrations', locals: { conferences: @conferences, registrations: @registrations,
|
||||
registration_weeks: @registration_weeks }
|
||||
.col-md-4
|
||||
= render partial: 'user_distribution', locals: { user_distribution: @user_distribution }
|
||||
.col-md-8
|
||||
.row
|
||||
%ul.nav.nav-tabs#recentTable
|
||||
|
|
|
|||
|
|
@ -6,4 +6,6 @@
|
|||
.col-md-4
|
||||
= render partial: 'todo_list', locals: { conference_progress: @conference_progress }
|
||||
.col-md-4
|
||||
= render partial: 'top_submitter', locals: {top_submitter: @top_submitter}
|
||||
= render partial: 'top_submitter', locals: {top_submitter: @top_submitter}
|
||||
.col-md-4
|
||||
= render partial: 'event_distribution', locals: { event_distribution: @event_distribution }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue