• Stars
    star
    137
  • Rank 266,121 (Top 6 %)
  • Language
    Ruby
  • License
    Other
  • Created over 11 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Making parliamentary voting information accessible, understandable, and easy to use so that you can hold your elected representatives to account.

They Vote For You Build Status Code Climate Test Coverage

Introduction

In our democracy the definitive exercise of the power we give our politicians when we vote them into office is how they vote in our parliaments on our behalf. Yet you probably don't know how your MP votes. This isn't your fault.

Parliamentary voting information is notoriously difficult to find and analyse. This project changes that by making it understandable and easy to use.

Over 10 years ago the pioneering Public Whip project was created in the UK. This is an evolution of that original PHP application into a modern Rails application.

Process overview

Australia

The OpenAustralia.org project parses the Australian Federal Hansard into ParlParse format (this due to it's history of being a fork of the UK TheyWorkForYou project). The debates XML files the parser creates, also available on data.openaustralia.org, contain voting data and we load this into a Rails application.

UK

The UK Public Whip site still operates from the original PHP codebase however it's very possible for it to be upgraded to Rails in the future. During the development of They Vote For You, the OpenAustralia Foundation was careful to ensure there is an upgrade path.

To upgrade, checkout the php-compatibility branch and point the Rails application at a copy of the UK production database. Test the site out and fix any bugs - there are likely to be some UK-specific additions needed to the Rails application.

Once the site is working you can then checkout a more recent version of the codebase and run rake db:migrate to upgrade the database schema. This also is likely to need some UK-specific changes.

The final step is to customise the site language and interface. The best way to achieve this would be to develop some sort of theming system.

Ukraine

People data is collected by a morph.io scraper and fed into EveryPolitician. This produces Popolo formatted data that is then loaded into TVFY using a Rake task, e.g.:

bundle exec rake application:load:popolo[https://raw.githubusercontent.com/everypolitician/everypolitician-data/master/data/Ukraine/Verkhovna_Rada/ep-popolo-v1.0.json]

Once the people data has been loaded you can start loading votes. These are scraped by another morph.io scraper, that saves data in a flat format that can easily be converted to Popolo. The conversion is handled by a small proxy application and the results are imported using another Rake task, e.g.:

bundle exec rake application:load:popolo[https://arcane-mountain-8284.herokuapp.com/vote_events/2015-07-14]

Development

If your machine is already set up to develop Rails applications with MySQL just carry out the following steps and you should be good to go.

Developing with Vagrant is also possible (see below) but was mainly useful with the retired PHP application. A new Vagrant setup can be found in the OpenAustralia/Infrastructure repository, however this is primarily intended as a "production-like" test environment rather than providing a development environment.

Before beginning, install MySQL, HTMLTidy and Ruby:

# OS X ...
brew install tidy-html5 mysql rbenv ruby-build
rbenv install $(cat .ruby-version)

# ... or Linux (Debian)
sudo apt-get install tidy mysql-server mysql-client libmysqlclient-dev
# then follow: https://github.com/sstephenson/rbenv#basic-github-checkout to get rbenv and ruby-build

Steps required to configure, install and start the Rails application:

# Install bundle
bundle install

# Install mailcatcher
gem install mailcatcher

# Copy the default config files over.
cp config/database.yml.example config/database.yml

# (Edit config/database.yml and fill in your username, password and database settings.)
bundle exec rake application:config:dev

# Copy secrets config
cp config/secrets.yml.example config/secrets.yml

# Set up your database (including seed data)
bundle exec rake db:setup

# Run tests
bundle exec rake

# Start the server
bundle exec rails server

With Vagrant

Once you have vagrant and virtualbox installed and have cloned this repository run vagrant up. This will download the base virtualbox image and set up the development environment, be prepared for a bit of a wait.

Run the tests from inside the VM like this:

  • vagrant ssh
  • cd /vagrant
  • bundle exec rake

Assuming they pass, you can start the rails server:

  • bundle exec rails server

Once it is up you can browse to http://localhost:3000

When manually testing the site, the "sign up" confirmation emails will automatically go to a dummy smtp server called mailcatcher. To check the emails, browse to http://localhost:1080

If vagrant reports that it can't mount the /vagrant virtualbox shared folder, it's becuase the VM has had it's kernel updated. Run vagrant provision && vagrant reload and you should be back in business.

The original PHP app is also available at http://localhost:8080 but only if you're running an older branch (out of scope for this guide).

Loading data

Australia

These rake tasks are the ones you're most likely to need to run. You can run them as the deploy user in /srv/www/production/current, for instance:

deploy@ip-172-31-37-36:/srv/www/production/current$ RAILS_ENV=production bundle exec rake application:load:divisions[2018-10-18]
  • application:load:members loads members, offices and electorates. You always need this to run the site. Strictly speaking it only needs to run when details need updating but can be run as often as you like as it only updates data.
  • application:load:divisions[from_date,to_date] load division[s]. to_date is optional and if omitted, allows you to load a single date.
  • application:cache this namespace contains cache updating tasks that are necessary for the site to run. They should be self-explanatory.

Daily updates are carried out by the application:load:daily Rake task, which is run daily at 09:15 by cron.

Popolo

Countries that use Popolo, e.g. Ukraine, only need to know about the application:load:popolo Rake task. It will load people or country data, depending on what it finds in the file.

Search

Search requires elasticsearch. You will need to download the .deb for Linux or on Mac run brew install elasticsearch.

Add data to your index the first time with bundle exec rake searchkick:reindex:all and Searchkick should take care of updates from there.

Production

Extra Requirements

  • Memcached

Australia

Deployment

The code is deployed using Capistrano. To deploy to production run:

bundle exec cap production deploy

Ukraine

Server provisioning

Ukraine's server has its configuration management in another repository. Once you've run the server provisioning tasks you can follow the instructions below to deploy the application.

Deployment

After provisioning your development server, set up and deploy using Mina:

bundle exec mina ukraine_dev setup
bundle exec mina ukraine_dev deploy

# Now you can load people data
bundle exec mina ukraine_dev rake[application:load:popolo[https://raw.githubusercontent.com/everypolitician/everypolitician-data/master/data/Ukraine/Verkhovna_Rada/ep-popolo-v1.0.json]]

# And some vote data
bundle exec mina ukraine_dev rake[application:load:popolo[https://arcane-mountain-8284.herokuapp.com/vote_events/2015-07-14]]

# Setup caches
bundle exec mina ukraine_dev rake[application:cache:all_except_people_distances]

# Then build the index so search works
bundle exec mina ukraine_dev rake[searchkick:reindex:all]

To deploy to the production server, replace ukraine_dev with ukraine_production in the above commands.

Accessing the admin panel

The administration panel, which currently doesn't do a whole lot, can be accessed in development at http://localhost:3000/admin/ and in production at https://theyvoteforyou.org.au/admin. You must be an admin to be able to access that page. Any user that is an admin can make another user and admin too using the admin panel. The first admin user must be created via the rails console:

$ bundle exec rails c
irb> User.find_by(email: "[email protected]").update(admin: true)

Obviously substitute the email address in the command above.

Feature flags

Some features that are still in development are enabled via "feature flags". The features can optionally switched on for certain users, block of users or everyone. These flags are administered at https://theyvoteforyou.org.au/admin/flipper/features in production or http://localhost:3000/admin/flipper/features when in development.

The names of the features added in the admin panel need to match those in the code at config/initializers/flipper.rb.

To enable a feature for a particular user: Go to the feature on the flipper admin panel. Then click the button "Add an actor". Then add the flipper_id which for a user will be of the form User;<user id>. So for example it could be User;3.

Other Credits

This project uses some icons from the noun project under under creative commons licenses:

More Repositories

1

morph

Take the hassle out of web scraping
Ruby
461
star
2

planningalerts

Find out and have your say about what's being built and knocked down in your area.
Ruby
95
star
3

openaustralia-parser

Parser component for OpenAustralia.org
Ruby
28
star
4

openaustralia

Looking for the front-end or parser? See the README. Looking for issues? You're in the right repo.
Ruby
23
star
5

electionleaflets

Live election leaflet monitoring for Australia.
PHP
18
star
6

twfy

Web Application component for Open Australia (twfy module)
PHP
16
star
7

morph-cli

Commandline interface for morph
Ruby
9
star
8

planningalerts-parsers

[Phased out] PlanningAlerts scrapers
Ruby
8
star
9

infrastructure

Automated setup and configuration for most of OpenAustralia Foundation's servers
HCL
8
star
10

yinyo

A wonderfully simple API driven service to reliably execute many long running scrapers in a super scaleable way
Go
6
star
11

australian_local_councillors_popolo

Popolo data for Local Councillors in Australia
Ruby
6
star
12

newsletter

This was a monthly newsletter by the OpenAustralia Foundation for people who love civic tech (Feb 2015-Nov 2015).
5
star
13

mapit-australia-docker

Dockerized Mapit with Australian data
Shell
5
star
14

oaf

OpenAustralia Foundation
4
star
15

alaveteli_versions

Scrapes details of every public Alaveteli deployment
Ruby
3
star
16

mapit-docker

Dockerized MapIt
Shell
3
star
17

example_ruby_chrome_headless_scraper

Example scraper showing how to use Chrome headless from a ruby scraper
Ruby
3
star
18

morph-docker-base

Base docker image for all images on Morph
Shell
2
star
19

rblib

Web Application component for Open Australia (rblib module)
Ruby
2
star
20

openaustralia-chef

RETIRED. Was: Chef recipes used for configuring openaustralia.org's server
Ruby
2
star
21

morph_popolo

A little Sinatra app to output Popolo data from the morph.io API.
Ruby
2
star
22

morph-docker-python

Docker image for running Python scrapers in Morph
Shell
2
star
23

morph-docker-php

Docker image to run php scrapers in Morph
Shell
2
star
24

scraperwiki-morph

ScraperWiki / Morph compatibility layer
Ruby
2
star
25

example_ruby_phantomjs_scraper

Ruby
1
star
26

sa_lg_councillors

South Australian Councillors
Ruby
1
star
27

homebrew-yinyo

Ruby
1
star
28

morph-docker-ruby

Docker image for running Ruby scrapers in Morph
Ruby
1
star
29

right_to_know_requests

Data about requests on Right To Know for analysis
Ruby
1
star
30

morph-docker-buildstep-base

Base docker image for all buildstep based images on Morph
1
star
31

planningalerts_xml_data_feed

Fetches bulk data from the PlanningAlerts API and converts it to XML for use in your legacy systems.
Ruby
1
star
32

perllib

Web Application component for Open Australia (perllib module)
Perl
1
star
33

ukraine_verkhovna_rada_deputies

Members of the Ukrainian parliament, the Verkhovna Rada of Ukraine
Ruby
1
star
34

phplib

Web Application component for Open Australia (phplib module)
PHP
1
star
35

australian_local_councillors_images

Stores a copy of Australian local councillor images from Popolo on S3. Runs on morph.io
Ruby
1
star
36

jacaranda

a watchful tree and slack messenger to keep you informed of the use of your civic tech projects, like PlanningAlerts and Right To Know
Ruby
1
star
37

publicwhip-matthew

Fork of UK code that runs www.publicwhip.org.uk for tracking parliamentary voting information
PHP
1
star
38

jacaranda-righttoknow

a watchful tree and slack messenger to keep you informed of the use of Right To Know
Ruby
1
star
39

members_of_parliament_queensland_australia

A list of current Members of the Parliament of Queensland, Australia
Ruby
1
star
40

vic_lg_directory_councillors

Names of councillors for Victorian councils
Ruby
1
star
41

shlib

Web Application component for Open Australia (shlib module)
1
star
42

all_alaveteli_requests

Get all the requests on an Alaveteli site and put them in a single gigantic pdf
Ruby
1
star
43

nsw_greens_councillors_contact_details

Contact details of local councillors in NSW that are members of the Green party scraped from the NSW Greens website
Ruby
1
star
44

ukraine_verkhovna_rada_votes

Votes by deputies in the Ukrainian Parliament
Ruby
1
star