Open HiGregory opened 3 years ago
Currently, the algorithm needs improvement in data storage, easy usage, adding an improved grading system, and allowing more parameters in the search options. Below is the program in its first stage as I have it on my computer: `''' In this file, we will attempt to read an Excel file and take some specific information out of it by means of a simple/ manual filtration algorithm. This information is then stored in a 2D array. Then upon user input, it is displayed a pie chart with police- specific statistics. '''
import xlrd import math import matplotlib.pyplot as plt
file_location = (r"C:\Users\jalbe\OneDrive\Documents\File_IN\2015-2020 CIP cases - Badge Watch.xlsx") open_file = xlrd.open_workbook(file_location) sheet = open_file.sheet_by_index(0) row_num = sheet.nrows
total_officers = [] for k in range (1, row_num): if (sheet.cell_value(k,2) not in total_officers): total_officers.append(sheet.cell_value(k,2))
grading_list = [[0 for i in range (13)] for j in range (len(total_officers)+1)] # Number of valid rows (rows with badge ID) badge_ID = [] col = 0 prev_col = 0 BID = 0 name = '' no_BID = 0
for row in range (1, row_num):
if (sheet.cell_value(row,2) != "")and((type(sheet.cell_value(row,2))).__name__ != 'str'):
n = 0
total_complaints = 0
if sheet.cell_value(row,2) not in badge_ID:
BID = int(sheet.cell_value(row,2))
name = str(sheet.cell_value(row,3)+' '+sheet.cell_value(row,4))
badge_ID.append(BID)
grading_list[col][0] = BID
grading_list[col][12] = name
if sheet.cell_value(row,5) == 'Harassment':
n = 1
elif sheet.cell_value(row,5) == 'Police Involved Shooting':
n = 2
elif sheet.cell_value(row,5) == 'Improper Procedure':
n = 3
elif sheet.cell_value(row,5) == 'Negligence of Duty':
n = 4
elif sheet.cell_value(row,5) == 'Misconduct':
n = 5
elif sheet.cell_value(row,5) == 'Abusive Treatment':
n = 6
elif sheet.cell_value(row,5) == 'Discourtesy':
n = 7
elif sheet.cell_value(row,5) == 'Missing or Damaged Property':
n = 8
elif sheet.cell_value(row,5) == 'Bias Based Profiling':
n = 9
elif sheet.cell_value(row,5) == 'Excessive Force':
n = 10
elif sheet.cell_value(row,5) == '':
n = 11
grading_list[col][n] = (grading_list[col][n]) + 1
for l in range (1, 11):
total_complaints += grading_list[col][l]
grading_list [col][11] = total_complaints
col = col + 1
else:
prev_col = col
for i in range (0, len(badge_ID)):
if (badge_ID[i] == sheet.cell_value(row,2)):
col = i
break
if sheet.cell_value(row,5) == 'Harassment':
n = 1
elif sheet.cell_value(row,5) == 'Police Involved Shooting':
n = 2
elif sheet.cell_value(row,5) == 'Improper Procedure':
n = 3
elif sheet.cell_value(row,5) == 'Negligence of Duty':
n = 4
elif sheet.cell_value(row,5) == 'Misconduct':
n = 5
elif sheet.cell_value(row,5) == 'Abusive Treatment':
n = 6
elif sheet.cell_value(row,5) == 'Discourtesy':
n = 7
elif sheet.cell_value(row,5) == 'Missing or Damaged Property':
n = 8
elif sheet.cell_value(row,5) == 'Bias Based Profiling':
n = 9
elif sheet.cell_value(row,5) == 'Excessive Force':
n = 10
elif sheet.cell_value(row,5) == '':
n = 11
grading_list[col][n] = (grading_list[col][n]) + 1
for m in range (1, 11):
total_complaints += grading_list[col][m]
grading_list [col][11] = total_complaints
col = prev_col
elif (sheet.cell_value(row,2) == ""):
no_BID += 1
print(no_BID, " Complaints have no Badge ID")
repeat = True repeat_check = ''
while (repeat):
BID_input = int(input("Enter badge ID for the officer you look for: "))
officer_col_index = 0
officer_in_list = False
# Searching the database
for m in range (0, len(total_officers)+1):
if (grading_list[m][0] == BID_input):
officer_col_index = m
officer_in_list = True
break
elif (m == len(total_officers)):
print("Sorry, officer badge ID not found.")
if (officer_in_list):
print("Information on:", str(grading_list[officer_col_index][12]))
# Grading system
most_complaints = 0
for n in range (0, len(total_officers)+1):
if (grading_list[n][11] > most_complaints):
most_complaints = grading_list[n][11]
print(str(grading_list[officer_col_index][12]),"'s Grade: ", math.ceil(100-((grading_list[officer_col_index][11]/most_complaints)*100)),"%")
# Displaying pie chart on the specific officer
if (officer_in_list):
categories = ['Harassment','Police Involved Shooting','Improper Procedure','Negligence',\
'Misconduct','Abusive Treatment','Discourtesy','Missing/Damage Property',\
'Biased Profiling','Excessive Force']
labels = []
sizes = []
explode = []
total = grading_list[officer_col_index][11]
for p in range (0, 10):
if ((grading_list[officer_col_index][p+1]) > 0):
labels.append(categories[p])
sizes.append((grading_list[officer_col_index][p+1]/total)*100)
explode.append(0.05)
# Maintenance check
#print(*labels)
#print(*sizes)
#print(*explode)
# Creating plot image
fig1, ax1 = plt.subplots()
# Setting up pie chart
ax1.pie(sizes, explode=explode, autopct='%1.1f%%',
shadow= True, startangle=90, center = (0, 0))
ax1.set_title(str(grading_list[officer_col_index][12])+"'s Statistics")
ax1.legend(title = str(total)+ " total complaints", labels = labels, bbox_to_anchor=(.60, -.175, 0.5, 0.5))
ax1.axis('equal')
#Showing image
plt.show()
repeat_check = input("Search again? Enter ('Y' or 'N')")
if (repeat_check == 'N') or (repeat_check == 'n'):
repeat = False`
Notice: As a team, we're currently undergoing issues getting Django ready on our computers. We plan to use Docker to get the environment ready and our code together.
As an end-user, I want to be able to search for cops by any parameters and see charts based on the data to help give me a quick context of the data.
Challenge - Jose Hernandez has set this up in Python but is working on setting this up on the landing page. Suggestion - Use Django web-based framework to host the front-end application