1+ import copy
12import os
23import json
34import io
5758
5859
5960@app .get ("/" )
60- def index (request : Request ) -> Response :
61+ def index (request : Request , template : str = "index.html" ) -> Response :
6162
6263 return templates .TemplateResponse (
63- "index.html" ,
64+ template ,
6465 {
6566 "request" : request ,
6667 "mvs_dev_version" : MVS_DEV_VERSION ,
@@ -92,6 +93,18 @@ async def simulate_json_variable_open_plan(request: Request):
9293 return await simulate_json_variable (request , queue = "open_plan" )
9394
9495
96+ @app .post ("/sendjson/openplan/sensitivity-analysis" )
97+ async def sensitivity_analysis_json_variable_open_plan (request : Request ):
98+
99+ input_dict = await request .json ()
100+
101+ sensitivity_analysis_id = run_sensitivity_analysis (
102+ input_json = json .dumps (input_dict )
103+ )
104+
105+ return await check_sensitivity_analysis (sensitivity_analysis_id )
106+
107+
95108@app .post ("/uploadjson/dev" )
96109def simulate_uploaded_json_files_dev (
97110 request : Request , json_file : UploadFile = File (...)
@@ -116,6 +129,38 @@ def simulate_uploaded_json_files_open_plan(
116129 return run_simulation_open_plan (request , input_json = json_content )
117130
118131
132+ @app .post ("/uploadjson-sensitivity-analysis/open_plan" )
133+ def sensitivity_analysis_uploaded_json_files_open_plan (
134+ request : Request , json_file : UploadFile = File (...)
135+ ) -> Response :
136+ """Receive mvs sensitivity analysis parameter in json post request and send it to simulator
137+ the value of `name` property of the input html tag should be `json_file` as the second
138+ argument of this function
139+ """
140+ json_content = jsonable_encoder (json_file .file .read ())
141+
142+ sensitivity_analysis_id = run_sensitivity_analysis (input_json = json_content )
143+
144+ return templates .TemplateResponse (
145+ "submitted_sensitivity_analysis.html" ,
146+ {"request" : request , "task_id" : sensitivity_analysis_id },
147+ )
148+
149+
150+ def run_sensitivity_analysis (input_json = None , queue = "open_plan" ):
151+ """Send a sensitivity analysis task to a celery worker"""
152+
153+ """Receive mvs simulation parameter in json post request and send it to simulator"""
154+ input_dict = json .loads (input_json )
155+
156+ sensitivity_analysis = celery_app .send_task (
157+ f"{ queue } .run_sensitivity_analysis" , args = [input_dict ], queue = queue , kwargs = {}
158+ )
159+ answer = sensitivity_analysis .id
160+
161+ return answer
162+
163+
119164def run_simulation (request : Request , input_json = None , queue = "dev" ) -> Response :
120165 """Send a simulation task to a celery worker"""
121166
0 commit comments