|
22 | 22 | <el-container class="plot-vuer">
|
23 | 23 | <Running :active.sync="runningActive" :is-full-page="runningFullPage" :color="runningColor" />
|
24 | 24 | <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> |
26 | 26 | </el-container>
|
27 | 27 | </el-container>
|
28 | 28 | </div>
|
@@ -96,52 +96,63 @@ export default {
|
96 | 96 | runSimulation() {
|
97 | 97 | this.runningActive = true;
|
98 | 98 |
|
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"], |
104 | 107 | },
|
105 |
| - output: ["Membrane/V"], |
106 | 108 | };
|
107 | 109 |
|
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]. |
111 | 117 |
|
112 |
| - json_config["parameters"] = { |
| 118 | + if (this.mode !== 0) { |
| 119 | + data.json_config["parameters"] = { |
113 | 120 | "Rate_modulation_experiments/Iso_1_uM": 1.0,
|
114 | 121 | "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),
|
115 | 122 | };
|
116 | 123 | }
|
117 | 124 |
|
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(); |
127 | 126 |
|
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) { |
131 | 131 | this.runningActive = false;
|
132 |
| - this.simulationValid = data.status == "ok"; |
133 | 132 |
|
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 | + } |
141 | 148 | } 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>)"; |
143 | 152 | }
|
144 |
| - }); |
| 153 | + } |
| 154 | + }; |
| 155 | + xmlhttp.send(JSON.stringify(data)); |
145 | 156 | },
|
146 | 157 | },
|
147 | 158 | };
|
|
0 commit comments