Skip to content

Commit

Permalink
hopefully AWS compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewDant committed Apr 9, 2019
1 parent f7267bd commit aa59400
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 121 deletions.
1 change: 1 addition & 0 deletions .ebignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
.idea/
__pycache__/
venv/
*.db
*.db
# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
93 changes: 93 additions & 0 deletions application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from flask import Flask, request, render_template
from datetime import datetime, timedelta
from models import db, Pressure # , Result
from k_nearest import *
import os
import json
import random

application = Flask(__name__)

application.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(
application.root_path, "post-chair.db"
)
# Suppress deprecation warning
application.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

db.init_app(application)

main()

if __name__ == "__main__":
application.run(threaded=True)


@application.route("/")
def index():
return render_template("index.j2")


@application.route("/input/", methods=["POST"])
def data_input():
data_json = request.get_json()

back_score = generate_score([data_json['back_left'], data_json['back_right'], data_json['back_bottom']])
seat_score = generate_score([data_json['seat_left'], data_json['seat_right'], data_json['seat_rear']])

# TODO real classification
p1 = Pressure(timestamp=datetime.now(), back_left=data_json['back_left'], back_right=data_json['back_right'],
back_bottom=data_json['back_bottom'],
seat_left=data_json['seat_left'], seat_right=data_json['seat_right'],
seat_rear=data_json['seat_rear'], back_score=back_score, seat_score=seat_score,
classification="Good Posture")

db.session.add(p1)
db.session.commit()

return json.dumps(p1.serialize())


@application.route("/data/")
def data():
new_data = Pressure(timestamp=datetime.now(), back_left=random.randint(0, 1023),
back_right=random.randint(0, 1023), back_bottom=random.randint(0, 1023),
seat_left=random.randint(0, 1023), seat_right=random.randint(0, 1023),
seat_rear=random.randint(0, 1023), back_score=random.uniform(0, 50),
seat_score=random.uniform(0, 50),
classification=random.choice(["Good Posture", "Bad Posture"]))
db.session.add(new_data)
db.session.commit()

num_minutes = int(request.args.get('minutes'))
time_offset = datetime.now() - timedelta(minutes=num_minutes)

data_list = db.session.query(Pressure).filter(Pressure.timestamp > time_offset) \
.order_by(Pressure.timestamp.asc()).all()

return json.dumps([d.serialize() for d in data_list])


@application.cli.command("initdb")
def init_db():
db.drop_all()
db.create_all()
print("Initialized default DB")


@application.cli.command("bootstrap")
def bootstrap_data():
db.drop_all()
db.create_all()

for _ in range(0, 10):
p1 = Pressure(timestamp=datetime.now(), back_left=random.randint(0, 1023),
back_right=random.randint(0, 1023), back_bottom=random.randint(0, 1023),
seat_left=random.randint(0, 1023), seat_right=random.randint(0, 1023),
seat_rear=random.randint(0, 1023), back_score=random.uniform(0, 50),
seat_score=random.uniform(0, 50),
classification=random.choice(["Good Posture", "Bad Posture"]))
db.session.add(p1)

db.session.commit()

print("Added bootstrap data")
102 changes: 0 additions & 102 deletions main.py

This file was deleted.

32 changes: 16 additions & 16 deletions new_req.txt → requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Flask==1.0.2
Jinja2==2.10
Flask-SQLAlchemy==2.3.2
cycler==0.10.0
kiwisolver==1.0.1
matplotlib==3.0.3
numpy==1.16.2
pandas==0.24.1
pyparsing==2.3.1
python-dateutil==2.8.0
pytz==2018.9
scikit-learn==0.20.3
scipy==1.2.1
seaborn==0.9.0
six==1.12.0
sklearn==0.0
Flask==1.0.2
Jinja2==2.10
Flask-SQLAlchemy==2.3.2
cycler==0.10.0
kiwisolver==1.0.1
matplotlib==3.0.3
numpy==1.16.2
pandas==0.24.1
pyparsing==2.3.1
python-dateutil==2.8.0
pytz==2018.9
scikit-learn==0.20.3
scipy==1.2.1
seaborn==0.9.0
six==1.12.0
sklearn==0.0
4 changes: 2 additions & 2 deletions templates/index.j2
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<div class="row">
<div class="col-md-12 col-lg-6">
<div class="card bg-light text-center chair-card">
<span class="card-header chair-header">Current Pressue Readings (Volts)</span>
<span class="card-header chair-header">Current Pressue Readings</span>
<div class="card-body">
<div class="chair-container">
{# TODO these styles are NOT responsive currently #}
Expand All @@ -97,7 +97,7 @@
</div>
<div class="col-md-12 col-lg-6">
<div class="card bg-light text-center chair-card">
<span class="card-header chair-header">Average Pressue Readings (Volts)</span>
<span class="card-header chair-header">Average Pressue Readings</span>
<div class="card-body">
<div class="chair-container">
{# TODO these styles are NOT responsive currently #}
Expand Down

0 comments on commit aa59400

Please sign in to comment.