/
run.py
51 lines (40 loc) · 1.32 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
import forecast
import rforest
import poldb
from flask import Flask, json
from decorators import crossdomain
from bson import json_util
application = Flask(__name__)
application.debug = True
@application.route('/')
def hello_world():
return "Hello world!"
@application.route('/forecast')
@crossdomain(origin='*')
def index():
# upon user request, lets call the twitter api, and see if the last time
# is the one in the db (last time not including 24 hour summaries)
# if its in the db, return that row, otherwise, build out the predictions
# on the other hand, lets make predictions as a cron job every 60 minutes,
# and just simply return the latest row to the user
forest = rforest.forest(train=False)
frcast = forecast.forecast(forest.X_train.columns, forest.rf)
return json.jsonify(frcast.df)
# lets grab the latest row of predictions
@application.route('/getLatest')
@crossdomain(origin='*')
def getLatest():
db = poldb.Poldb()
return json.jsonify(db.getLatestPol())
# @application.route('/getErrors')
# @crossdomain(origin='*')
# def getErrors():
# db = poldb.Poldb()
# return json.jsonify(db.getErrors())
@application.route('/getLatestErrors')
@crossdomain(origin='*')
def getLatestErrors():
db = poldb.Poldb()
return json_util.dumps(db.getLatestErrors())
if __name__ == '__main__':
application.run(debug=True)