MinnPost / legislature-tracker

An application that pulls in Open States data and combines with editorial expertise to create a live view into a state legislature session.
http://minnpost.github.io/legislature-tracker/
Other
30 stars 17 forks source link

State Legislature/Bill Tracker

Using editorial expertise and the Sunlight Lab's Open States API, this application creates a curated view of what is going on in a state's legislature session.

It combines data from Open States and editorial data collected with Google Docs. You can see some examples at minnpost.github.io/legislature-tracker.

Examples out in the wild

Installation and configuration

This is a frontend application. It is meant to be used as a library; it is not suggested that you fork this repository unless you need to fix a bug or alter the code. It is recommended that you install the code with Bower:

bower install legislature-tracker

Include the relevant .js and .css files found in the dist folder in your HTML page. The .libs.js is included for convenience but you can include the dependencies from the bower folder as well. The application also supports module loading with RequireJS, AMD, or Browserify.

Initialize the tracker with the following:

var app = new LT({
  el: '.container-for-leg-tracker',
  OSKey: 'open-states-key-here',
  eKey: 'google-spreadsheet-key-here',
  state: 'MN',
  session: '2013-2014',
  // more options see below ...
});

Options

When creating a new Legislature Tracker object, you can set the following options. All default options are in js/app.js.

Required options

The following are required for the application to work correctly

Common options

The following are common options you may want to override.

Hook options

These are functions that are called during processing to allow for you to override data and other functionality. Do note that if you alter certain data, you may break things.

osBillParse: A function that is called when parsing open states bill data. It passes the data at the pointer after it has been fetched from Open States and after the model parsing, but before it is loaded into the model. For, instance, this adds text names to sources:

osBillParse: function(billData, app) {
  billData.sources = _.map(billData.sources, function(s, si) {
    s.text = 'SOURCE [' + si + ']';
    return s;
  });
  return billData;
},

Label translations

To override the naming of certain things, like labels, you can update the the translations config object. The wordTranslations is just another options; the following are the defaults:

wordTranslations: {
  chamber: {
    'upper': 'Senate',
    'lower': 'House'
  },
  partyAbbr: {
    'Democratic-Farmer-Labor': 'DFL',
    'Democratic': 'D',
    'Republican': 'R'
  },
  sponsors: {
    'Primary sponsors': 'Primary sponsors',
    'primary sponsors': 'primary sponsors',
    'Primary sponsor': 'Primary sponsor',
    'primary sponsor': 'primary sponsor',
    'Co-sponsors': 'Co-sponsors',
    'co-sponsors': 'co-sponsors',
    'Co-sponsor': 'Co-sponsor',
    'co-sponsor': 'co-sponsor'
  }
},

Advanced options

These options are set the same as basic options, but their default setting will work fine for most users.

Google spreadsheets setup

The name and letter case of the columns and worksheets are important. See this spreadsheet for an example. There are options to change the column name mapping, but this is not well supported yet.

First make sure you have 3 sheets with the following columns:

Link field formatting

There are a few fields that are a list of links. You should use this format so that they are parsed correctly. Do note that the parser is pretty rudimentary so don't expect much.

"Link text title|http://www.example.com/123", "Another link text title|http://www.example.com/154"

Changing the look

All styling is provided with CSS. The CSS with the application is a bit specific, so be sure to know how CSS specificity works. If you must, you can override the output as well.

Overriding templates

You can override the HTML templates that are used in the application and change wording as well as any HTML output. Templates are using Ractive. You can see the current templates in the js/templates/ directory. The templates are managed in the LT.LT.templates object. It is suggested to copy the template and then make alterations from there. For instance:

LT.templates['template-ebill'] = 'Your template content here';

How does your legislature work?

The Open States data is very good structured data about bills, but it is basic data that does not account for the subtleties of how legislatures work.

The Legislature tracker tries to take these subtleties into account, but may not be good enough for your legislature. Please open an issue in the queue to discuss how to address other use cases. This is currently handling the following:

