lucyparsons / OpenOversight

Police oversight and accountability through public data 👮
https://openoversight.com
GNU General Public License v3.0
240 stars 79 forks source link

Add high level stats to volunteer frontpage and/or leaderboard #231

Open redshiftzero opened 7 years ago

redshiftzero commented 7 years ago

I want to see a progress bar for each police department: "5% of 13,000 officers in our database have photos"

redshiftzero commented 6 years ago

https://www.w3schools.com/bootstrap/bootstrap_progressbars.asp

ssempervirens commented 6 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?

redshiftzero commented 6 years ago

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):

  1. 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.

  2. 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.

  3. 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'! 🐉