Skip to main content

Charlotte-metro traffic analysis helper including predictions, travel paths, and more

Project description

CMPD Traffic Helper (Traffic Analysis for Charlotte, NC)

Build Status Python 3.4 Python 3.5 Python 3.6 License: MIT

CMPD Traffic Alerts service for persistence data and also any predictions/model analysis. Updater service as well as traditional ML model utilities.

Goals of Project

  • Identify areas of improvement in Charlotte traffic flow
  • Identify problems areas, specific roads needing attention
  • Identify least likelihood route from point A to point B of having an accident
  • Provide a web based area to allow suggested routing to minimize likelihood of an accident

APIs used:

Data used:

  • CMPD Traffic Accidents (Accident information)
  • NC-DOT ARC GIS (Road features)
  • Charlotte Open Data Portal (Traffic volumes, population, traffic signals, spatial features)
  • Live weather stats (OpenWeatherAPI)

Install Instructions

This project has 2 Python projects traffic_analyzer and cmpd_accidents:

  • cmpd_accidents is for persistence and storing accidents either as a callable script or through PyPI
  • traffic_analyzer is for model creation/generation

Install locally:

pip install .

Install via PyPI:

pip install charlotte-traffic-analysis

How to Use

Current usage:

  1. Setup persistence for storing data (MongoDB or MySQL currently supported)
  2. Setup database or collections as "accidents"
  3. Setup OpenWeatherAPI account and API key That's it! All other data is stored as reference data from the latest census information via Charlotte NC

To check for current accidents and store them in your persistence:

import cmpd_accidents as cmpd
cmpd.update_traffic_data(<MongoDB host>, <MongoDB port>, <OpenWeather api key>) 

or

python main.py <MongoDB host> <MongoDB port> <OpenWeather api key>

It is preferable to setup a job-type service to run the API incrementally over time. Using cron via -nix type systems: Clone the current repo:

git clone https://github.com/dillonmabry/cmpd-traffic-helper

Setup cron job to run every 5 minutes:

crontab -e
*/5 * * * * cd <your-repo-location>/cmpd_accidents && sudo python3 main.py mongodb://<user>:<password>@<host>/<databasename> <port> <OpenWeather api key>

Note on Persistence

If you would rather use a relational persistence such as MySQL, the interface is already available for SQLAlchemy connect via the database module. Simply replace the "collection" argument with "table" for relational persistence. Seed scripts are available in resources/db feel free to replace with what table columns you prefer.

Persistence swap example:

Relational

from cmpd_accidents import SQLAlchemyConnect
db = SQLAlchemyConnect(connection_string='mysql+pymysql://<user>:<password>@<host>/<database>')
with self.database as db:
            exist_events = db.find_ids(table="accidents", ids=current_ids, cursor_limit=500)
with self.database as db:
                db.insert_bulk(table="accidents", items=final_data) # persist data

MongoDB

from cmpd_accidents import MongoDBConnect
db = MongoDBConnect(host='mongodb://<user>:<password>@<host>/<database>', port=27017)
with self.database as db:
            exist_events = db.find_ids(collection="accidents", ids=current_ids, cursor_limit=500)
with self.database as db:
                db.insert_bulk(collection="accidents", items=final_data) # persist data

Tests

python setup.py test

To-Do

  • [X] Create API to use CMPD SOAP Service for latest traffic accident data
  • [X] Setup generic persistence for use of different databases (MySQL, etc.)
  • [X] Add integration tests
  • [X] Setup Travis CI integration
  • [X] Exploratory Data Analysis
  • [X] Analyze existing traffic prediction models and develop mock model
  • [ ] Test mock model and provide detailed transparency
  • [ ] Utilize created model to provide insight for current traffic patterns and information
  • [ ] Create Python web service via hosting solution to call mock model and integrate with web portal
  • [ ] Finalize and push Python package to PyPI
  • [ ] Fix any new bugs
  • [ ] Create web based portal with interactivity

Related R Notebook

This project was initially created via R and converted as best as possible to Python/Sklearn after decision to use Python to support model calling would be easier via web

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for charlotte-traffic-analysis, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size charlotte_traffic_analysis-0.1.3.tar.gz (5.6 MB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page