-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcovid19_endpoint.py
62 lines (39 loc) · 1.42 KB
/
covid19_endpoint.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
# coding: utf-8
# In[3]:
from flask import Flask, jsonify, request
from flask_cors import CORS, cross_origin
import pandas as pd
import numpy as np
# In[4]:
access_count = 0
# In[3]:
app = Flask(__name__)
CORS(app)
@app.route("/katana-ml/api/v1.0/forecast/covid19", methods=['POST'])
def forecast():
global access_count
access_count += 1
country = request.json['country']
df = pd.read_csv('data/covid19_forecast_data_' + country + '.csv', parse_dates=True)
df = df.drop(df.columns[[0]], axis=1)
result = df.to_json(orient='records', date_format='iso')
return result
@app.route("/katana-ml/api/v1.0/forecast/covid19/stats", methods=['GET'])
def stats():
df = pd.read_csv('data/covid19_stats_countries.csv', parse_dates=True)
df = df.drop(df.columns[[0]], axis=1)
result = df.to_json(orient='records', date_format='iso')
return result
@app.route("/katana-ml/api/v1.0/forecast/covid19/count", methods=['GET'])
def accecc_count():
global access_count
return str(access_count)
@app.route("/katana-ml/api/v1.0/forecast/covid19/countries", methods=['GET'])
def get_countries():
df = pd.read_csv('data/covid19_countries_list.csv')
df = df.drop(df.columns[[0]], axis=1)
result = df.to_json(orient='records', date_format='iso')
return result
# running REST interface port=5001
if __name__ == "__main__":
app.run(debug=False, host='0.0.0.0', port=5001)