Recidiviz / justice-counts-components

A set of React components powering a web app for exploring centralized, standardized metrics on the performance of justice systems across the United States
GNU General Public License v3.0
1 stars 0 forks source link

Justice Counts - React Components

Build Status

Coverage Status

A set of React components powering a web app for exploring centralized, standardized metrics on the performance of justice systems across the United States

Contents

  1. Development
  2. Input Data Format

Development

Getting set up

  1. Grab the source:

    git clone git@github.com:Recidiviz/justice-counts-components.git

  2. Install Yarn package manager:

    brew install yarn

    For alternative Yarn installation options, see Yarn Installation.

  3. Install dependencies:

    yarn install

That's it! We suggest installing a linting package for your preferred code editor that hooks into eslint, such as linter-eslint for Atom.

Testing and linting

To run tests wired up through react-scripts:

yarn test --coverage

Running tests this way will also write code coverage statistics to stdout and the coverage directory, which are reported to Coveralls.

To run linting:

yarn lint

Linting is done with a combination of eslint and Prettier. react-scripts runs some minimal linting by default as part of its build process; errors on those linting rules would cause build scripts to fail, but errors in the broader configuration should not.

To have eslint and Prettier fix violations automatically, run:

yarn lint --fix

Running the app locally

A yarn script is available for starting the development server. The entire app is a React frontend that is served out of port 3000. This will also automatically open a browser to localhost on the appropriate port, pointing to the frontend.

yarn start

The development server will remain active until you either close your terminal or shut down the entire setup at once using CTRL+c.

Creating a build

To generate a build of the frontend that is suitable for deploys, run: yarn build.

Each time this is run, the /build directory will be wiped clean.

Input Data Format

The main app component should receive a number of required properties. This includes the stateCode to visualize data for, in a format of US_XX, e.g. US_CO or US_PA. It also includes several collections of data points.

These include (state-level) corrections metrics, in both annual and monthly forms, (county-level) jails metrics, and static data providing the list of counties in a given state. These collections of data should live in different flat files under /src/data. They can be moved around trivially, or pulled instead from a CDN or an API, for different deployment styles. Example versions of all of these files are currently inside of the repository, but they should be replaced for live use cases.

The following sub-sections define these data collections.

Corrections (Monthly)

Found in /src/data/corrections_monthly.json.

Read into App.js where it is provided correctionsMonthlyData, this file contains an array of metric data points.

The file is in JSON Lines format, with different json objects separated by newlines. Each object contains a data point corresponding to a metric aggregated at the monthly level, matching the spec below:

Corrections (Annual)

Found in /src/data/corrections_annual.json.

Read into App.js where it is provided as correctionsAnnualData, this file contains an array of metric data points.

The file is in JSON Lines format, with different json objects separated by newlines. Each object contains a data point aggregated at the annual level. The spec is identical to the above spec for monthly-aggregated corrections data.

The difference is in how the metrics are prepared on the backend:

Jails

Found in /src/data/jails_data.json.

Read into App.js where it is provided as jailsData, this file contains an array of metric data points.

The file is in JSON Lines format, with different json objects separated by newlines. Each object contains a data point corresponding to a metric matching the spec below:

Counties

Found in /src/data/counties_data.json.

Read into App.js where it is provided as countiesData, this file contains an array of objects.

The file is in JSON Lines format, with different json objects separated by newlines. Each object represents a particular county in the United States, across all states, matching the spec below: