-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f7267bd
commit aa59400
Showing
6 changed files
with
117 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters