Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
redshiftzero committed Oct 19, 2016
2 parents 3dae9ab + 864aefe commit 66bb294
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 36 deletions.
6 changes: 4 additions & 2 deletions DEPLOY.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ server {
proxy_pass http://127.0.0.1:4000;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 300s;
proxy_read_timeout 300s;
}
}
```
Expand Down Expand Up @@ -88,7 +90,7 @@ Group=nginx
WorkingDirectory=/home/nginx/oovirtenv/OpenOversight/OpenOversight
Environment="PATH=/home/nginx/oovirtenv/bin"
Environment="PGPASS=~/.pgpass"
ExecStart=/usr/local/bin/gunicorn -w 4 -b 127.0.0.1:4000 app:app
ExecStart=/usr/local/bin/gunicorn -w 16 -b 127.0.0.1:4000 --timeout 90 app:app
[Install]
WantedBy=multi-user.target
Expand Down
12 changes: 6 additions & 6 deletions OpenOversight/app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
('Other', 'Other'), ('Not Sure', 'Not Sure')]
GENDER_CHOICES = [('M', 'Male'), ('F', 'Female'), ('Other', 'Other'),
('Not Sure', 'Not Sure')]
RANK_CHOICES = [('Not Sure', 'Not Sure'), ('PO', 'Police Officer'),
('FIELD', 'Field Training Officer'), ('SERGEANT', 'Sergeant'),
('LIEUTENANT', 'Lieutenant'),
('CAPTAIN', 'Captain'), ('COMMANDER', 'Commander'),
('DEP CHIEF', 'Deputy Chief'), ('CHIEF', 'Chief'),
('DEPUTY SUPT', 'Deputy Superintendent'), ('SUPT OF POLICE', 'Superintendent')]
RANK_CHOICES = [('Not Sure', 'Not Sure'), ('SUPT OF POLICE', 'Superintendent'),
('DEPUTY SUPT', 'Deputy Superintendent'), ('CHIEF', 'Chief'),
('DEP CHIEF', 'Deputy Chief'), ('COMMANDER', 'Commander'),
('CAPTAIN', 'Captain'), ('LIEUTENANT', 'Lieutenant'),
('SERGEANT', 'Sergeant'), ('FIELD', 'Field Training Officer'),
('PO', 'Police Officer')]
DEPT_CHOICES = [('ChicagoPD', 'Chicago Police Department')]


Expand Down
50 changes: 25 additions & 25 deletions OpenOversight/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
db = SQLAlchemy(app)


def grab_officers(form):
officer_query = db.session.query(Officer, Assignment).join(Assignment)

def filter_by_form(form, officer_query):
if form['race'] in ('BLACK', 'WHITE', 'ASIAN', 'HISPANIC', 'PACIFIC ISLANDER'):
officer_query = officer_query.filter(Officer.race.like('%%{}%%'.format(form['race'])))
if form['gender'] in ('M', 'F'):
Expand All @@ -31,38 +29,40 @@ def grab_officers(form):
officer_query = officer_query.filter(db.or_(db.and_(Officer.birth_year <= min_birth_year,
Officer.birth_year >= max_birth_year),
Officer.birth_year == None))
return officer_query

return officer_query.all()

def grab_officers(form):
officer_query = db.session.query(Assignment, Officer).join(Officer)
officer_query = filter_by_form(form, officer_query)
return officer_query.all()

def grab_officer_faces(officer_ids):
if len(officer_ids) == 0:
return []

officer_images = {}
face_query = db.session.query(Image, Face).join(Face)
for officer_id in officer_ids:
faces = face_query.filter(Face.officer_id == officer_id).all()
def grab_officer_faces(form):
officer_query = db.session.query(Assignment, Officer, Face, Image) \
.join(Officer).join(Face).join(Image)
officer_query = filter_by_form(form, officer_query)
officer_images = officer_query.all()
return officer_images

if len(faces) > 0:
officer_images.update({officer_id: faces[0].Image.filepath})
else: # use placeholder image
officer_images.update({officer_id: 'static/images/placeholder.png'})

return officer_images
def sort_officers_by_photos(all_officers, officers_w_images):
all_officer_ids_w_photos = [x.Officer.id for x in officers_w_images]
all_officer_ids = [x.Officer.id for x in all_officers]

all_officer_images = {}
officers = officers_w_images
for officer in officers_w_images:
all_officer_images.update({officer.Officer.id: officer.Image.filepath})

def sort_officers_by_photos(officers, officer_images):
identified_officers = []
unidentified_officers = []
for officer in officers:
if officer_images[officer.Officer.id] == 'static/images/placeholder.png':
unidentified_officers.append(officer)
for officer in all_officers:
if officer.Officer.id in all_officer_ids_w_photos:
continue
else:
identified_officers.append(officer)
all_officer_images.update({officer.Officer.id: 'static/images/placeholder.png'})
officers.append(officer)

officers = identified_officers + unidentified_officers
return officers
return officers, all_officer_images

def allowed_file(filename):
return '.' in filename and \
Expand Down
5 changes: 2 additions & 3 deletions OpenOversight/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ def get_officer():
def get_gallery():
form_values = request.form
officers = grab_officers(form_values)
officer_ids = [officer.Officer.id for officer in officers]
officer_images = grab_officer_faces(officer_ids)
sorted_officers = sort_officers_by_photos(officers, officer_images)
officer_images = grab_officer_faces(form_values)
sorted_officers, officer_images= sort_officers_by_photos(officers, officer_images)

return render_template('gallery.html',
officers=sorted_officers,
Expand Down

0 comments on commit 66bb294

Please sign in to comment.