<commit_before>[![Build Status](https://travis-ci.org/rossettistone/inspector-gadget.svg?branch=master)](https://travis-ci.org/rossettistone/inspector-gadget)
[![Code Climate](https://codeclimate.com/github/rossettistone/inspector-gadget/badges/gpa.svg)](https://codeclimate.com/github/rossettistone/inspector-gadget)
[![Test Coverage](https://codeclimate.com/github/rossettistone/inspector-gadget/badges/coverage.svg)](https://codeclimate.com/github/rossettistone/inspector-gadget/coverage)

# Requirements
- [Docker](https://www.docker.com/products/overview) v1.12.1 (or higher)

# Getting Started

Copy the `B_Insp_Com.zip`, `B_Insp_Ele.zip`, and `B_Insp_Res.zip` GIS shapefiles provided by the City GIS team to the `/data/gis` directory before seeding or running the app for the first time.

Configure the web and database containers in **docker-compose.yml** and run:
```
$ docker-compose build
```

This will build all the necessary containers. You will also need to rebuild the container if you change the Gemfile of Gemfile.lock files.

Make sure you have the `db` image running with:
```
$ docker-compose -f docker-compose.yml -f docker-compose.dev.yml up db
```

Configure the databse settings by modifying **config/database.yml**. With the settings in place, create and setup the database:
```
$ docker-compose run web rake db:setup
```

Make sure eveything is working by running our tests:
```
$ docker-compose run web bundle exec rspec
```

Next, Follow the instructions from [Running the App](#running-the-app), [Perparing the Database](#preparing-the-database), and [Seeding](#seeding).

# Running the App

- You can serve the app (in development mode) by running: `docker-compose -f docker-compose.yml -f docker-compose.dev.yml up`
- You can interact with a rails console by running: `docker-compose run web rails console`
- In order to interact with the application in development, you will need to create a test user. You can achieve this by running `User.create!({:email => "<EMAIL>", :password => "<PASSWORD>", :password_confirmation => "<PASSWORD>" })` on the rails console.

## Preparing the Database

`postgres 9.5`
`postgis 2.2.x`

The City of Long Beach uses a "state plane" coordinate projection system by default for most of its GIS data. This application needs to ingest city-created GIS data, but postgis does not include this particular projection by default. It is readily available for import from spatialreference.org at http://spatialreference.org/ref/esri/102645/.

First, spin up the DB docker image:
```
$ docker-compose up db
```

Next, access the command line of the Inspector Gadget DB docker image:
```
$ docker exec -it inspectorgadget_db_1 /bin/bash
```

Switch to the `postgres` user:
```
$ su postgres
```

Next, run the following query directly against the database via `psql` to insert the projection information:
```sql
INSERT into spatial_ref_sys (srid, auth_name, auth_srid, proj4text, srtext) values ( 102645, 'esri', 102645, '+proj=lcc +lat_1=34.03333333333333 +lat_2=35.46666666666667 +lat_0=33.5 +lon_0=-118 +x_0=2000000 +y_0=500000.0000000002 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs ', 'PROJCS["NAD_1983_StatePlane_California_V_FIPS_0405_Feet",GEOGCS["GCS_North_American_1983",DATUM["North_American_Datum_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["False_Easting",6561666.666666666],PARAMETER["False_Northing",1640416.666666667],PARAMETER["Central_Meridian",-118],PARAMETER["Standard_Parallel_1",34.03333333333333],PARAMETER["Standard_Parallel_2",35.46666666666667],PARAMETER["Latitude_Of_Origin",33.5],UNIT["Foot_US",0.30480060960121924],AUTHORITY["EPSG","102645"]]');
```

Note that the above query has one small change from the query available on spatialreference.org: it removes a preceding "9" from the SRID `9102645` to make it `102645`. It seems as though the 9 was a remnant of darker times. This change was gleaned from this [Stack Exchange post](http://gis.stackexchange.com/questions/69864/postgis-is-rejecting-an-srid-code-for-my-projection-ive-found-a-nearly-identic).

## Seeding

While the `db` image is running, populate the database with seeds via rake:

1. `docker-compose run web bundle exec rake db:seed:inspectors`
1. `docker-compose run web bundle exec rake db:seed:inspection_types`
1. `docker-compose run web bundle exec rake import:inspector_regions`

# Architecture Overview

## How Inspections are Assigned to Inspectors
<commit_msg>Updated README with the proper commands to seed, test, and run this containerized app<commit_after>[![Build Status](https://travis-ci.org/rossettistone/inspector-gadget.svg?branch=master)](https://travis-ci.org/rossettistone/inspector-gadget)
[![Code Climate](https://codeclimate.com/github/rossettistone/inspector-gadget/badges/gpa.svg)](https://codeclimate.com/github/rossettistone/inspector-gadget)
[![Test Coverage](https://codeclimate.com/github/rossettistone/inspector-gadget/badges/coverage.svg)](https://codeclimate.com/github/rossettistone/inspector-gadget/coverage)

# Requirements
- [Docker](https://www.docker.com/products/overview) v1.12.1 (or higher)

# Getting Started

Make sure to copy the `B_Insp_Com.zip`, `B_Insp_Ele.zip`, and `B_Insp_Res.zip` GIS shapefiles provided by the City GIS team to the `/data/gis` directory before running the app for the first time.

Configure the web and database containers in **docker-compose.yml** and run:
```
$ docker-compose build
```

This will build all the necessary containers. **Please note that you will also need to rebuild the container if you change the Gemfile of Gemfile.lock files.**

Next, follow the instructions from the [Perparing the Database](#preparing-the-database) and [Seeding](#seeding) sections.

## Preparing the Database

`postgres 9.5`
`postgis 2.2.x`

The City of Long Beach uses a "state plane" coordinate projection system by default for most of its GIS data. This application needs to ingest city-created GIS data, but postgis does not include this particular projection by default. It is readily available for import from spatialreference.org at http://spatialreference.org/ref/esri/102645/.

First, spin up the DB docker image:
```
$ docker-compose -f docker-compose.yml -f docker-compose.dev.yml up db
```

Configure the databse settings by modifying `config/database.yml`. With the settings in place, create and setup the database:
```
$ docker-compose -f docker-compose.yml -f docker-compose.dev.yml run web rake db:setup
```

Next, access the command line of the Inspector Gadget DB docker image:
```
$ docker exec -it inspectorgadget_db_1 /bin/bash
```

Switch to the `postgres` user:
```
$ su postgres
```

Next, run the following query directly against the database via `psql` to insert the projection information:

```bash
$ psql
$ \connect inspector_gadget_development
```

```sql
INSERT into spatial_ref_sys (srid, auth_name, auth_srid, proj4text, srtext) values ( 102645, 'esri', 102645, '+proj=lcc +lat_1=34.03333333333333 +lat_2=35.46666666666667 +lat_0=33.5 +lon_0=-118 +x_0=2000000 +y_0=500000.0000000002 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs ', 'PROJCS["NAD_1983_StatePlane_California_V_FIPS_0405_Feet",GEOGCS["GCS_North_American_1983",DATUM["North_American_Datum_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["False_Easting",6561666.666666666],PARAMETER["False_Northing",1640416.666666667],PARAMETER["Central_Meridian",-118],PARAMETER["Standard_Parallel_1",34.03333333333333],PARAMETER["Standard_Parallel_2",35.46666666666667],PARAMETER["Latitude_Of_Origin",33.5],UNIT["Foot_US",0.30480060960121924],AUTHORITY["EPSG","102645"]]');
```

Note that the above query has one small change from the query available on spatialreference.org: it removes a preceding "9" from the SRID `9102645` to make it `102645`. It seems as though the 9 was a remnant of darker times. This change was gleaned from this [Stack Exchange post](http://gis.stackexchange.com/questions/69864/postgis-is-rejecting-an-srid-code-for-my-projection-ive-found-a-nearly-identic).

Repeat the above step for the `inspector_gadget_test` database. After running the above DDL INSERT statement, be sure to exit out of the postgres and container shells respectively.

## Seeding

While the `db` image is running, populate the database with seeds via rake:

1. `docker-compose -f docker-compose.yml -f docker-compose.dev.yml run web bundle exec rake db:seed:inspectors`
1. `docker-compose -f docker-compose.yml -f docker-compose.dev.yml run web bundle exec rake db:seed:inspection_types`
1. `docker-compose -f docker-compose.yml -f docker-compose.dev.yml run web bundle exec rake import:inspector_regions`

## Testing

Make sure eveything is working by running our tests:
```
$ docker-compose -f docker-compose.yml -f docker-compose.dev.yml run web bundle exec rspec
```

# Running the App

- You can serve the app (in development mode) by running: `docker-compose -f docker-compose.yml -f docker-compose.dev.yml up`
- You can interact with a rails console by running: `docker-compose run web rails console`
- In order to interact with the application in development, you will need to create a test user. For example, you can achieve this by running something like `User.create!({:email => "<EMAIL>", :password => "<PASSWORD>", :password_confirmation => "<PASSWORD>" })` on the rails console to create your test user.

# Architecture Overview

## How Inspections are Assigned to Inspectors

{'fraction_non_alphanumeric': 0.11461139896373057, 'fraction_numerical': 0.061139896373056994, 'mean_word_length': 5.734822051639917, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 14, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 14, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1285047', 'n_tokens_mistral': 3630, 'n_tokens_neox': 3093, 'n_words': 931}