Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
jbradberry committed Mar 19, 2018
2 parents ab8d96f + 8dde964 commit 77c633b
Show file tree
Hide file tree
Showing 59 changed files with 10,089 additions and 1,314 deletions.
12 changes: 9 additions & 3 deletions conf/pillar/devs.sls
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ users:
djyoung:
public_key:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDd+HZPZFY4cs7xeuJQXd5XLoeMLpQSLvX7pVOAlXrxiCrk1HxyWfuE6lDy8gjmJffde31SfhIvngwyoA2bQ5ufYT7ronyWHpJGtpDqFL8bFQbtg35Y6VJB7NnIyCFvoQW0GXcXVgipZBJk5bZLfS3BPIoHD1m+1WTFTqDWBKMmn/3l+Yi/cK1iUawlZMOPbPskNzNXuupdOhTf5pzI0ExQGCvISJj7pvMWfq2GMqXKzH5BP7RBn2N2QUB1U1CJfvAcpN/NoF1V+Q1jEGeV03ShayK0eBfc/8HP/7+O/QC/xnUnTHoXlAj7+ECx6YXdTeC8OKI0NCbnG9ArExEdmXxd dyoung@RENCI-W530
trawick:
public_key:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAdX6zHUvXSdFkqDOlcqWmHb8Gm+McbS1+uLDJzulyGjpbIU/6qRxnIWdmqx75sgMNhMqzPZIsHTh1LBcmeAhodBLy1wX9tn7FgxPqrlprQxZbZCnCFT3zcXoqyGcvH2ZqhQ1lbVPaD5O7yD4RCuOInFFGuQOmVSjoJt58S5KiO2soVYTzxjf46vCxYnmLhscbUd54gJWAWzmqCwuJ3L1FlVi0Vw9KKCXN+0Zav5R3UFcUUQu4YhmBHgDqoxUttY2tKsyTqBo/DSddr0KPysRzFB/i302Xlg1f4vG/VzTeywyS+Jrt3c3EIX1ofbWDHZYGCormfD3LmsZTJRrE589J trawick@trawick-ip
nmashton:
public_key:
- ss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u2e4hzOQ5nhlJzlBYnABVgpwyaFA3w6PA5g/VDn/F+6Sjo6gWuWtbxAsbfoEuyyuLRzKDuRkufgb4Bq2EZPr0YBNOOWuv6BXuTWgq8Jec4ggK3KGgZl3PEfTxij7J4RGZ1pGE06VEW3GXmKQDVpuyrNFbuHGyXCICR/5S5WWwmM4BCTB6Belhv9xmm7MMmyw5vdH9tQNgB/OTtY3og3ZkkYHrhmYbrgHsPJpuxYdZG1Xm5LTTq7Szl2hjUeOZCBw7OjwM078EHFbYmZzud5T2MezHcHRH5hD/dvPtbmt4Xr9iuoMrC62+7kaZltyqJGzMu5773eP26Ld3hXF47AtTn8D+O0BYGs6aDxmAFgHsnqX80folBzwsaBIkMPYrXMneC/IoKIUvIDL5mlFaTNY86wFHwJXqS6K7lZKKekmusoMQUpEiYVP3zHuDfGv52Rt6agOF77g36KhRs3xTXV29nd2nERrfOB3N+EHrw== digitalanime@gmail.com
mlavin:
public_key:
- ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAm4ppCtMeHOCBTn0gLXRUut31op73cFLFXdQHcD5HWOWaemhqdvFlv7EhWu6fdNHuusRt1j592y+Mswk1l5cmt2jv/1TwSgIoJ2YNUNv0tDWAuMAT5wcE8lj/PEN6294M9WQyRWQW6r8ZRCz78m//rkZZeDvu0xiT6ZJtaldZqhq3UbHssjxpNBp1ooT80D1AuT7c5y5neJSxaQ1JNMOuihheY8rtSfz3U2/0MnurMZXdvO6X+2hVszrmp0VNrvFHsiPoH5dOmmGjhXi8DbNpX1pWhYQinaREEslSiUwQbdE6drQ30uR+6dqon2WULWE3KPUtYVDn+DoKKxi1UJXYrw== mlavin@caktus007
6 changes: 3 additions & 3 deletions conf/pillar/production.sls
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repo:
branch: master

