Skip to content

Commit

Permalink
added nginx to install script
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Nov 23, 2016
1 parent bc43700 commit 81611ab
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.pyc
.ipynb_checkpoints

nflenv*
2 changes: 1 addition & 1 deletion app.conf → nfl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ setgid www-data

env PATH=/home/ubuntu/nfl/nflenv/bin
chdir /home/ubuntu/nfl
exec uwsgi --ini app.ini
exec uwsgi --ini nfl.ini
5 changes: 1 addition & 4 deletions app.ini → nfl.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
[uwsgi]
module = wsgi

[uwsgi]
module = wsgi

master = true
processes = 5

socket = app.sock
socket = nfl.sock
chmod-socket = 660
vacuum = true

Expand Down
9 changes: 9 additions & 0 deletions nfl_nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
server {
listen 80;
server_name 127.0.0.1;

location / {
include uwsgi_params;
uwsgi_pass unix:/home/ubuntu/nfl/nfl.sock;
}
}
76 changes: 37 additions & 39 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,6 @@
import random
import os


'''
==================================
GLOBALS
==================================
'''
# register this as 'app'
app = Flask(__name__)

# load the current model
model_filename = os.path.join(os.path.dirname(__file__), '../data/gbc-v6.pkl')
with open(model_filename, 'r') as f:
model = pickle.load(f)

# set the model version
model_version = 'gbc-v6'

# for now, just use a file to store confusion matrices
user_cm_file = 'data/user_cm.csv'
model_cm_file = 'data/model_cm.csv'
cm_index_dict = {'PASS':0, 'RUSH':1, 'KICK':2}
pred_dict = {1:'PASS', 2:'RUSH', 0:'KICK'}

# filename where the data is located
data_filename = 'data/pbp-validation.csv'

'''
==================================
HELPER FUNCTIONS
Expand Down Expand Up @@ -101,13 +75,43 @@ def compute_accuracy(cm):
else:
return num_right / cm.sum()


'''
==================================
GLOBALS
==================================
'''
# register this as 'app'
nfl = Flask(__name__)

# load the current model
model_filename = os.path.join(os.path.dirname(__file__), '../data/gbc-v6.pkl')
with open(model_filename, 'r') as f:
model = pickle.load(f)

# set the model version
model_version = 'gbc-v6'

# for now, just use a file to store confusion matrices
user_cm_file = os.path.join(os.path.dirname(__file__), '../data/user_cm.csv')
model_cm_file = os.path.join(os.path.dirname(__file__), '../data/model_cm.csv')
cm_index_dict = {'PASS':0, 'RUSH':1, 'KICK':2}
pred_dict = {1:'PASS', 2:'RUSH', 0:'KICK'}
user_cm, model_cm = create_confusion_matrices()

# read in the cleaned data
data_filename = os.path.join(os.path.dirname(__file__), '../data/pbp-validation.csv')
pbp = pd.read_csv(data_filename)



'''
==================================
Flask methods
==================================
'''
# home page
@app.route('/')
@nfl.route('/')
def home_page():

record = get_a_play()
Expand All @@ -123,7 +127,7 @@ def home_page():
return render_template('home.html', data=data)

# about the author page
@app.route('/author')
@nfl.route('/author')
def author_page():

data = {}
Expand All @@ -132,7 +136,7 @@ def author_page():
return render_template('author.html', data=data)

# about the project page
@app.route('/project')
@nfl.route('/project')
def project_page():

data = {}
Expand All @@ -141,7 +145,7 @@ def project_page():
return render_template('project.html', data=data)

# about the author page
@app.route('/field')
@nfl.route('/field')
def field():

data = {}
Expand All @@ -151,7 +155,7 @@ def field():


# get just the confusion matrices
@app.route('/get_accuracy')
@nfl.route('/get_accuracy')
def get_accuracy():

# prep the data for the template
Expand All @@ -168,7 +172,7 @@ def get_accuracy():

# Log the user guesses. Test with:
# curl -H "Content-Type: application/json" -X POST -d '@src/static/example.json' http://localhost:8080/guess
@app.route('/guess', methods=['POST'])
@nfl.route('/guess', methods=['POST'])
def guess():

# pull the request data
Expand Down Expand Up @@ -197,11 +201,5 @@ def guess():
'''
if __name__ == '__main__':

# read in the cleaned data
pbp = pd.read_csv(data_filename)

# read in the confusion matrix data
user_cm, model_cm = create_confusion_matrices()

# run the app
app.run(host='0.0.0.0', port=80, debug=False)
nfl.run(host='0.0.0.0', port=80, debug=False)
5 changes: 3 additions & 2 deletions src/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ source nflenv/bin/activate
pip install scipy scikit-learn pandas numpy requests Flask
deactivate

sudo cp app.conf /etc/init/.

sudo cp nfl.conf /etc/init/.
sudo cp nfl_nginx /etc/nginx/sites-available/nfl
sudo ln -s /etc/nginx/sites-available/nfl /etc/nginx/sites-enabled

4 changes: 2 additions & 2 deletions wsgi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src.app import app
from src.app import nfl

if __name__ == "__main__":
app.run()
nfl.run()

0 comments on commit 81611ab

Please sign in to comment.