-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
61 lines (48 loc) · 1.29 KB
/
server.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
import json
import time
from typing import Optional
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from data_access import get_data, get_data_for_pie, get_salary_data
app = FastAPI()
origins = [
"http://localhost",
"http://localhost:3000",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["GET"],
allow_headers=["*"],
)
@app.get("/")
async def read_root():
return {"Hello": "World"}
@app.get("/data/{country}")
async def read_data(country: Optional[str] = None):
begin = time.time()
result = await get_data(country)
parsed = json.loads(result.to_json(orient="records"))
return {
"time(secs)": (time.time() - begin),
"result": parsed,
}
@app.get("/pie")
async def make_pie(field: Optional[str] = "country"):
begin = time.time()
result = await get_data_for_pie(field)
parsed = json.loads(result.to_json())
return {
"time(secs)": (time.time() - begin),
"result": parsed,
}
@app.get("/salary-distribution")
async def make_pie():
begin = time.time()
result = await get_salary_data()
parsed = json.loads(result.to_json())
return {
"time(secs)": (time.time() - begin),
"result": parsed,
}