Commit 3bd62f93 authored by Mario Manno's avatar Mario Manno

Merge branch 'zonque-gender'

parents c8f10ee9 3d47218e
......@@ -31,4 +31,13 @@ class StatisticsController < ApplicationController
end
end
def gender_breakdown
authorize! :read, @conference
result = @conference.gender_breakdown(params[:accepted_only])
respond_to do |format|
format.json { render json: result.to_json }
end
end
end
......@@ -118,6 +118,25 @@ class Conference < ActiveRecord::Base
result
end
def gender_breakdown(accepted_only = false)
result = Array.new
ep = Person.joins(events: :conference)
.where(:"conferences.id" => self.id)
.where(:"event_people.event_role" => ["speaker", "moderator"])
.where(:"events.public" => true)
if accepted_only
ep = ep.where(:"events.state" => "confirmed")
end
ep.group(:gender).count.each do |k,v|
k = "unknown" if k.nil?
result << { label: k, data: v }
end
result
end
def language_codes
codes = self.languages.map{|l| l.code.downcase}
codes = %w{en} if codes.empty?
......
class Person < ActiveRecord::Base
GENDERS = %w{male female}
GENDERS = %w{male female other}
has_many :availabilities, dependent: :destroy
has_many :event_people, dependent: :destroy
......@@ -19,6 +19,8 @@ class Person < ActiveRecord::Base
belongs_to :user, dependent: :destroy
before_save :nilify_empty
acts_as_indexed fields: [:first_name, :last_name, :public_name, :email, :abstract, :description, :user_email]
has_paper_trail
......@@ -170,4 +172,8 @@ class Person < ActiveRecord::Base
self.event_people.select { |ep| ep.event.conference == conference }.select { |ep| ['speaker', 'moderator'].include? ep.event_role }
end
def nilify_empty
self.gender = nil if self.gender and self.gender.empty?
end
end
......@@ -91,6 +91,14 @@
= link_to "Accepted only", "#", :id => "languages_accepted_events_only"
#event_language_graph(style="width:400px;height:300px;")
- if @conference.gender_breakdown.count > 1
%h4 Events by gender
%p
= link_to "All", "#", :id => "gender_all_events"
|
= link_to "Accepted only", "#", :id => "gender_accepted_events_only"
#event_gender_graph(style="width:400px;height:300px;")
:coffeescript
update_languages_breakdown = (accepted_only = false) ->
if accepted_only
......@@ -106,6 +114,20 @@
$.plot($("#event_language_graph"), data, {series: {pie: {show: true}}})
)
update_gender_breakdown = (accepted_only = false) ->
if accepted_only
params = {"accepted_only": 1}
else
params = {}
$.ajax(
url: "#{gender_breakdown_statistics_path}",
type: "GET",
dataType: "json",
data: params,
success: (data) ->
$.plot($("#event_gender_graph"), data, {series: {pie: {show: true}}})
)
update_events_breakdown = (type = "") ->
if type
params = {"type": type}
......@@ -146,3 +168,11 @@
event.preventDefault()
update_languages_breakdown()
$("#gender_all_events").click (event) ->
update_gender_breakdown()
event.preventDefault()
$("#gender_accepted_events_only").click (event) ->
update_gender_breakdown(true)
event.preventDefault()
update_gender_breakdown()
......@@ -74,6 +74,7 @@ Frab::Application.routes.draw do
match "/statistics/events_by_state" => "statistics#events_by_state", as: "events_by_state_statistics"
match "/statistics/language_breakdown" => "statistics#language_breakdown", as: "language_breakdown_statistics"
match "/statistics/gender_breakdown" => "statistics#gender_breakdown", as: "gender_breakdown_statistics"
resource :conference, except: [:new, :create] do
get :edit_tracks
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment