-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
browse department as directory #533
base: develop
Are you sure you want to change the base?
Conversation
This is great, thanks! I was able to get it to work with the test data, but when I tried to use Baltimore data the ranks don't match up with what's in |
…ll ranks in data get displayed
38b9dc5
to
0ed2103
Compare
Thanks for the feedback. You're right, it could be hard to manually maintain proper rank names for many departments with slight variations. I pushed another approach that makes it independent of RANK_CHOICES. It makes up a list of ranks found in the data and uses those to demarcate sections in the directory view. The html was also generalized so all ranks found would be displayed, with Not Sure at the end, and a random (blue-ish) background color. The disadvantages of this approach are Let me know if it fixes your error, I can also try your dataset if you like, just let me know where to find it. |
OpenOversight/app/main/views.py
Outdated
rank_types = ["NOT SURE"] | ||
|
||
for officer in officers: | ||
rec = assign_dict[officer.id] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible there exist officers that don't have assignments, so this should probably be wrapped in a try block:
try:
rec = assign_dict[officer.id]
except KeyError:
continue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, i hadn't considered this case. fixed in last commit
Cool, I like that approach and I was able to get it working for Baltimore data. We have like dozens of job titles, some with only 1 or 2 employees, so that made the list pretty long and unwieldy. But the solution to that is probably just to filter out what officers I import (e.g. not forensic scientists). I wonder if the best way to allow department-specific ranks but not have the disadvantages you listed above, would be to have a per-department list of ranks provided when a department is created. Maybe by uploading an ordered CSV or otherwise storing it in the database? But that may also be a follow-on issue beyond the scope of this PR :) |
OpenOversight/app/main/views.py
Outdated
if safe_rank not in officer_nodes.keys(): | ||
officer_nodes[safe_rank] = [] | ||
else: | ||
officer_nodes[safe_rank].append({'id': officer.id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be in an else
block or it won't add the first officer of a rank it finds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ha! thanks for catching this, fixed in last commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super sweet! One speedup suggestion in the view function for this (we have a LOT of officers in some departments, e.g. NYPD has 40k+ cops and is on its way into the openoversight)
abort(404) | ||
|
||
officers = Officer.query.filter(Officer.department_id == department_id).all() | ||
# map each officer to their most recent assignment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a faster (i.e. to avoid the first for loop below) way to get the most recent assignment is to use the assignments
relationship on the Officer
object:
Officer.query.first().assignments[-1]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at first i tried using this relationship, but I found that accessing assignments on each Officer was very slow (sometimes timing out the browser on the test data). i found it much faster to query all Assignments at once and then associate them to officers in the loop. additionally, i wasn't sure that the assignments would be guaranteed to be in chronological order in the list
👍 to this, storing the ranks in the database is the right way to go (fine to do in a separate issue/PR imo, see #326) |
Status
Ready for review / in progress
Description of Changes
Related to #527 #474 #500 , provides a directory view of the department that users can quickly Ctrl-F through if they know name or star number.
Changes proposed in this pull request:
Notes for Deployment
Screenshots (if appropriate)
Tests and linting
I have rebased my changes on current
develop
pytests pass in the development environment on my local machine
flake8
checks pass