Skip to content

Commit

Permalink
Pull in and display EP gender stats on report page
Browse files Browse the repository at this point in the history
Display breakdown of gender overall for each conutries legislatures, by
term and overall by party.
  • Loading branch information
struan committed Jun 28, 2016
1 parent 5b4c466 commit 481554a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 126 deletions.
5 changes: 5 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'tilt/sass'
require 'active_support/core_ext'
require 'open-uri'
require 'json'
require 'csv'

$LOAD_PATH << File.expand_path('../lib', __FILE__)
Expand Down Expand Up @@ -169,6 +170,10 @@

get '/reports/:country' do
@country = Everypolitician.country(slug: params[:country])
stats_raw = JSON.parse(open('https://raw.githubusercontent.com/everypolitician/gender-balance-country-stats/gh-pages/stats.json').read, symbolize_names: true)
stats = Hash[stats_raw.map { |c| [c[:slug], c] }]
@country_stats = stats[params[:country]]
@legislature_stats = Hash[@country_stats[:legislatures].map {|l| [l[:slug], l]}]
erb :report, :layout => :layout_page
end

Expand Down
6 changes: 1 addition & 5 deletions views/country_partial.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<% if country.complete? %>
<a class="list__item country country--completed<% if country.played_by_user? %>-by-user<% end %>">
<% else %>
<a class="list__item country" href="<%= url "/countries/#{country.slug}" %>">
<% end %>
<a class="list__item country" href="<%= url "/reports/#{country.slug}" %>">

<h3 class="country__name"><%= country.name %></h3>

Expand Down
156 changes: 43 additions & 113 deletions views/report.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,156 +14,86 @@
</p>

<div class="report-legislatures">
<% @country.legislatures.each_with_index do |legislature, i|
stats = @legislature_stats[legislature.slug][:totals]
total = stats[:overall][:total].to_f
male = stats[:overall][:male].to_f
female = stats[:overall][:female].to_f
total = male + female
%>
<% if i % 2 == 0 %>
<div class="row">
<% end %>
<div class="col-sm-6">

<%# I would just include country_partial here, but it only works with @country objects %>
<a class="list__item country" href="#legislature1" data-scroll-to-id>
<h3 class="country__name">Galactic Senate</h3>
<a class="list__item country" href="#<%= legislature.slug %>" data-scroll-to-id>
<h3 class="country__name"><%= legislature.name %></h3>
<em class="country__status">Show details</em>
<div class="country__progress">
<p class="country__progress__intro">Known gender balance for Galactic Senate:</p>
<p class="country__progress__intro">Known gender balance for <%= legislature.name %>:</p>
<div class="progress-bar progress-bar--gendered progress-bar--labelled">
<div class="progress-bar__males" style="width: <%= 801 / 1015.0 * 100 %>%">
<span class="progress-bar__label">801 men</span>
<div class="progress-bar__males" style="width: <%= male / total * 100 %>%">
<span class="progress-bar__label"><%= male.to_i %> <%= male.to_i == 1 ? 'man' : 'men' %></span>
</div>
<div class="progress-bar__females" style="width: <%= (1015 - 801) / 1015.0 * 100 %>%">
<span class="progress-bar__label"><%= 1015 - 801 %> women</span>
</div>
</div>
</div>
</a>

</div>
<div class="col-sm-6">

<%# I would just include country_partial here, but it only works with @country objects %>
<a class="list__item country" href="#legislature2" data-scroll-to-id>
<h3 class="country__name">Jedi High Council</h3>
<em class="country__status">Show details</em>
<div class="country__progress">
<p class="country__progress__intro">Known gender balance for Jedi High Council:</p>
<div class="progress-bar progress-bar--gendered progress-bar--labelled">
<div class="progress-bar__males" style="width: <%= 8 / 12.0 * 100 %>%">
<span class="progress-bar__label">8 men</span>
</div>
<div class="progress-bar__females" style="width: <%= 4 / 12.0 * 100 %>%">
<span class="progress-bar__label">4 women</span>
<div class="progress-bar__females" style="width: <%= female / total * 100 %>%">
<span class="progress-bar__label"><%= female.to_i %> <%= female.to_i == 1 ? 'woman' : 'women' %></span>
</div>
</div>
</div>
</a>

</div>
<% if i % 2 != 0 %>
</div>
<% end %>
<% end %>
</div>
</div>
</div>

<div class="page-section page-section--white" id="legislature1">
<% @country.legislatures.each do |legislature| %>
<div class="page-section page-section--white" id="<%= legislature.slug %>">
<div class="container">

<h2 class="page-title">Galactic Senate</h2>
<h2 class="page-title"><%= legislature.name %></h2>

