Skip to content

Commit 4dad8e0

Browse files
authored
Version 0.3.1.
2 parents a4d30e2 + f65a453 commit 4dad8e0

File tree

3 files changed

+47
-36
lines changed

3 files changed

+47
-36
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@abi-software/simulationvuer",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"private": false,
55
"scripts": {
66
"serve": "vue-cli-service serve --mode static",

src/components/SimulationVuer.vue

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<el-container class="plot-vuer">
2323
<Running :active.sync="runningActive" :is-full-page="runningFullPage" :color="runningColor" />
2424
<PlotVuer v-show="simulationValid" class="plot-vuer" :dataInput="data" :plotType="'plotly-only'" />
25-
<p v-show="!simulationValid" class="default error"><span class="error">Error:</span> {{ errorMessage }}.</p>
25+
<p v-show="!simulationValid" class="default error"><span class="error">Error:</span> <span v-html="errorMessage"></span>.</p>
2626
</el-container>
2727
</el-container>
2828
</div>
@@ -96,52 +96,63 @@ export default {
9696
runSimulation() {
9797
this.runningActive = true;
9898
99-
var model_url = "https://models.physiomeproject.org/e/611/HumanSAN_Fabbri_Fantini_Wilders_Severi_2017.cellml";
100-
var json_config = {
101-
simulation: {
102-
"Ending point": 3,
103-
"Point interval": 0.001,
99+
var data = {
100+
model_url: "https://models.physiomeproject.org/e/611/HumanSAN_Fabbri_Fantini_Wilders_Severi_2017.cellml",
101+
json_config: {
102+
simulation: {
103+
"Ending point": 3,
104+
"Point interval": 0.001,
105+
},
106+
output: ["Membrane/V"],
104107
},
105-
output: ["Membrane/V"],
106108
};
107109
108-
if (this.mode !== 0) {
109-
// Mode 1: stellate stimulation.
110-
// Mode 2: vagal stimulation.
110+
// Notes:
111+
// - this.mode:
112+
// - 0: normal sinus rhythm;
113+
// - 1: stellate stimulation; and
114+
// - 2: vagal stimulation.
115+
// - this.level has a value in [0; 10], but to compute ACh, we need a
116+
// value in [0; 1].
111117
112-
json_config["parameters"] = {
118+
if (this.mode !== 0) {
119+
data.json_config["parameters"] = {
113120
"Rate_modulation_experiments/Iso_1_uM": 1.0,
114121
"Rate_modulation_experiments/ACh": this.mode === 1 ? (1.0 - 0.1 * this.level) * 22.0e-6 : 22.0e-6 + 0.1 * this.level * (38.0e-6 - 22.0e-6),
115122
};
116123
}
117124
118-
fetch(this.apiLocation + "/simulation?model_url=" + encodeURIComponent(model_url) + "&json_config=" + encodeURIComponent(JSON.stringify(json_config)))
119-
.then((response) => {
120-
if (!response.ok) {
121-
this.runningActive = false;
122-
this.simulationValid = false;
123-
this.errorMessage = response.statusText.toLowerCase() + " (" + response.status + ")";
124-
125-
return;
126-
}
125+
var xmlhttp = new XMLHttpRequest();
127126
128-
return response.json();
129-
})
130-
.then((data) => {
127+
xmlhttp.open("POST", this.apiLocation + "/simulation", true);
128+
xmlhttp.setRequestHeader("Content-type", "application/json");
129+
xmlhttp.onreadystatechange = () => {
130+
if (xmlhttp.readyState === 4) {
131131
this.runningActive = false;
132-
this.simulationValid = data.status == "ok";
133132
134-
if (this.simulationValid) {
135-
this.data = [
136-
{
137-
x: data.results["environment/time"],
138-
y: data.results["Membrane/V"],
139-
},
140-
];
133+
if (xmlhttp.status === 200) {
134+
var data = JSON.parse(xmlhttp.responseText);
135+
136+
this.simulationValid = data.status === "ok";
137+
138+
if (this.simulationValid) {
139+
this.data = [
140+
{
141+
x: data.results["environment/time"],
142+
y: data.results["Membrane/V"],
143+
},
144+
];
145+
} else {
146+
this.errorMessage = data.description;
147+
}
141148
} else {
142-
this.errorMessage = data.description;
149+
this.simulationValid = false;
150+
151+
this.errorMessage = xmlhttp.statusText.toLowerCase() + " (<a href='https://httpstatuses.com/" + xmlhttp.status + "/' target='_blank'>" + xmlhttp.status + "</a>)";
143152
}
144-
});
153+
}
154+
};
155+
xmlhttp.send(JSON.stringify(data));
145156
},
146157
},
147158
};

0 commit comments

Comments
 (0)