BOS311
Presentation
Introduction
System Blueprint:
Background Program Flow Chart:
Take a glance of the official database:
About BOS:311
- Non-emergency city service company
- Incidents are reported by residents of Boston
- Public service whose motto is to resolve reported issues effectively
Data Visualization of BOS:311 datasets
Problem Statements
- Potential Duplicate issue creations.
- No feedback is given to the users.
- Hundred of new cases created every day disperse in Boston city.
- No rule for reasonably distributing resources to handle the cases.
Our Targets
1. Improve system efficiency.
2. Reduce staff workload.
3. Increase user satisfaction.
4. Integrate the ChatBot in BOS:311 Mobile Application.
Details:
- The first target is to improve system efficiency through Amazon RDS. We defined a new variable named priority from 1~5 to mark the emergence level of each case.
- The second target is to reduce the staff workload through the background program. Our system will detect the validation of every new report.
- The third target is to increase user satisfaction through Amazon SNS. Our system will follow up on the cases, and inform the latest cast status to the users.
- The fourth target is to integrate the ChatBot in the BOS:311 application, which created base on Amazon Lex. The users could talk with the phone and submit a new report. That’s cool, right?
P.S: Priority is a big issue that is worth discussing more. Also, a different case should have a different weighted priority. And the default priority from 1 to 5 could be customized again.
Our Future Plan
Amazon Lambda - running background program.
Amazon S3 - storing case pictures.
Amazon Rekognition - analyze closed today case for detecting validation.
Amazon SNS - inform user the latest case status.
Amazon Cloud Formation - for future upgrade.
Contributions
This program is designed for BOS311 and related database. Basically:
- the AWS Chatbot, created by Gowtham Badu, will gain users’ input and send a JSON file to the background program.
- the background program, created by Zacks Shen, will detect the case then decide to UPDATE, INSERT our database or make a deeper analysis. The database request will send to AWS RDS in a JSON file.
- the AWS RDS, maintained by Deepak Prasad Baskaran, will receive the request from the background program then manipulate the database.
- the report and first version of the slides, was created by Jaswanth Satya Harsha Mattaparthy.
- the video, created by us together, was edited by Zacks Shen.
One more thing
Besides on the program itself, the article contains several crucial system design ideas and methods in Python and MySQL:
- How to read .csv files in dataframe style in Python.
- How to import text files such as .csv to the database in OS X.
- How to connect to MySQL server through Python.
- How to using Python manipulate MySQL.
- The ideas of handling users’ case.
- Checking the case validity.
- Saving system and human resource.
- Providing better follow-up services.
Offline Preparation
- Download dataset and Gather Information in Python
- Load data in MySQL
- Get columns name
- Modify the columns
- Add column
email
- Add column
priority
- Add column
If you do NOT have MySQL option file
(https://zacks.one/sql-tutorial/#2.3)
1. Gather data information in Python
1 | import pandas |
2. Load data in MySQL
Login to MySQL as root:
1 | mysql -u root -p |
Create database named bosbot
then use it:
1 | CREATE DATABASE bosbot; |
Create a table named “test” with the same columns as the csv file.
- Remember the data_type must be equal or longer than it in the text file.
1 | CREATE TABLE sample_311 ( |
Import your data from the text file to table sample_311
:
Remember copy your text file such as .csv to /tmp first
1 | LOAD DATA INFILE '/tmp/tmpr2k_j017.csv' |
If the system pops up the error: ERROR 1290 (https://zacks.one/sql-tutorial/#2.3)
Check the top 10 rows:
1 | SELECT * FROM sample_311 LIMIT 10 \G |
Compare it to the original file:
- Return to Python interface and input:
1 | bos311.head(10) |
Code Offline
Modules
Modules:
mysql.connector
: for connecting to MySQL.python3 -m pip install mysql-connector-python
- OR
conda install mysql-connector-python
datetime
: for requesting the date.
1 | # Import modules |
Code Part
1 | #!/usr/bin/env python3 |
Testing Part
Background Program Flow Chart:
The Background Program Flow Chart simulates the whole process from creating a case to manipulating our database. Once the user clicks Submit Report, he/she has to select a reason, which we need to classify the case. Then the user is required to provide the location to help us handle the case. Photo and description are optional. You can also leave your contact information. After updating the case status, we will inform you. Our Chatbot will record all the above information then send it to our Background program.
Here our Background program received all the information it needed. It will start to compare the new case to our existing cases. According to the reason, location, and date, we can make sure if it is a valid case. And the cased will be changed from Open to Closed when we complete your case. There are four situations:
Situation 1: The case is an absolute new case that is no similar to all of the cases stored in our database.
reason
= NOT samelocation
= OR NOT same- ACTION: INSERT Database; inform the user; return the case ID.
1 | # Situation 1: NOT duplicate case > INSERT Database |
1 | SELECT * FROM sample_311 WHERE case_title = "Situation 1" \G |
1 | mysql_UPDATE_case_status(case_status = "Closed") # Change the case_status of situation 1 from "Open" to "Closed" |
1 | SELECT * FROM sample_311 WHERE case_title = "Situation 1" \G |
Situation 2: The case is similar to an existing case. However, the existing case has been Closed days ago, which means things happen again. It should be a new case.
reason
= SAMElocation
= SAMEcase_status
= Closedopen_dt
= NOT today- ACTION: INSERT Database; inform the user; return the case ID.
1 | # Situation 2: duplicate case but closed several days ago > New case and INSERT database |
1 | SELECT * FROM sample_311 WHERE reason = "Enforcement & Abandoned Vehicles" AND location = "15 Sudbury St Boston MA 02203" \G |
Situation 3: The case is similar to an existing case. However, the existing case just has been Closed today, which means the new case might be the duplicate case. (Remember we just created a case today and closed it in Situation 1
.) For example, several users submit the same case; or the same case is submitted several times due to network or system error; or maybe things happen again. If so, we need to analyze it through AWS Rekognition and make a decision.
reason
= SAMElocation
= SAMEcase_status
= Closedopen_dt
= Today- ACTION: Analyze the case; inform the user.
1 | # Situation 3: # duplicate case but closed today > Analyze(Rekognition) |
1 | SELECT * FROM sample_311 WHERE reason = "Illegal Parking" AND location = "360 Huntington Ave Boston MA 02115" \G |
Situation 4: The case is similar to an existing case. However, the existing case is Open, which means it may be an urgent case. We should raise the priority of the case. And our priority is from 1 to 5.
reason
= SAMElocation
= SAMEcase_status
= Open- ACTION: UPDATE database. Raise the priority; Inform the user, return the case ID.
1 | # Situation 4: duplicate and open case > UPDATE priority |
1 | SELECT * FROM sample_311 WHERE priority != 1 \G |