Skip to content

Commit

Permalink
Merge pull request #1277 from StochSS/live-graphing
Browse files Browse the repository at this point in the history
Live graphing for previews
  • Loading branch information
briandrawert authored Nov 10, 2021
2 parents 4555d88 + eafbfd2 commit b77ad45
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
7 changes: 6 additions & 1 deletion client/pages/model-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,22 @@ let ModelEditor = PageView.extend({
errorCB(err, response, body);
}
else if(!body.Running){
Plotly.purge(this.queryByHook('preview-plot-container'));
if(body.Results.timeout){
$(this.queryByHook('model-timeout-message')).collapse('show');
}
this.plotResults(body.Results.results);
}else{
if(body.Results) {
Plotly.purge(this.queryByHook('preview-plot-container'));
this.plotResults(body.Results.results);
}
this.getResults();
}
},
error: errorCB
});
}, 2000);
}, 1000);
},
handlePresentationClick: function (e) {
let errorMsg = $(this.queryByHook("error-detected-msg"));
Expand Down
4 changes: 4 additions & 0 deletions stochss/handlers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ async def get(self):
target = self.get_query_argument(name="target", default=None)
resp = {"Running":False, "Outfile":outfile, "Results":""}
if run_cmd == "start":
model = StochSSModel(path=path)
if os.path.exists(f".{model.get_name()}-preview.json"):
os.remove(f".{model.get_name()}-preview.json")
exec_cmd = ['/stochss/stochss/handlers/util/scripts/run_preview.py',
f'{path}', f'{outfile}']
if target is not None:
Expand All @@ -229,6 +232,7 @@ async def get(self):
log.debug(f"Results for the model preview: {results}")
if results is None:
resp['Running'] = True
resp['Results'] = model.get_live_results()
log.info("The preview is still running")
else:
resp['Results'] = results
Expand Down
4 changes: 3 additions & 1 deletion stochss/handlers/util/ensemble_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ def run(self, preview=False, verbose=True):
if preview:
if verbose:
log.info(f"Running {self.g_model.name} preview simulation")
results = self.g_model.run(timeout=5)
live_file = f".{self.g_model.name}-preview.json"
options = {"file_path": live_file}
results = self.g_model.run(timeout=60, live_output="graph", live_output_options=options)
if verbose:
log.info(f"{self.g_model.name} preview simulation has completed")
log.info(f"Generate result plot for {self.g_model.name} preview")
Expand Down
22 changes: 22 additions & 0 deletions stochss/handlers/util/stochss_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,28 @@ def convert_to_spatial(self):
return {"Message":message, "File":s_file}, {"spatial":model, "path":s_path}


def get_live_results(self):
'''
Get the live output figure for the preview.
Attributes
----------
'''
file_name = f".{self.get_name()}-preview.json"
try:
with open(file_name, "r") as live_fig:
fig = json.load(live_fig)
fig["config"] = {
"displayModeBar": True,
"responsive": True
}
return {"results": fig, "timeout":False}
except FileNotFoundError:
return ""
except json.decoder.JSONDecodeError:
return ""


def get_notebook_data(self):
'''
Get the needed data for converting to notebook
Expand Down

0 comments on commit b77ad45

Please sign in to comment.