-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
118 lines (85 loc) · 3.07 KB
/
main.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from multiprocessing.pool import Pool
from flask import Flask
from dateutil import parser
from genetic import optimization
import logging
import util.targettransformer as tf
logging.basicConfig(filename='lstm_sized.log', filemode='w', level=logging.DEBUG)
# create logger
logger = logging.getLogger("Main")
logger.setLevel(logging.DEBUG)
# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter
formatter = logging.Formatter("%(asctime)s;%(levelname)s;%(message)s", "%Y-%m-%d %H:%M:%S")
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
logger.addHandler(ch)
app = Flask(__name__)
best_result = None
finished = False
@app.route('/')
def index():
return "Welcome: <a href='/start_computing'>Start</a>"
@app.route('/best')
def current_the_best():
return str(best_result)
@app.route('/status')
def status():
global finished
if finished:
return "Finished!"
else:
return "Not finished! Best: " + str(best_result)
@app.route('/start_computing')
def start_computing():
global best_result
best_result = optimization.BestIndividual()
start_date = parser.parse("2007-01-01")
end_date = parser.parse("2009-12-31")
start_test_date = parser.parse("2010-01-01")
end_test_date = parser.parse("2013-12-31")
pool = Pool(processes=1) # Start a worker processes.
opt = optimization.Optimization("msft", start_date, end_date, start_test_date, end_test_date, best_result,
target_extractor=tf.WILL_RISE)
result = pool.apply_async(opt.run, callback=callback)
#pop, log = optimization.run()
return 'Processamento Iniciado!'
@app.route('/start_regression')
def start_regression():
global best_result
best_result = optimization.BestIndividual()
start_date = parser.parse("2007-01-01")
end_date = parser.parse("2009-12-31")
start_test_date = parser.parse("2010-01-01")
end_test_date = parser.parse("2013-12-31")
pool = Pool(processes=1) # Start a worker processes.
opt = optimization.Optimization("msft", start_date, end_date, start_test_date, end_test_date, best_result,
target_extractor=tf.CLOSE)
result = pool.apply_async(opt.run, callback=callback)
#pop, log = optimization.run()
return 'Processamento Iniciado!'
def callback(pop, log):
global finished
logger.info(":Best of the best:")
logger.info(str(optimization.best_individual))
finished = True
@app.errorhandler(500)
def server_error(e):
logger.exception('An error occurred during a request.')
return """
An internal error occurred: <pre>{}</pre>
See logs for full stacktrace.
""".format(e), 500
if __name__ == '__main__':
# This is used when running locally. Gunicorn is used to run the
# application on Google App Engine. See entrypoint in app.yaml.
logger.info("Starting...")
try:
app.run(host='127.0.0.1', port=8080, debug=True)
except Exception as e:
logger.error(e)
logger.info("Finishing...")
# [END app]