Skip to content

Commit 05c89b4

Browse files
committed
Complaint sorting implemented
1 parent c68551f commit 05c89b4

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

app/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,22 @@ def getBBLDetails():
117117
open_complaints = complaints[0]
118118
closed_complaints = complaints[1]
119119
number = complaints[2]
120-
120+
121+
keywords = [['Administrative'],['Environmental'],['Safety']]
122+
121123
returnData = {}
122124
returnData["address"] = address
123125
returnData["open_complaints"] = open_complaints
124126
returnData["closed_complaints"] = closed_complaints
125127
returnData["number"] = number
128+
129+
allComplaints = open_complaints
130+
allComplaints.extend(closed_complaints)
131+
sortedComplaints = NYCDBWrapper.sortComplaints(allComplaints, keywords)
132+
returnData["Administrative"] = sortedComplaints[0]
133+
returnData["Environmental"] = sortedComplaints[1]
134+
returnData["Safety"] = sortedComplaints[2]
135+
126136

127137
return returnData
128138

app/modules/NYCDBWrapper.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,16 @@ def getBBL(building, street, borough):
6161
return (data['address']['bbl'])
6262

6363

64+
def sortComplaints(complaints, keywords):
65+
# complaints is a list of all the complaints, open_complaints and closed_complaints from cleanComplaints()
66+
# keywords is a list of 3 lists, keywords[0] is the list of Administrative keywords, 1- Environmental, 2- Safety.
67+
toReturn = [[],[],[]]
68+
for complaint in complaints:
69+
for i, category in enumerate(keywords):
70+
for keyword in category:
71+
if keyword in complaint['Description']:
72+
toReturn[i].append(complaint)
73+
return toReturn
74+
6475
def getSameComplaints(user_id):
6576
return None

app/static/js/components/Dashboard.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ export default class Dashboard extends React.Component {
8181
<div className="lowerPortion">
8282
<Row>
8383
<Col>
84-
<ComplaintCard header={"Administrative"} data={open_complaints} />
84+
<ComplaintCard header={"Administrative"} data={Administrative} />
8585
</Col>
8686
<Col>
87-
<ComplaintCard header={"Environmental"} data={closed_complaints} />
87+
<ComplaintCard header={"Environmental"} data={Environmental} />
8888
</Col>
8989
<Col>
90-
<ComplaintCard header={"Safety"} data={closed_complaints} />
90+
<ComplaintCard header={"Safety"} data={Safety} />
9191
</Col>
9292
</Row>
9393
</div>

tests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ def test_find_all_complaints(self):
7474
self.assertIsNotNone(complaints[1])
7575
# Check if closed and open complaints are both not null
7676

77+
def test_complaint_sort(self):
78+
testBBL = 1019610057
79+
complaints = NYCDBWrapper.findAllComplaints(testBBL)
80+
complaints[0].extend(complaints[1])
81+
print(complaints[0])
82+
keywords = [['Administrative'],['Environmental'],['Safety']]
83+
sorted_complaints = NYCDBWrapper.sortComplaints(complaints[0],keywords)
84+
self.assertIsNotNone(sorted_complaints)
85+
7786
def test_find_new_complaints(self):
7887
testBBL = 1019610057
7988
start_date = "2010-01-22T16:04:13"

0 commit comments

Comments
 (0)