Commit 2c624f61 authored by Neranga K.T.'s avatar Neranga K.T.

.

parent 9811d84b
......@@ -4,6 +4,13 @@ from keras.layers import Dense,Dropout
from keras.models import Sequential
import keras.backend as K
#creating the tables using sqlalchemy
from flask_sqlalchemy import SQLAlchemy
import datetime
#serialize and deserialize data
from flask_marshmallow import Marshmallow
scaler_x = joblib.load('scaler_x.pkl')
scaler_y = joblib.load('scaler_y.pkl')
......@@ -53,4 +60,67 @@ def get_level():
results=[{"level":float(result)}]
return (jsonify(results=results))
app.run(host='0.0.0.0',port=5000)
userpass = 'mysql://root:''@'
basedir = '127.0.0.1'
dbname = '/helply'
socket = '?unix_socket=/opt/lampp/var/mysql/mysql.sock'
dbname = dbname + socket
app.config['SQLALCHEMY_DATABASE_URI'] = userpass + basedir + dbname
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
#DB Connection
db = SQLAlchemy(app)
#crate a object of marshmallow
ma = Marshmallow(app)
#creating the table
class MemoryResults(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(20))
age = db.Column(db.String(10))
game_level = db.Column(db.String(50))
time_duration = db.Column(db.Float())
result = db.Column(db.String(20))
date = db.Column(db.DateTime, default = datetime.datetime.now)
def __init__(self, name, age, game_level, time_duration, result):
self.name = name
self.age = age
self.game_level = game_level
self.time_duration = time_duration
self.result = result
#for serializing and deserializing , create the schema
#create Results schema
class ResultsSchema(ma.Schema):
class Meta:
fields = ('id', 'name', 'age', 'game_level', 'time_duration', 'result', 'date') # fields to serialize
result_schema = ResultsSchema()
results_schema = ResultsSchema(many=True)
#add results => POST method
@app.route('/add', methods = ['POST'])
def add_result():
# title = request.json['title']
# body = request.json['body']
name = request.json['name']
age = request.json['age']
game_level = request.json['game_level']
time_duration = request.json['time_duration']
result = request.json['result']
#object of class table
results = MemoryResults(name, age, game_level, time_duration, result)
#add to the db
db.session.add(results)
#commit to the db
db.session.commit()
return result_schema.jsonify(results)
#run the flask file
if __name__ == "__main__":
# app.run(debug=True)
app.run(host='0.0.0.0', port=5000, debug=True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment