-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
56 lines (43 loc) · 1.83 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from flask import Flask, render_template, Response, request
import json
import pandas as pd
from data import dataHandler
def createResponse(status, message):
"""returns flask Response object"""
if type(message) in (str, list):
message = json.dumps(message)
elif type(message) == pd.DataFrame:
message = message.to_json(date_format='iso', orient='records')
return Response(message, status=status, mimetype='application/json')
app = Flask(__name__, static_url_path='/static')
@app.route("/")
def createPatterns():
return render_template('index.html')
@app.route("/initData", methods=['POST'])
def initData():
try:
dataHandler.init(request.json)
return createResponse(200, "Data connection successfully initialized!")
except Exception as error:
print(error)
return createResponse(400, "Error during initiating data connection! %s" % error)
@app.route("/loadNewData", methods=['GET'])
def loadNewData():
try:
return createResponse(200, dataHandler.load(request.args.get('dtLimit'), request.args.get('dir')))
except Exception as error:
print(error)
return createResponse(400, "Error during loading new data! %s" % error)
@app.route("/savePattern", methods=['POST'])
def savePattern():
try:
dataHandler.savePattern(request.json['startDt'], request.json['stopDt'], request.json['dir'])
return createResponse(200, "New pattern was successfully saved!")
except Exception as error:
print(error)
return createResponse(400, "Error during saving new pattern! %s" % error)
@app.route("/loadPatterns", methods=['GET'])
def loadPatterns():
return createResponse(200, dataHandler.loadPatterns())
if __name__ == "__main__":
app.run(debug=True, port=5002)