<div class="row">
<div class="col-sm-6">
<h3>Gender balance by term:</h3>
<div class="report-list report-list--by-term">
<%= erb :report_partial, locals: {
report: {
title: "41st Sitting",
total: 1015.0,
total_male: 801,
total_female: 1015 - 801,
action: 'display-by-group'
}
} %>
<%= erb :report_partial, locals: {
report: {
title: "40th Sitting",
total: 1015.0,
total_male: 766,
total_female: 1015 - 766,
action: 'display-by-group'
}
} %>
<%= erb :report_partial, locals: {
report: {
title: "39th Sitting",
total: 1015.0,
total_male: 332,
total_female: 171,
action: 'display-by-group'
}
} %>
<% legislature.legislative_periods.each do |term| %>
<% term_slug = 'term/' + term.slug
term_stats = @legislature_stats[legislature.slug][:terms][term_slug.to_sym] %>
<%= erb :report_partial, locals: {
report: {
title: term.name,
total: term_stats[:overall][:total].to_f,
total_male: term_stats[:overall][:male].to_f,
total_female: term_stats[:overall][:female].to_f,
action: 'display-by-group'
}
} %>
<% end %>
</div>
</div>
<div class="col-sm-6">
<h3>Gender balance by group:</h3>
<% stats = @legislature_stats[legislature.slug][:totals] %>
<div class="report-list report-list--by-group">
<% stats[:parties].each do |slug, data| %>
<%= erb :report_partial, locals: {
report: {
title: "Alliance of Free Planets",
total: 812.0,
total_male: 461,
total_female: 812 - 461,
action: 'display-by-term'
}
} %>
<%= erb :report_partial, locals: {
report: {
title: "Confederacy of Independent Systems",
total: 948.0,
total_male: 672,
total_female: 948 - 672,
title: data[:name],
total: data[:total].to_f,
total_male: data[:male].to_f,
total_female: data[:female].to_f,
action: 'display-by-term'
}
} %>
<%= erb :report_partial, locals: {
report: {
title: "Trade Federation",
total: 369.0,
total_male: 312,
total_female: 369 - 312,
action: 'display-by-term'
}
} %>
</div>
</div>
</div>
</div>
</div>

<div class="page-section page-section--white" id="legislature2">
<div class="container">

<h2 class="page-title">Jedi High Council</h2>

<div class="row">
<div class="col-sm-6">
<h3>Gender balance by term:</h3>
<div class="report-list report-list--by-term">
<%= erb :report_partial, locals: {
report: {
title: "44–40 BBY",
total: 12.0,
total_male: 8,
total_female: 4
}
} %>
</div>
<div class="report-blank-slate">
<p>We don’t yet have any historical data about this legislature.</p>
<p>Do you know where we can find the data? <a href="#">Contribute it, via EveryPolitician.</a></p>
</div>
</div>
<div class="col-sm-6">
<h3>Gender balance by group:</h3>
<div class="report-blank-slate">
<p>We don’t yet have any data about political groups in this legislature.</p>
<p>Do you know where we can find the data? <a href="#">Contribute it, via EveryPolitician.</a></p>
<% end %>
</div>
</div>
</div>
</div>
</div>
<% end %>
10 changes: 2 additions & 8 deletions views/report_partial.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@

<h3 class="report__title"><%= report[:title] %></h3>

<% if report[:action] == 'display-by-group' %>
<a class="report__action" data-display-by-group>Display by group</a>
<% elsif report[:action] == 'display-by-term' %>
<a class="report__action" data-display-by-term>Display by term</a>
<% end %>

<div class="progress-bar progress-bar--gendered progress-bar--labelled">
<div class="progress-bar__males" style="width: <%= report[:total_male] / report[:total] * 100 %>%">
<span class="progress-bar__label"><%= report[:total_male] %> men</span>
<span class="progress-bar__label"><%= report[:total_male].to_i %> <%= report[:total_male].to_i == 1 ? 'man' : 'men' %></span>
</div>
<% if (report[:total_male] + report[:total_female] != report[:total]) %>
<div class="progress-bar__empty" style="width: <%= (report[:total] - report[:total_male] - report[:total_female]) / report[:total] * 100 %>%">
</div>
<% end %>
<div class="progress-bar__females" style="width: <%= report[:total_female] / report[:total] * 100 %>%">
<span class="progress-bar__label"><%= report[:total_female] %> women</span>
<span class="progress-bar__label"><%= report[:total_female].to_i %> <%= report[:total_female].to_i == 1 ? 'woman' : 'women' %></span>
</div>
</div>

Expand Down

0 comments on commit 481554a

Please sign in to comment.