-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
71 lines (55 loc) · 2 KB
/
app.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from flask import Flask, render_template, request
from CurrencyConv import Conv
from PiCalc import compute
from PiCalc import PiCalc
from model import InputForm
from model import CurrForm
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/picalc')
def picalc():
return render_template('PiCalc.html')
@app.route("/computeResult", methods=['GET', 'POST'])
def computeResult():
form = InputForm(request.form)
numTerms = 0
approximation = 0
if request.method == 'POST' and form.validate():
result = compute(form.decimalPlaces.data, form.speed.data)
obj = PiCalc(int(form.decimalPlaces.data))
numTerms = 0
approximation = 0
if (form.speed.data == "Fast"):
numTerms = obj.getNumberTermsMachinApprox()
print(numTerms)
approximation = obj.fast_pi_approximation()
print(approximation)
else:
numTerms = obj.getNumberTermsSlowApprox()
print(numTerms)
approximation = obj.calculation_slow_approx()
print(approximation)
else:
result = None
return render_template("PiCalc.html", form=form, result=result, numTerms=numTerms, approximation=approximation)
@app.route("/CurrencyConv")
def currConv():
return render_template("CurrencyConv.html")
@app.route("/computeConv", methods=['GET', 'POST'])
def computeConv():
form = CurrForm(request.form)
baseCurr = form.baseCurr.data
targetCurr = form.targetCurr.data
amount = form.baseCurrAmount.data
obj = Conv(baseCurr, targetCurr, amount)
resultAmount = obj.urlResponse()
my_string = '{:,.2f}'.format(resultAmount)
return render_template("CurrencyConv.html", form=form, baseCurrAmount=amount, baseCurr=baseCurr,
targetValue=my_string, targetCurr=targetCurr)
@app.route("/monteCarlo")
def monteCarlo():
return render_template("PiApproxMonteCarlo.html")
if __name__ == '__main__':
app.run(debug=True)