Commit 997e5764 authored by Daniel Mack's avatar Daniel Mack Committed by Mario Manno

statistics: add gender breakdown

Join events of a conference with persons involved, and group the resulting
data set by gender. Use that to provide a json array which can in turn be
used by the jQuery plot module.

The breakdown is limited to moderators or speakers of an event, and to
events that are public.

Display a plot on the home screen of a conference.
parent c8f10ee9
......@@ -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?
......
......@@ -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