postgresql_config: # from pgtune
work_mem: 88MB
work_mem: 200MB
maintenance_work_mem: 448MB
shared_buffers: 1792MB
effective_cache_size: 5GB
Expand All @@ -27,8 +27,8 @@ postgresql_config: # from pgtune

# Addtional public environment variables to set for the project
env:
FOO: BAR

NEW_RELIC_APP_NAME: "opendatapolicing production"
NEW_RELIC_MONITOR_MODE: "true"

# Uncomment and update username/password to enable HTTP basic auth
# Password must be GPG encrypted.
Expand Down
3 changes: 2 additions & 1 deletion conf/pillar/staging.sls
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ repo:
branch: dev

postgresql_config: # from pgtune
work_mem: 44MB
work_mem: 200MB
maintenance_work_mem: 448MB
shared_buffers: 1792MB
effective_cache_size: 5GB
checkpoint_segments: 32
log_min_duration_statement: 1000
random_page_cost: 1

# Addtional public environment variables to set for the project
env:
Expand Down
2 changes: 1 addition & 1 deletion conf/salt/project/web/gunicorn.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[program:{{ pillar['project_name'] }}-server]
command={{ directory }}/dotenv.sh {% if use_newrelic %}{{ virtualenv_root }}/bin/newrelic-admin run-program {% endif %}{{ virtualenv_root }}/bin/gunicorn {{ pillar['project_name'] }}.wsgi:application --bind=0.0.0.0:8000 --workers={{ grains['num_cpus'] * 2 + 1 }} --timeout=300
command={{ directory }}/dotenv.sh {% if use_newrelic %}{{ virtualenv_root }}/bin/newrelic-admin run-program {% endif %}{{ virtualenv_root }}/bin/gunicorn {{ pillar['project_name'] }}.wsgi:application --bind=0.0.0.0:8000 --workers={{ grains['num_cpus'] * 2 + 1 }} --timeout=500
user={{ pillar['project_name'] }}
directory={{ directory }}
autostart=true
Expand Down
44 changes: 38 additions & 6 deletions docs/data-import.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ environments, using the ``import_census`` management command. This must be
performed as part of developer and server setup as well as when census support is
added for additional states.


Local/Development Environment
-----------------------------

Before running state imports, first import census data:

.. code-block:: bash
python manage.py import_census
Database Dump (quicker)
_______________________
Expand All @@ -22,9 +29,9 @@ To load an existing database dump on S3, run:
dropdb traffic_stops_nc
createdb -E UTF-8 traffic_stops_nc
wget https://s3-us-west-2.amazonaws.com/openpolicingdata/traffic_stops_nc_production_20150801.tar.zip
unzip traffic_stops_nc_production_20150801.tar.zip
pg_restore -Ox -d traffic_stops_nc traffic_stops_nc_production.tar
wget https://s3-us-west-2.amazonaws.com/openpolicingdata/traffic_stops_nc_2018_01_08.dump.zip
unzip traffic_stops_nc_2018_01_08.dump.zip
pg_restore -Ox -d traffic_stops_nc traffic_stops_nc_2018_01_08.dump
Browse https://s3-us-west-2.amazonaws.com/openpolicingdata/ to see what dumps
are available.
Expand All @@ -33,10 +40,11 @@ To create a new database dump, run:

.. code-block:: bash
pg_dump -Ox -Ft traffic_stops > traffic_stops.tar
ssh dev.opendatapolicingnc.com 'sudo -u postgres pg_dump -Fc traffic_stops_nc_staging' > traffic_stops_nc.dump
That can be loaded with the ``pg_restore`` command shown above.


Raw NC Data (slower)
____________________

Expand All @@ -45,17 +53,35 @@ applied before importing. If in doubt:

.. code-block:: bash
# for NC
dropdb traffic_stops_nc && createdb -E UTF-8 traffic_stops_nc
# for MD
dropdb traffic_stops_md && createdb -E UTF-8 traffic_stops_md
./migrate_all_dbs.sh
Command-line
++++++++++++

If loading NC, make sure to add ``NC_FTP_USER`` and ``NC_FTP_PASSWORD`` and your ``.env`` file.

