-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.py
More file actions
80 lines (58 loc) · 1.8 KB
/
Copy pathApp.py
File metadata and controls
80 lines (58 loc) · 1.8 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# coding: utf-8
# In[28]:
import unicodedata
import os
import json
from matplotlib import pyplot as plt
import numpy as np
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
import StringIO
from flask import Flask, make_response, request, render_template, current_app
from custom_integrator import Integrator
from flask_cors import CORS
# In[35]:
app = Flask(__name__)
cors = CORS(app, resources={r"/plot*": {"origins": "https://drdave89.co.uk"}})
@app.route('/api.html',methods = ['GET'])
def api():
return render_template('api.html')
@app.route('/',methods = ['GET'])
def index():
return render_template('index.html')
@app.route('/scripts.js',methods = ['GET'])
def scripts():
return render_template('script.js')
@app.route('/plot', methods = ['POST'])
def plot():
global a
global b
data = request.data
dataDict = json.loads(data)
x0 = (float)(str(dataDict['x0Val']))
p0 = (float)(str(dataDict['p0Val']))
t0 = (float)(str(dataDict['t0Val']))
t1 = (float)(str(dataDict['t1Val']))
dt = (float)(str(dataDict['dtVal']))
function = str(dataDict['functionVal'])
print function
if (t1-t0)/dt > 5000.0:
dt = (t1-t0)/5000.0
integrator=Integrator(dt=dt,t0=t0,t1=t1,y0=[x0,p0],function=function)
integrator.integrate()
y=integrator.y
t=integrator.t
fig = Figure(facecolor='white')
axis = fig.add_subplot(1, 1, 1)
axis.plot(t,y)
canvas = FigureCanvas(fig)
output = StringIO.StringIO()
canvas.print_png(output)
response = make_response(output.getvalue().encode("base64"))
response.mimetype = 'image/png'
return response
# In[ ]:
if __name__ == '__main__':
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)
# In[ ]: