/
web_app.py
96 lines (80 loc) · 3.26 KB
/
web_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
from flask import Flask, render_template, request
from bokeh.plotting import figure
from bokeh.embed import components
from visualization import Visualization
from interpreter_final import Interpreter
from socket import gethostname
app = Flask(__name__)
@app.route('/')
def hello(): #welcome page
return render_template('index.html')
@app.route('/home')
def hello_world(): #also welcome page
return render_template('index.html')
@app.route('/predict')
def predict(): #page talks about our algorithm
return render_template('predict.html')
@app.route('/about')
def about(): #about us
return render_template('about.html')
@app.route('/acknow')
def ack(): #thank you page
return render_template('acknowledgements.html')
@app.route('/test')
def testing():
return render_template('testingPromo.html')
@app.route('/result/', methods=['POST', 'GET'])
def result():
error = None
script = ''
div = {}
if request.method == 'POST':
result = request.form
for key, val in result.items():
if key == 'prod':
prod = val
elif key == 'timeWindow':
time = val
print(type(time))
if time == '' or prod == '': # checks to see if user filled everything in
error = 'Please fill in all fields.'
script = ' '
div = {}
cheapest_dates = ""
elif time.isdigit() and int(time)>=80 and int(time)<=3650: #checks to see if input is a number and in the proper range
if prod == 'Oil' and time != '':
myinterpreter = Interpreter('oil_prices', int(time))
myinterpreter.differencing()
myinterpreter.create_acf()
myinterpreter.get_p_and_q()
myinterpreter.build_model()
data = myinterpreter.get_data_source()
visualization = Visualization(data)
plot = visualization.get_graph2()
cheapest_dates = visualization.find_lowest_prices()
script, div = components(plot)
elif prod == 'Electricity' and time != '':
myinterpreter = Interpreter('avg_elec_price', int(time))
myinterpreter.differencing()
#myinterpreter.test_stationarity()
myinterpreter.create_acf()
myinterpreter.get_p_and_q()
myinterpreter.build_model()
data = myinterpreter.get_data_source()
visualization = Visualization(data)
cheapest_dates = visualization.find_lowest_prices()
plot = visualization.get_graph2()
script, div = components(plot)
else:
error = "Please type your specified time period as a number between 80 and 3650."
script = ' '
div = {}
cheapest_dates = ""
return render_template("result.html", prod=prod, time=time,
error=error, script=script, div=div, cheapest_dates = cheapest_dates)
if __name__ == '__main__':
if 'liveconsole' not in gethostname():
HOST = '0.0.0.0' if 'PORT' in os.environ else '127.0.0.1'
PORT = int(os.environ.get('PORT', 5000))
app.run(host=HOST, port=PORT)