Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

jayArnel/crimemapping

Repository files navigation

Crime Modeling and Prediction

Libraries

NOTE: Some of this libraries may fail to install depending on the ubuntu version you have on your machine.

sudo apt-get install binutils libproj-dev postgresql-9.4-postgis-2.1 postgresql-server-dev-9.4 postgresql-contrib-9.4 libatlas-base-dev libblas-dev

Clone

git clone git@github.com:jayArnel/crimemapping.git
cd crimemapping

Create Virtualenv

sudo pip install virtualenvwrapper
mkvirtualenv <name>
workon <name>

Install Package Dependencies

pip install -r requirements.txt

Create the Database

sudo su - postgres
createdb <dbname>

Create User for the Database

sudo su - postgres 
createuser -s -P <username>
    *setup password*
psql
GRANT ALL PRIVILEGES ON DATABASE <dbname> TO <username>;

Extend Database to postgis

sudo su - postgres 
psql <dbname>
CREATE EXTENSION postgis;

Setup Database with Django

create local_settings.py file in crimemapping folder

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': '<dbname>',
        'USER': '<username>',
        'PASSWORD': '<password>',
        'HOST': 'localhost',
        'PORT': '',
    }
}

Run Migrations

make sure your virtualenv <env> is activated by calling workon <env>

python manage.py migrate

Collect static files

python manage.py collectstatic -l --no-input

Setup Nginx

setup a local server in your machine via Nginx

Install nginx

sudo apt-get install nginx

Setup Nginx configuration

create configuration file

sudo nano /etc/nginx/sites-available/crimemapping

copy-paste configuration

upstream localhost {
    server localhost:8000;
}
server {
    listen 0.0.0.0:80;
    server_name localhost;

    keepalive_timeout 5;
    # path for static files
    root /path/to/project/storage; #! important! update this path
    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        if (!-f $request_filename) {
            proxy_pass http://localhost;
            break;
        }
    }
}

enable configuration

sudo ln -s /etc/nginx/sites-available/crimemapping /etc/nginx/sites-enabled/crimemapping
``
check for errors, then restart nginx
``` nginx
sudo nginx -t
sudo service nginx restart

Starting the Web App

python manage.py runserver

Open 'localhost' on your web browser

Running the Model

python manage.py shell
from crimeprediction import network

network.run_network(1000, 'monthly', crime_type=None, seasonal=True)