-
Notifications
You must be signed in to change notification settings - Fork 0
/
function_app.py
39 lines (31 loc) · 1.25 KB
/
function_app.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
"""
Azure Function app for demoland-engine.
To deploy manually, either follow the steps in the demoland-project book:
https://urban-analytics-technology-platform.github.io/demoland-project/book/developer_notes.html
or trigger the deploy_azure_functions GitHub Action:
https://github.com/Urban-Analytics-Technology-Platform/demoland-engine/actions/workflows/deploy_azure_functions.yaml
"""
import azure.functions as func
import json
import os
import logging
app = func.FunctionApp()
@app.function_name(name="DemoLandEngine")
@app.route(route="scenario", auth_level=func.AuthLevel.ANONYMOUS)
def test_function(req: func.HttpRequest) -> func.HttpResponse:
try:
req_body = req.get_json()
logging.info("Received request with body:")
logging.info(req_body)
scenario = req_body["scenario_json"]
model_identifier = req_body["model_identifier"]
os.environ["DEMOLAND"] = model_identifier
from demoland_engine.api import scenario_calc
pred_dict = scenario_calc(scenario, model_identifier)
return func.HttpResponse(json.dumps(pred_dict))
except Exception as e:
logging.error(e)
return func.HttpResponse(json.dumps({
"result": "error",
"message": str(e)
}))