Merge pull request #173 from ChrisBr/new_dashboard

Implements event submissions over time chart
This commit is contained in:
Christian Bruckmayer 2014-05-30 10:23:23 +02:00
commit fa129de063
12 changed files with 215 additions and 9 deletions

View file

@ -7,4 +7,20 @@ class CallForPapers < ActiveRecord::Base
validates_presence_of :start_date, :end_date, :hard_deadline
validates :rating, :numericality => { :greater_than_or_equal_to => 0, :less_than_or_equal_to => 10 }
def self.max_weeks
all = CallForPapers.all
result = [0]
all.each do |cfp|
result.push(cfp.end_week - cfp.start_week)
end
result.max
end
def start_week
start_date.strftime('%W').to_i
end
def end_week
end_date.strftime('%W').to_i
end
end

View file

@ -124,6 +124,43 @@ class Conference < ActiveRecord::Base
return false
end
##
# Returns an array with the summarized event submissions per week.
# ====Params:
# * +weeks+ -> Integer with number of weeks. This is necessary to compare conferences.
#
# ====Returns
# * +Array+ -> e.g. [0, 3, 3, 5] -> first week 0 events, second week 3 events.
def get_submissions_per_week(weeks)
result = []
if call_for_papers && events
submissions = events.select('id, created_at').group_by { |t| t.week }
start_week = call_for_papers.start_week
sum = 0
(0..weeks - 1).each do |week|
if submissions["#{week + start_week}"]
sum += submissions["#{week + start_week}"].length
end
result.push(sum)
end
else
result = Array.new(weeks, 0)
end
result
end
##
# Checks if the conference is pending.
#
# ====Returns
# * +false+ -> If the conference start date is in the past.
# * +true+ -> If the conference start date is in the future.
def pending?
start_date > Date.today
end
private
##

View file

@ -174,6 +174,10 @@ class Event < ActiveRecord::Base
end
end
def week
created_at.strftime('%W')
end
private
def abstract_limit