{"id":22357272,"url":"https://github.com/mdh266/crimetime","last_synced_at":"2025-07-30T10:33:03.697Z","repository":{"id":93022684,"uuid":"74296750","full_name":"mdh266/CrimeTime","owner":"mdh266","description":"Python web application for exploring and forecasting crime rates in NYC","archived":false,"fork":false,"pushed_at":"2019-02-26T02:07:07.000Z","size":7977,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-11T17:53:58.139Z","etag":null,"topics":["data-science","docker","flask-application","forecasting-crime-rates","geospatial-analysis","pandas","python","statsmodels","time-series-analysis"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mdh266.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-11-20T19:17:26.000Z","updated_at":"2023-11-27T04:23:53.000Z","dependencies_parsed_at":"2023-03-08T11:00:43.724Z","dependency_job_id":null,"html_url":"https://github.com/mdh266/CrimeTime","commit_stats":{"total_commits":107,"total_committers":4,"mean_commits":26.75,"dds":"0.11214953271028039","last_synced_commit":"ae3255eb16aa3ee46be61a61c728a020ec66f408"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdh266%2FCrimeTime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdh266%2FCrimeTime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdh266%2FCrimeTime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdh266%2FCrimeTime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mdh266","download_url":"https://codeload.github.com/mdh266/CrimeTime/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228124574,"owners_count":17873170,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-science","docker","flask-application","forecasting-crime-rates","geospatial-analysis","pandas","python","statsmodels","time-series-analysis"],"created_at":"2024-12-04T14:13:45.529Z","updated_at":"2024-12-04T14:13:46.821Z","avatar_url":"https://github.com/mdh266.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CrimeTime\n---------------------\n\n## Introduction \n---------------------\n\nThis web application was part of a 3 week project at \u003ca href=\"http://insightdatascience.com/\"\u003eInsight Data Science\u003c/a\u003e.  I originally started this project because I was interested in developing a data driven approach to reducing crime in the NYC area.  Working on this project I quickly noticed that different neighborhoods are affected by different types of crime and these crimes peak at different times of the year (you can see this \u003ca href=\"http://michael-harmon.com/blog/crimetime.html\"\u003eblog post\u003c/a\u003e to read more).  I thought if I could make a web application that forecasts monthly crime rates on a local level it might help police redistribute their resources more effectively and thus reduce the crime in NYC.  The applicaiton could also be of interest to individuals or business who are concerned about crime rates in their neighborhood.  \n\nThe application prompts to enter an address from the input page seen below:\n\t\n\n![Input Page](./doc/input.png)\n\n\nAnd they get back a report on the historical trends of crimes in their neighborhood:\n\n\t\n![All Crime Info](./doc/Historical.png)\n\nUsers can select specific crimes in their neighborhood and get the historical trend, seasonality, as well as which days and times most of these crimes happen.  The results for assault are shown below:\n\n\t\n![Specific Crime Info](./doc/Dashboard.png)\n\nUsers can also choose to forecast specific crime rates into the future.\n\n\n## How It works\n---------------------\n\n**The source code can be found \u003ca href=\"https://github.com/mdh266/CrimeTime\"\u003ehere\u003c/a\u003e.**\n\n\nThis code was written using \u003ca href=\"https://www.python.org/\"\u003e Python\u003c/a\u003e and \u003ca href=\"http://flask.pocoo.org/\"\u003e Flask\u003c/a\u003e\nand deployed to \u003ca href=\"https://aws.amazon.com/\"\u003e Amazon web services.\u003c/a\u003e Users are prompted to enter an address and then I use the \u003ca href=\"https://pypi.python.org/pypi/geopy\"\u003egeopy\u003c/a\u003e library to get\nthe latitude and longitude of the address.  Once that latitude and longitude are known I \nuse the \u003ca href=\"https://pypi.python.org/pypi/Shapely\"\u003eshapely\u003c/a\u003e library to find out which police \nprecinct the address is in and obtain the data on that police precinct.\n\nThe info for police precincts was obtained by scraping the NYPD's \n\u003ca href=\"http://www.nyc.gov/html/nypd/html/home/precincts.shtml\"\u003e website \u003c/a\u003e using the\n\u003ca href=\"https://pypi.python.org/pypi/beautifulsoup4\"\u003e beautifulsoup\u003c/a\u003e library and \nalso this specific\n \u003ca href=\"https://nycopendata.socrata.com/Public-Safety/Police-Precincts/78dh-3ptz/data\"\u003edatabase\u003c/a\u003e. The historical crime data was obtained from the \u003ca href=\"https://nycopendata.socrata.com/\"\u003eNYC Open Data Website\u003c/a\u003e \nand cleaning was completed using \u003ca href=\"http://pandas.pydata.org/\"\u003ePandas\u003c/a\u003e and\n\u003ca href=\"http://geopandas.org/\"\u003eGeoPandas\u003c/a\u003e. The data was then stored in a \n\u003ca href=\"https://sqlite.org/\"\u003eSQLite\u003c/a\u003e database. Forecasted crime rates were predicted using a \n\u003ca href=\"http://www.statsmodels.org/dev/generated/statsmodels.tsa.statespace.sarimax.SARIMAX.html\"\u003eseasonal ARIMA\u003c/a\u003e\nmodel through the Python library \u003ca href=\"http://statsmodels.sourceforge.net/\"\u003e StatsModels\u003c/a\u003e. \nI used a grid search to obtain the appropriate model paramaters with the selection criteria that the choice of parameters must minimize the validation error.\n\n\n## Running it on your own computer\n---------------------\n\nTo run this web application on your computer, please email me to obtain the SQLite\ndatabase and install all the necessary dependencies on you computer.  You can install all the depencies using \u003ca href=\"https://www.docker.com/\"\u003eDocker\u003c/a\u003e by running the following commands from the \u003ccode\u003eCrimeTime/\u003c/code\u003e directory:\n\n\tdocker build -t crimetime . \n\nYou can then run the application with the command,\n\n\tdocker run -id p 5000:5000 crimetime\n\nThen enter the address http://0.0.0.0:5000/ into your web browser to use the web application.\n\nAlternatively you can use the  \u003ca href=\"https://www.continuum.io/anaconda-overview\"\u003eAnaconda\u003c/a\u003e distribution and create an virtual environment using the \u003ccode\u003eenvironment.yml\u003c/code\u003e file as described \u003ca href=\"https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file\"\u003ehere\u003c/a\u003e.  And then run the following command from the \u003ccode\u003eCrimeTime/\u003c/code\u003e directory:\n\n\tpython tornadoapp.py\n\nand go to the address http://0.0.0.0:5000/ in your web browser.\n\n\n\n## Building the database\n---------------------\n\nTo build the database on your local machine first download the file \"NYPD_7_Major_Felony_Incident_Map.csv\" from the NYC Open Data website and\nplace it in the \u003ccode\u003eCrimeTime/data/\u003c/code\u003e directory. Then making sure you have all the necessary dependencies installed on your computer (see above) and type the folowing command into your terminal from the \u003ccode\u003eCrimeTime/\u003c/code\u003e directory,\n\n\tpython ./backend/PreProcessor.py\t\n\n\n**NOTE: If NYC Open Data no longer has the file on their website, please email me and I will provide you with the database.**\n\n\n## Testing\n---------------------\n\nTo test the code to make sure it works run the following command in your terminal shell from the \u003ccode\u003e/CrimeTime/\u003c/code\u003edirectory:\n\n\tpy.test tests\t\n\nYou will then see a report on the testing results.\n\n## Documentation\n---------------------\n\nTo build the documentation for this code type the following command in terminal from \u003ccode\u003e/CrimeTime/\u003c/code\u003e directory:\n\n\tsphinx-apidoc -F -o doc/ backend/\nThen cd into the \u003ccode\u003edoc/\u003c/code\u003e directory and type,\n\n\tmake html\n\nThe html documentation will be in the directory \u003ccode\u003e_build/html/\u003c/code\u003e.  Open the file \u003ccode\u003eindex.html\u003c/code\u003e in that directory.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdh266%2Fcrimetime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmdh266%2Fcrimetime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdh266%2Fcrimetime/lists"}