-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.py
More file actions
58 lines (45 loc) · 2.02 KB
/
api.py
File metadata and controls
58 lines (45 loc) · 2.02 KB
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
from typing import Union
from fastapi import FastAPI
from test_augment import test
from starlette.responses import RedirectResponse
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles
from datetime import datetime
from area import AreaManager, ShadowAreaManager, Polygon, RouteResult, get_route
app = FastAPI()
area_manager = AreaManager()
shadow_manager = ShadowAreaManager()
@app.get("/api/prepare_area")
def prepare_area(startlat: float, startlon: float, endlat: float, endlon: float) -> dict[str, str | list[Polygon]]:
start = (startlat, startlon)
end = (endlat, endlon)
area = area_manager.new(start, end)
return {"id": area.id, "buildings": area.get_buildings()}
@app.get("/api/get_shadows")
def get_shadows(area_id: str, time: datetime) -> None:
area = shadow_manager.new(area_manager.get(area_id), time)
return {"id": area.id, "shadows": area.get_shadows()}
@app.get("/api/route")
def route(shadow_id: str, startlat: float, startlon: float, endlat: float, endlon: float) -> None:
shadow = shadow_manager.get(shadow_id)
area = area_manager.get(shadow.area_id)
return get_route(area, shadow, (startlat, startlon), (endlat, endlon))
@app.get("/api/test_augment")
def test_augment(prefix_url = "/home/simon/Documents/vampire-guide/", start = "40.7466991,-73.9809522", end = "40.7478495,-73.9843726"):
filename_html = "map.html"
start_location = start.replace(' ', '').split(',')
start_location = tuple(map(float, start_location))
end_location = end.replace(' ', '').split(',')
end_location = tuple(map(float, end_location))
print(f"{start_location=}, {end_location=}")
try:
test(
html_output=filename_html,
start_location=start_location,
end_location=end_location
)
except Exception as e:
print(f"Error: {e}")
return {"Error": "this location is not supported, YET!"}
map_file = FileResponse(filename_html, headers={"Cache-Control": "no-cache"})
return map_file