If on a Mac, install ``gnu-sed``:

.. code-block:: bash
brew install gnu-sed --with-default-names
Run the import command:

.. code-block:: bash
python manage.py import_nc --dest $PWD/ncdata
# for NC (~25m)
rm -rf ./ncdata # if you don't want to reuse previous download
python manage.py import_nc --dest $PWD/ncdata --noprime # noprime = don't prime cache
# for MD (~30m)
rm -rf ./mddata # if you don't want to reuse previous download
python manage.py import_md --dest $PWD/mddata
This took ~25 minutes on my laptop. Run ``tail -f traffic_stops.log`` to follow
along. Reusing an existing ``--dest`` directory will speed up import. However,
Expand All @@ -68,6 +94,7 @@ Now you should be able to view data with ``runserver``:
python manage.py runserver
Admin
+++++

Expand All @@ -90,6 +117,7 @@ imported. Setting the fields:
Once the "dataset" has been created, select the new dataset in list view and
apply the "Import selected dataset" action.


Server
------

Expand Down Expand Up @@ -123,9 +151,11 @@ activated prior to an import of IL data and then deactivated afterwards, as foll
sudo swapoff /swapfile
sudo rm /swapfile


Raw NC Data
___________


Command-line
++++++++++++

Expand All @@ -142,11 +172,13 @@ Reusing an existing ``--dest`` directory will speed up import. However,
if import code has changed since the last time the directory was used, don't
reuse an existing directory.


Admin
+++++

Follow the "Admin" instructions above under "Local/Development Environment".


Create DB Dump
______________

Expand All @@ -157,6 +189,7 @@ ______________
# then on local laptop, run:
scp opendatapolicingnc.com:traffic_stops_nc_production.tar.zip .
Updating landing page stats
---------------------------

Expand Down Expand Up @@ -196,4 +229,3 @@ management commands. Example::
Id 224: Raleigh Police Department 863,653
Id 104: Greensboro Police Department 555,453
Id 88: Fayetteville Police Department 503,013

14 changes: 3 additions & 11 deletions docs/frontend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ Each subclass of ``VisualBase`` needs to define at least these methods:
- ``setDefaultChart``: setting the ``this.chart`` value to an NVD3 chart with correct configuration values
- ``drawChart``: calling ``this.chart`` to actually mount and draw the chart with the data

There is also an optional ``triggerRaceToggle`` method that is triggered by the ``raceToggle.change`` event on the ``document``. This takes care of switching out the graph's data between "race" and "ethnicity" views, where this is relevant. For example, within a NC chart, this method is defined like so::

triggerRaceToggle: function (e, v) {
this.set('showEthnicity', v);
this.drawChart();
}

From this example, you can see that a chart that allows different data sets to be selected will need to have an event handler that invokes ``this.drawChart`` in order to redraw the chart after the needed local state updates have been performed.

Understanding "common" classes
------------------------------
Expand All @@ -59,14 +51,14 @@ Let's look at ``StopRatioDonutBase`` as a concrete example. This has two abstrac
The North Carolina instance of this class defines them like this::

_items: function () {
return (this.get('showEthnicity')) ? Stops.ethnicities : Stops.races;
return Stops.ethnicities;
},

_pprint: function (type) {
return Stops.pprint.get(type);
}

So when ``_items`` is invoked, it fetches its ``showEthnicity`` value and returns either ``Stops.ethnicities`` or ``Stops.races``. When ``_pprint`` is used, it looks up a value in ``Stops.pprint``.
So when ``_items`` is invoked, it fetches ``Stops.ethnicities``. When ``_pprint`` is used, it looks up a value in ``Stops.pprint``.

The Maryland instance is much simpler::

Expand All @@ -78,7 +70,7 @@ The Maryland instance is much simpler::
return x;
}

Because Maryland has no race / ethnicity distinction, its items are simply ``Stops.ethnicities``. And because its data is "humanized" from the get-go, its ``_pprint`` function can just return the input value.
Because its data is "humanized" from the get-go, its ``_pprint`` function can just return the input value.

Other configuration
-------------------
Expand Down

0 comments on commit 77c633b

Please sign in to comment.