Package: charlotte-traffic-analysis
CMPD Traffic Helper (Traffic Analysis for Charlotte, NC)CMPD Traffic Alerts service for persistence data and also any predictions/model analysis. Updater service as well as traditional ML model utilities.Goals of ProjectIdentify areas of improvement in Charlotte traffic flowIdentify problems areas, specific roads needing attentionIdentify least likelihood route from point A to point B of having an accidentProvide a web based area to allow suggested routing to minimize likelihood of an accidentAPIs used:Charlotte Mecklenburg Near-real time accident feedshttp://maps.cmpd.org/trafficaccidents/default.aspxOpenWeatherAPI weather location informationhttps://openweathermap.org/apiData 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 InstructionsThis project has 2 Python projectstraffic_analyzerandcmpd_accidents:cmpd_accidents is for persistence and storing accidents either as a callable script or through PyPItraffic_analyzer is for model creation/generationInstall locally:pip install .Install via PyPI:pip install charlotte-traffic-analysisHow to UseCurrent usage:Setup persistence for storing data (MongoDB or MySQL currently supported)Setup database or collections as "accidents"Setup OpenWeatherAPI account and API key
That's it! All other data is stored as reference data from the latest census information via Charlotte NCTo 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>)orpython 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-helperSetup 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 PersistenceIf 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:Relationalfrom 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 dataMongoDBfrom 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 dataTestspython setup.py testTo-DoCreate API to use CMPD SOAP Service for latest traffic accident dataSetup generic persistence for use of different databases (MySQL, etc.)Add integration testsSetup Travis CI integrationExploratory Data AnalysisAnalyze existing traffic prediction models and develop mock modelTest mock model and provide detailed transparencyUtilize created model to provide insight for current traffic patterns and informationCreate Python web service via hosting solution to call mock model and integrate with web portalFinalize and push Python package to PyPIFix any new bugsCreate web based portal with interactivityRelated R NotebookThis 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