Add submissions chart to conferences

This commit is contained in:
Petko Bordjukov 2014-10-15 12:58:00 +03:00
parent d1f49a4218
commit 49079b635e
8 changed files with 67 additions and 0 deletions

View File

@ -47,6 +47,8 @@ gem 'font-awesome-rails'
gem 'nested_form'
gem 'jquery-datatables-rails'
gem 'morrisjs-rails'
gem 'raphael-rails'
group :development do
gem 'spring'

View File

@ -149,6 +149,8 @@ GEM
mime-types (2.4.1)
mini_portile (0.6.0)
minitest (5.4.2)
morrisjs-rails (0.5.1)
railties (> 3.1, < 5)
multi_json (1.10.1)
nested_form (0.3.2)
net-scp (1.2.1)
@ -196,6 +198,7 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.3.2)
raphael-rails (2.1.2)
rb-fsevent (0.9.4)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
@ -301,6 +304,7 @@ DEPENDENCIES
guard-rspec
jquery-datatables-rails
jquery-rails
morrisjs-rails
nested_form
pg
phony_rails
@ -308,6 +312,7 @@ DEPENDENCIES
rails (= 4.1.6)
rails-erd
rails-i18n
raphael-rails
rmagick
rspec-rails
sass-rails (~> 4.0.3)

View File

@ -5,4 +5,6 @@
//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
//= require bootstrap-sprockets
//= require metisMenu/metisMenu
//= require raphael
//= require morris
//= require_directory .

View File

@ -0,0 +1,9 @@
$ ->
Morris.Line
element: 'submissions-chart'
data: $('#submissions-chart').data('submissions')
xkey: 'created_at'
ykeys: ['all_submissions', 'all_confirmations']
labels: ['Submissions', 'Confirmed submissions']
lineColors: ['#D9230F', '#469408']
resize: true

View File

@ -7,6 +7,7 @@
@import "metisMenu/metisMenu";
@import "dataTables/jquery.dataTables";
@import "dataTables/bootstrap/3/jquery.dataTables.bootstrap";
@import "morris";
@import "layout";
@import "navigation";

View File

@ -0,0 +1,31 @@
module ConferencesHelper
def submissions_chart_data(conference)
submissions_by_day = conference.submissions_grouped_by_day
confirmed_by_day = conference.submissions_grouped_by_confirmation_day
start_date = conference.created_at.to_date
end_date = Time.zone.now.to_date < conference.start_date.to_date ? Time.zone.now.to_date : conference.start_date.to_date
chart_data = (start_date..end_date).map do |date|
{
created_at: date,
new_submissions: submissions_by_day[date].try(:first).try(:number) || 0,
new_confirmations: confirmed_by_day[date].try(:first).try(:number) || 0
}
end
chart_data.each_with_index do |entry, index|
entry[:all_submissions] = if index == 0
entry[:new_submissions]
else
chart_data[index - 1][:all_submissions] + entry[:new_submissions]
end
entry[:all_confirmations] = if index == 0
entry[:new_confirmations]
else
chart_data[index - 1][:all_confirmations] + entry[:new_confirmations]
end
end
chart_data
end
end

View File

@ -23,6 +23,20 @@ class Conference < ActiveRecord::Base
future.first || last
end
def submissions_grouped_by_day
submissions = Event.where(track: tracks, created_at: created_at..start_date)
submissions = submissions.group('date(created_at)')
submissions = submissions.select('created_at, count(id) as number')
submissions.group_by { |s| s.created_at.to_date }
end
def submissions_grouped_by_confirmation_day
submissions = Event.approved.where(track: tracks, created_at: created_at..start_date).where.not(confirmed_at: nil)
submissions = submissions.group('date(confirmed_at)')
submissions = submissions.select('confirmed_at, count(id) as number')
submissions.group_by { |s| s.confirmed_at.to_date }
end
private
def close_all_other_calls_for_papers

View File

@ -69,3 +69,6 @@
span.pull-left = t 'views.conference.see_details'
span.pull-right = fa_icon 'arrow-circle-right'
span.clearfix
.row
.col-lg-12
.submissions-chart#submissions-chart data-submissions="#{submissions_chart_data(@conference).to_json}"