Development

Prerequisites

All commands are assumed to be on the command line, often called the Terminal, unless otherwise noted. The following will install technologies needed for the other steps and will only needed to be run once on your computer so there is a good chance you already have these technologies on your computer.

  1. Install Git.
    • On a Mac, install Homebrew, then do: brew install git
  2. Install NodeJS.
    • On a Mac, do: brew install node
  3. Install Grunt: npm install -g grunt-cli
  4. Install Bower: npm install -g bower
  5. Install Ruby, though it is probably already installed on your system.
  6. Install Bundler: gem install bundler
  7. Install Sass: gem install sass
    • On a Mac do: sudo gem install sass
  8. Install Compass: gem install compass
    • On a Mac do: sudo gem install compass

Get code and install packages

Get the code for this project and install the necessary dependency libraries and packages.

  1. Check out this code with Git: git clone https://github.com/MinnPost/legislature-tracker.git
  2. Go into the code directory: cd legislature-tracker
  3. Install NodeJS packages: npm install
  4. Install Bower components: bower install

Running

  1. Run: grunt server
    • This will run a local webserver for development and you can view the application in your web browser at http://localhost:8136.
    • Utilize examples/example.html for development, while examples/example-dev.html is used for the deployed version, and index-build.html is used to test the build before deployment.
    • The server runs grunt watch which will watch for linting JS files and compiling SASS. If you have your own webserver, feel free to use that with just this command.

Building

Built versions will only be regularly committed for tagged releases.

  1. Uses grunt which depends on Node. To install: npm install -g grunt-cli && npm install
  2. (for specific version) Update version in: package.json
  3. Run: grunt
  4. (for specific version) Tag release with appropriate version: git tag 0.1.1

Architecture

The basic idea of the application is pulling together editorial knowledge about bills and combining it with Open States data about the bills to create a focused and useful interface to keep track of the important activities of a legislature session.

OS prefixes refer to Open States data, while E or e prefixes refer to editorial data and objects.

Each editorial (or meta) bill refers to one or more Open States (or actual) bill.

Cross-browser compatibility

The goal of this project is to be compatible with all major modern browsers including IE8.

Caching

To ensure that both memory and network usage is minimized, there is some basic caching happening.

For model instances, we wrap the creation of models in the following method:

LT.getModel('ModelName', 'identifying_attribute', attributes)

For fetching models we wrap fetchings so that it only happens once:

LT.fetchModel(model));
// Returns a jQuery promise object

Google Spreadsheets

This application uses Tabletop.js to read in data from Google Spreadsheets. Due to the fact that Google does not guarantee up time or ability to handle requests, it is good practice to cache the outputs for production. Tabletop has some recent additions to handle proxy via saving the outputs to a place like S3, as well as more traditional proxy like gs-proxy. Use the tabletopOptions option to set any of the tabletop options.

Attribution

About Us

MinnData, the MinnPost data team, is Alan, Tom, and Kaeti and all the awesome contributors to open source projects we utilize. See our work at minnpost.com/data.


                                                   .--.
                                                   `.  \
                                                     \  \
                                                      .  \
                                                      :   .
                                                      |    .
                                                      |    :
                                                      |    |
      ..._  ___                                       |    |
     `."".`''''""--..___                              |    |
     ,-\  \             ""-...__         _____________/    |
     / ` " '                    `""""""""                  .
     \                                                      L
     (>                                                      \
    /                                                         \
    \_    ___..---.                                            L
      `--'         '.                                           \
                     .                                           \_
                    _/`.                                           `.._
                 .'     -.                                             `.
                /     __.-Y     /''''''-...___,...--------.._            |
               /   _."    |    /                ' .      \   '---..._    |
              /   /      /    /                _,. '    ,/           |   |
              \_,'     _.'   /              /''     _,-'            _|   |
                      '     /               `-----''               /     |
                      `...-'                                       `...-'