Skip to content

Commit 8fecbbd

Browse files
committed
deploy: 95c107f
0 parents  commit 8fecbbd

31 files changed

+4277
-0
lines changed

.buildinfo

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sphinx build info version 1
2+
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3+
config: 5171aacc08bff122d89e3a2526ac1466
4+
tags: 645f666f9bcd5a90fca523b33c5a78b7

.doctrees/advanced_csv_import.doctree

64.2 KB
Binary file not shown.

.doctrees/area_coordinator.doctree

5.2 KB
Binary file not shown.

.doctrees/bulk_upload.doctree

25.7 KB
Binary file not shown.

.doctrees/environment.pickle

156 KB
Binary file not shown.

.doctrees/index.doctree

5.57 KB
Binary file not shown.

.nojekyll

Whitespace-only changes.

_sources/advanced_csv_import.md.txt

+206
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
Advanced csv import
2+
=============================================
3+
This is the documentation of the advanced csv import command `advanced_csv_import`. For the documentation of the less complicated
4+
bulk-upload command `bulk-add-officers` see [`bulk_upload`](bulk_upload.md). `bulk-add-officers` accepts one csv containing information
5+
about the officer, including badge-number, jobs and salary and makes decisions on whether to update rows in the database
6+
or create new entries based on the existing data.
7+
8+
The advanced csv upload is for the most part a way to copy data for one department into the database with as little as possible logic added on.
9+
So the tables provided in csv form represent the data that will be inside the sql tables after running the command.
10+
(With a few exceptions for many-to-many relationships and auxiliary models like location and license plates)
11+
12+
Before you start
13+
----------------
14+
CSV uploads should always be tested locally or in other non-production environments, and it is strongly recommended
15+
to have the database backed up before running the command. The command is designed to fail early and will
16+
only commit the changes if it didn't encounter any problems. The command however is pretty powerful
17+
and can therefore lead to data loss and inconsistencies if the provided csv files are not prepared correctly.
18+
19+
Explanation of the command
20+
--------------------------
21+
```shell
22+
/usr/src/app/OpenOversight$ flask advanced-csv-import --help
23+
Usage: flask advanced-csv-import [OPTIONS] DEPARTMENT_NAME DEPARTMENT_STATE
24+
25+
Add or update officers, assignments, salaries, links and incidents from
26+
csv files in the department using the DEPARTMENT_NAME and DEPARTMENT_STATE.
27+
28+
The csv files are treated as the source of truth. Existing entries might
29+
be overwritten as a result, backing up the database and running the
30+
command locally first is highly recommended.
31+
32+
See the documentation before running the command.
33+
34+
Options:
35+
--officers-csv PATH
36+
--assignments-csv PATH
37+
--salaries-csv PATH
38+
--links-csv PATH
39+
--incidents-csv PATH
40+
--force-create Only for development/testing!
41+
--overwrite-assignments
42+
--help Show this message and exit.
43+
```
44+
45+
46+
The command expects two mandatory arguments, the department name and department state.
47+
This is to reduce the chance of making changes to the wrong department by mixing up files.
48+
Then there are 5 options to include paths to officers, assignments, salaries, incidents and links csv files.
49+
Then there is a `--force-create` flag that allows to delete and overwrite existing entries in the database.
50+
This is only supposed to be used in non-production environments and to allow replication of the data of another (in most cases production)
51+
instance to local environments to test the import command locally first. More details on that flag at the end of the document: :ref:`ref-aci-force-create`.
52+
Finally, there is `--overwrite-assignments` which simplifies updating assignments. Instead of updating them,
53+
all assignments for the relevant officers are deleted and created new based on the provided data. This flag is only
54+
considered if an assignments-csv is provided and ignored otherwise. See the instructions in
55+
the section on assignment-csv for more details.
56+
57+
General overview of the csv import
58+
-----------------------------------
59+
The following lists the header fields that each csv can contain. If the csv includes any other fields, the command will fail.
60+
However, the fields are not case-sensitive and spaces are treated as `_`. So `Officer ID` can be used instead of `officer_id`.
61+
62+
*All optional fields can be left blank and will be inserted as* `NULL` *or empty string as appropriate.*
63+
**Warning:** When updating a record a field that is left blank might overwrite an existing record.
64+
This can only be prevented by not including the column in the csv at all.
65+
66+
.. _ref-aci-formats:
67+
68+
Formats:
69+
- `date` - The date should be provided in `YYYY-MM-DD` format.
70+
- `time` - Time should be provided in `HH:MM:SS` 24h-format in the respective timezone.
71+
- `DEPARTMENT_STATE` - The department state should be provided in the [standard two-letter abbreviation](https://www.faa.gov/air_traffic/publications/atpubs/cnt_html/appendix_a.html) format.
72+
73+
74+
The `id` field
75+
--------------
76+
Each csv corresponds to a table in the OpenOversight database. And each csv file has to include `id` as a field in the table.
77+
That field has one primary purpose: If the field is blank, it is assumed that that row is a new entry.
78+
If the field contains a number however, it is assumed that a record with that particular id already exists in the database
79+
and the record will be updated according to the provided fields. Finally, in the case of officers and incidents
80+
there is a third option where the `id` field can contain a string that starts with `#`. This also indicates a new record,
81+
but that new record can be referenced in other provided tables. (for example as the `officer_id` in the salaries csv)
82+
83+
84+
85+
Officers csv
86+
------------
87+
- Required: `id, department_name, department_state`
88+
- Optional: `last_name, first_name, middle_initial, suffix, race, gender, employment_date, birth_year, unique_internal_identifier`
89+
- Ignored: `badge_number, job_title, most_recent_salary, unique_identifier` (Unused but command will not fail when field is present)
90+
91+
### Details
92+
93+
- `department_name` - Name of department exactly as it is in the server database.
94+
This needs to match the department name provided with the command.
95+
- `department_state` - Name of department state exactly as it is in the server database, which will be the
96+
[standard two-letter abbreviation](https://www.faa.gov/air_traffic/publications/atpubs/cnt_html/appendix_a.html) for the department's respective location.
97+
This needs to match the department state provided with the command.
98+
- `unique_internal_identifier` - A string or number that can be used to
99+
uniquely identify the officer, in departments in which the badge
100+
number stays with the officer using that number is fine. Can and should be left blank
101+
if no such number is available.
102+
- `first_name` & `last_name` Will be inserted into the database as is.
103+
- `middle_initial` - Usually up to one character, but can be more.
104+
- `suffix` - Choice of the following values: `Jr, Sr, II, III, IV, V`.
105+
- `gender` - One of the following values: `M`, `F`, `Other`.
106+
- `race` - One of the following values: `BLACK`, `WHITE`, `ASIAN`, `HISPANIC`, `NATIVE AMERICAN`, `PACIFIC ISLANDER`, `Other`.
107+
- `employment_date` - [Date](https://help.highbond.com/helpdocs/analytics/13/user-guide/en-us/Content/table_definition/c_formats_of_date_and_time_source_data.htm) representing the start of employment with this department.
108+
- `birth_year` - Integer representing the birth year of the officer in a `yyyy` format.
109+
110+
Assignments csv
111+
---------------
112+
- Required: `id, officer_id, job_title`
113+
- Optional: `badge_number, unit_id, unit_name, start_date, resign_date`
114+
115+
### Details
116+
117+
- `officer_id` - Number referring to `id` of existing officer or string starting with `#` referring to a newly created officer in the provided officers csv.
118+
- `badge_number` - Any string that represents the star or badge number of the officer. In some departments this number changes with the assignment.
119+
- `job_title` - The job title, will be created if it does not exist.
120+
- `unit_id` - ID of existing unit within the department.
121+
- `unit_name` - Name of the unit, only used if the `unit_id` column is not provided.
122+
- `start_date` - [Start date](https://help.highbond.com/helpdocs/analytics/13/user-guide/en-us/Content/table_definition/c_formats_of_date_and_time_source_data.htm) of this assignment.
123+
- `resign_date` - [End date](https://help.highbond.com/helpdocs/analytics/13/user-guide/en-us/Content/table_definition/c_formats_of_date_and_time_source_data.htm) of this assignment.
124+
125+
### Special Flag
126+
127+
The `--overwrite-assignments` in the command can be used to not merge new with existing assignments.
128+
Instead, all existing assignments belonging to officers named in the `officer_id` column are deleted first,
129+
before the new assignments contained in the provided csv are created in the database.
130+
131+
This should only be used if the provided csv contains both the currently in the database and additional assignments,
132+
or is based on a better and more complete dataset, for example after receiving a dataset for historic assignment data.
133+
134+
Salaries csv
135+
------------
136+
- Required: `id, officer_id, salary, year`
137+
- Optional: `overtime_pay, is_fiscal_year`
138+
139+
### Details
140+
141+
- `officer_id` - Integer referring to `id` of existing officer or string starting with `#` referring to a newly created officer in the provided officers csv.
142+
- `salary` - Number representing the officer's salary in the given year.
143+
- `year` - Integer, the year this salary information refers to.
144+
- `overtime_pay` - Number representing the amount of overtime payment for offer in given year.
145+
- `is_fiscal_year` - Boolean value, indicating whether the provided year refers to calendar year or fiscal year.
146+
The values `true`, `t`, `yes` and `y` are treated as "yes, the salary is for the fiscal year", all others (including blank) as "no".
147+
148+
Incidents csv
149+
-------------
150+
- Required: `id, department_name, department_state`
151+
- Optional: `date, time, report_number, description, street_name, cross_street1, cross_street2, city, state, zip_code,
152+
created_by, last_updated_by, officer_ids, license_plates`
153+
154+
### Details
155+
156+
- `department_name` - Name of department exactly as in the server database.
157+
This needs to match the department name provided with the command.
158+
- `department_state` - Name of department state exactly as it is in the server database, which will be the
159+
[standard two-letter abbreviation](https://www.faa.gov/air_traffic/publications/atpubs/cnt_html/appendix_a.html) for the department's respective location.
160+
- `date` - [Date](https://help.highbond.com/helpdocs/analytics/13/user-guide/en-us/Content/table_definition/c_formats_of_date_and_time_source_data.htm) of the incident
161+
- `time` - [Time](https://help.highbond.com/helpdocs/analytics/13/user-guide/en-us/Content/table_definition/c_formats_of_date_and_time_source_data.htm) of the incident
162+
- `report_number` - String representing any kind of number assigned to complaints or incidents by the police department.
163+
- `description` - Text description of the incident.
164+
- `street_name` - Name of the street the incident occurred, but should not include the street number.
165+
- `cross_street1`, `cross_street2` The two closest intersecting streets.
166+
- `city`, `state`, `zip_code` State needs to be in 2 letter abbreviated notation.
167+
- `created_by`, `last_updated_by` - ID of existing user shown as responsible for adding this entry.
168+
- `officer_ids` - IDs of officers involved in the incident, separated by `|`.
169+
- Each individual id can either be an integer referring to an existing officer or a string starting with `#` referring to a newly created officer.
170+
- Example: `123|#C1|1627` for three officers, one with id 123, one with 1627 and one whose record was created in the officers csv
171+
and whose id-field was the string `#C1`.
172+
173+
- `license_plates` - All license plates involved in the incident. If there is more than one, they can be separated with a `|`.
174+
- Each license plate consists of the license plate number and optionally a state in abbreviated form separated by an underscore `_`.
175+
- Example: `ABC123_IL|B991` for one license plate with number `ABC123` from Illinois and one with number `B991` and no associated state.
176+
177+
178+
Links csv
179+
---------
180+
- Required: `id, url`
181+
- Optional: `title, link_type, description, author, created_by, officer_ids, incident_ids`
182+
183+
### Details
184+
185+
- `url` - Full url of the link starting with `http://` or `https://`.
186+
- `title` - Text that will be displayed as the link.
187+
- `description` - A short description of the link.
188+
- `link_type` - Choice of `Link`, `YouTube Video` and `Other Video`.
189+
- `author` - The source or author of the linked article, report, video.
190+
- `created_by` - ID of existing user shown as responsible for adding this entry.
191+
- `officer_ids` - IDs of officer profiles this link should be visible on, separated by `|`. See same field in incidents above for more details.
192+
- `incidents_ids` - IDs of incidents this link should be associated with, separated by `|`. Just like `officer_ids` this can contain strings.
193+
starting with `#` to refer to an incident created in the incident csv.
194+
195+
Examples
196+
---------
197+
Example csvs can be found in the repository under `OpenOversight/tests/test_csvs`.
198+
199+
Local development flag `--force-create`
200+
---------------------------------------
201+
This flag changes the behavior when an integer is provided as `id`. Instead of updating an existing record,
202+
a new record will be created and assigned the given `id`. If a record with that `id` already exists in the
203+
database, it will be deleted before the new record is created.
204+
205+
This functionality is intended to be used to import csv files downloaded from `OpenOversight download page </download/all>`_
206+
to get a local copy of the production data for one department in the local development database.

_sources/area_coordinator.md.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Area Coordinator
2+
================
3+
4+
An area coordinator is a person with an account on
5+
OpenOversight that is charged with curating the collection for a particular
6+
department. There can be several area coordinators for a given department.
7+
The tasks they perform include:
8+
9+
* Add new officers
10+
* Update officer information, such as new assignments or promotions
11+
* Add private notes to particular officer profiles (visible to other area
12+
coordinators or administrators)
13+
* Add a brief description to an officer's profile
14+
* Add links and videos to officer's profiles
15+
* Add incidents linked to one or more officers

_sources/bulk_upload.md.txt

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
Using the bulk upload feature
2+
=============================
3+
To facilitate adding rosters of new departments or updating existing
4+
departments there is a flask command that gives system administrators
5+
the ability to load the data from a csv file directly into the database.
6+
7+
**Warning** This process is not very robust at this point and there is
8+
risk of leaving the database in an inconsistent state. It is strongly
9+
recommended to back up the database before starting this operation and
10+
to run the command on a development server first and see if the results
11+
are as expected.
12+
13+
Preparation steps
14+
-----------------
15+
- Create department if it does not exist
16+
- Add ranks in hierarchical order, make sure all the ranks present in
17+
the csv are added
18+
19+
Layout of the csv file
20+
----------------------
21+
The csv file can have the following fields:
22+
```
23+
department_id
24+
unique_internal_identifier
25+
first_name
26+
last_name
27+
middle_initial
28+
suffix
29+
gender
30+
race
31+
employment_date
32+
birth_year
33+
star_no
34+
job_title
35+
unit_id
36+
start_date
37+
resign_date
38+
salary
39+
salary_year
40+
salary_is_fiscal_year
41+
overtime_pay
42+
```
43+
44+
45+
Explanation of the individual fields
46+
------------------------------------
47+
General information:
48+
- `department_id` - ID of department in the server database, for example `1` for Chicago Police Department can be found in
49+
url for that department: `https://openoversight.com/departments/1`.
50+
- `unique_internal_identifier` - A string or number that can be used to uniquely identify the officer, in departments in
51+
which the badge number stays with the officer using that number is fine, otherwise it is recommended to leave this
52+
blank and provide the `star_no` instead.
53+
- `first_name` & `last_name` & `middle_initial`
54+
- `suffix` - One of the following values: `Jr, Sr, II, III, IV, V`.
55+
- `gender` - One of the following values: `M`, `F`, `Other` or `Not Sure`.
56+
- `race` - One of the following values: `BLACK`, `WHITE`, `ASIAN`, `HISPANIC`, `NATIVE AMERICAN`, `PACIFIC ISLANDER`, `Other`, `Not Sure`.
57+
- `employment_date` - Start of employment with this department.
58+
- `birth_year` - Integer representing the birth year of the officer in a `yyyy` format
59+
60+
Current Employment information:
61+
- `star_no` - Star or badge number, might be related to current rank.
62+
- `job_title` - Rank or title, needs to be added to this department verbatim or `Not Sure`,
63+
- `unit_id` - ID of unit within the department.
64+
- `start_date` - Start date of this assignment.
65+
- `resign_date` - Resignation date of this assignment.
66+
67+
Salary information:
68+
If adding salary data, the following fields are required: `salary_year`,
69+
`salary_is_fiscal_year`, and `salary`.
70+
- `salary_year` - Year of which the salary information is provided in a `yyyy` format.
71+
- `salary_is_fiscal_year` - `true` or `false`, salary information is on fiscal year basis vs. calendar year.
72+
- `salary` - Salary in given year.
73+
- `overtime_pay` - Overtime received in given year.
74+
75+
Required fields
76+
- `department_id`, `first_name`, `last_name`, `job_title` and either `star_no` or `unique_internal_identifier` are required.
77+
- `employment_date`, `start_date` and `resign_date` can be either in `yyyy-mm-dd` or `mm/dd/yyyy` format - if the column is present
78+
the field cannot be left blank.
79+
80+
Command-line options
81+
- `--no-create` - For each line in the CSV, update an existing officer if one exists, but do not create any new officers. If an officer in the CSV is not already in OpenOversight, the line will be ignored.
82+
- `--update-by-name` - Update officers by `first_name` and `last_name`. Useful when `unique_internal_identifier` and `star_no` are not available.
83+
- `--update-static-fields` - Allow modifications to normally-static fields like `race`, `birth_year`, etc., which OpenOversight normally prevents from being modified. Values in the database will be overwritten with values in the CSV.
84+
85+
The command to run on the server
86+
--------------------------------
87+
`/usr/src/app/OpenOversight$ flask bulk-add-officers [/path/to/csv_file.csv]`

_sources/index.rst.txt

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.. OpenOversight documentation master file, created by
2+
sphinx-quickstart on Fri Jun 29 23:35:10 2018.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Welcome to OpenOversight's documentation!
7+
=========================================
8+
9+
.. toctree::
10+
:maxdepth: 2
11+
:caption: Contents:
12+
13+
area_coordinator
14+
bulk_upload
15+
advanced_csv_import
16+
17+
OpenOversight is a Lucy Parsons Labs project to improve law enforcement
18+
accountability through public and crowdsourced data. We maintain a database
19+
of officer demographic information and provide digital galleries of photographs.
20+
This is done to help people identify law enforcement officers for filing
21+
complaints and in order for the public to see work-related information about
22+
law enforcement officers that interact with the public.
23+
24+
Indices and tables
25+
==================
26+
27+
* :ref:`genindex`
28+
* :ref:`search`

0 commit comments

Comments
 (0)