Open redshiftzero opened 7 years ago
Yo, so taking a look at this and maybe I'm just missing something obvious. My thought on how to approach this is to create a function in views.py to search for number of images in the database. Where is that stored numerically in the code, so I can write a function to query that/is this the right approach?
Nope this is definitely not obvious 😃. So as an example, here's a rough sketch of how to go about creating a statistic that just displays the number of images per department on the /label
page for logged in users (noting that this is just one method, not the Right Method so feel free to deviate from this):
I'd add a function in OpenOversight/app/utils.py
that returns the number of total photos per department. I'd use compute_leaderboard_stats
as inspiration here, creating a function that queried the database and grouped the rows in the table corresponding to the Image object by Department
.
Armed with this function, I'd go to OpenOversight/app/main/views.py
and call my function in the existing view function for the /label
route. I'd pass the result to render_template
as a keyword argument.
Next, now that my template is getting the data about the number of images, I'd edit the template label_data.html
to display this number nicely next to the relevant department.
A couple things: you could do the query directly in the existing view function, but I expect that this view function might start to get a bit long and gnarly (since there are lots of statistics we might want to add to this volunteer landing page), so I think putting in a utility function is a bit nicer, but either solution works. You wouldn't want to create another view function however, unless you want to create another URL route (that is not /label
).
Keep the questions comin'! 🐉
I want to see a progress bar for each police department: "5% of 13,000 officers in our database have photos"