forked from nicholasbair/calc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.py
34 lines (22 loc) · 736 Bytes
/
calc.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
import falcon
import pandas as pd
class AuthMiddleware(object):
def process_request(self, req, resp):
token = req.get_header('Authorization')
if token is None:
raise falcon.HTTPUnauthorized('Unauthorized')
if not self._token_is_valid(token):
raise falcon.HTTPUnauthorized('Unauthorized')
def _token_is_valid(self, token):
token == os.environ.get('CALC_TOKEN')
class Ema(object):
def on_post(self, req, resp):
df_test = pd.DataFrame(req.media['data'])
df_test_ewma = df_test.ewm(alpha=0.1818).mean()
resp.status = falcon.HTTP_200
resp.body = (str(df_test_ewma.values.tolist()[-1][0]))
app = falcon.API(middleware=[
AuthMiddleware()
])
ema = Ema()
app.add_route('/ema', ema)