tejovk311 commited on
Commit
1a62f66
·
verified ·
1 Parent(s): f8c03ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -18
app.py CHANGED
@@ -214,29 +214,24 @@ def dashboard():
214
  <input type="text" id="mrd" placeholder="Enter MRD number" />
215
  <button onclick="loadData()">Load</button>
216
  </div>
217
-
218
  <div class="grid-container">
219
  <div class="chart-box" id="hr_chart"></div>
220
  <div class="chart-box" id="rr_chart"></div>
221
  <div class="chart-box" id="spo2_chart"></div>
222
  <div class="chart-box" id="bp_chart"></div>
223
  </div>
224
-
225
  <script>
226
  async function loadData() {
227
  const mrd = document.getElementById("mrd").value.trim();
228
  if (!mrd) return alert("Please enter an MRD number.");
229
  const res = await fetch(`/vitals_data?mrd=${mrd}`);
230
  const data = await res.json();
231
-
232
  const timestamps = [], hr = [], rr = [], spo2 = [], sys = [], dia = [];
233
-
234
  for (let v of data) {
235
  timestamps.push(v.timestamp);
236
  hr.push(v.heart_rate);
237
  rr.push(v.respiratory_rate);
238
  spo2.push(v.oxygen_saturation);
239
-
240
  if (v.blood_pressure && v.blood_pressure.includes("/")) {
241
  const [s, d] = v.blood_pressure.split("/");
242
  sys.push(parseInt(s));
@@ -247,30 +242,79 @@ def dashboard():
247
  }
248
  }
249
 
250
- const layout = (title) => ({
251
- title,
 
252
  height: 280,
253
  margin: { t: 30, l: 40, r: 20, b: 40 },
254
  xaxis: { title: "Time", tickangle: -45 },
255
- yaxis: { title: "Value" }
256
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
 
258
  Plotly.newPlot("hr_chart", [{
259
- x: timestamps, y: hr, name: "Heart Rate", type: "scatter", mode: "lines+markers"
260
- }], layout("Heart Rate"));
 
 
 
 
261
 
262
  Plotly.newPlot("rr_chart", [{
263
- x: timestamps, y: rr, name: "Respiratory Rate", type: "scatter", mode: "lines+markers"
264
- }], layout("Respiratory Rate"));
 
 
 
 
265
 
266
  Plotly.newPlot("spo2_chart", [{
267
- x: timestamps, y: spo2, name: "Oxygen Saturation", type: "scatter", mode: "lines+markers"
268
- }], layout("Oxygen Saturation"));
 
 
 
 
269
 
270
  Plotly.newPlot("bp_chart", [
271
- { x: timestamps, y: sys, name: "Systolic", type: "scatter", mode: "lines+markers" },
272
- { x: timestamps, y: dia, name: "Diastolic", type: "scatter", mode: "lines+markers" }
273
- ], layout("Blood Pressure"));
 
 
 
 
 
 
 
 
 
 
 
 
274
  }
275
  </script>
276
  </body>
@@ -279,6 +323,7 @@ def dashboard():
279
  return render_template_string(html)
280
 
281
 
 
282
  if __name__ == '__main__':
283
  app.run(host='0.0.0.0', port=7860)
284
 
 
214
  <input type="text" id="mrd" placeholder="Enter MRD number" />
215
  <button onclick="loadData()">Load</button>
216
  </div>
 
217
  <div class="grid-container">
218
  <div class="chart-box" id="hr_chart"></div>
219
  <div class="chart-box" id="rr_chart"></div>
220
  <div class="chart-box" id="spo2_chart"></div>
221
  <div class="chart-box" id="bp_chart"></div>
222
  </div>
 
223
  <script>
224
  async function loadData() {
225
  const mrd = document.getElementById("mrd").value.trim();
226
  if (!mrd) return alert("Please enter an MRD number.");
227
  const res = await fetch(`/vitals_data?mrd=${mrd}`);
228
  const data = await res.json();
 
229
  const timestamps = [], hr = [], rr = [], spo2 = [], sys = [], dia = [];
 
230
  for (let v of data) {
231
  timestamps.push(v.timestamp);
232
  hr.push(v.heart_rate);
233
  rr.push(v.respiratory_rate);
234
  spo2.push(v.oxygen_saturation);
 
235
  if (v.blood_pressure && v.blood_pressure.includes("/")) {
236
  const [s, d] = v.blood_pressure.split("/");
237
  sys.push(parseInt(s));
 
242
  }
243
  }
244
 
245
+ // Layouts with fixed y-axis ranges
246
+ const layoutHR = {
247
+ title: "Heart Rate",
248
  height: 280,
249
  margin: { t: 30, l: 40, r: 20, b: 40 },
250
  xaxis: { title: "Time", tickangle: -45 },
251
+ yaxis: { title: "bpm", range: [40, 130] }
252
+ };
253
+
254
+ const layoutRR = {
255
+ title: "Respiratory Rate",
256
+ height: 280,
257
+ margin: { t: 30, l: 40, r: 20, b: 40 },
258
+ xaxis: { title: "Time", tickangle: -45 },
259
+ yaxis: { title: "breaths/min", range: [5, 30] }
260
+ };
261
+
262
+ const layoutSpO2 = {
263
+ title: "Oxygen Saturation",
264
+ height: 280,
265
+ margin: { t: 30, l: 40, r: 20, b: 40 },
266
+ xaxis: { title: "Time", tickangle: -45 },
267
+ yaxis: { title: "%", range: [60, 100] }
268
+ };
269
+
270
+ const layoutBP = {
271
+ title: "Blood Pressure",
272
+ height: 280,
273
+ margin: { t: 30, l: 40, r: 20, b: 40 },
274
+ xaxis: { title: "Time", tickangle: -45 },
275
+ yaxis: { title: "mmHg", range: [40, 200] }
276
+ };
277
 
278
  Plotly.newPlot("hr_chart", [{
279
+ x: timestamps,
280
+ y: hr,
281
+ name: "Heart Rate",
282
+ type: "scatter",
283
+ mode: "lines+markers"
284
+ }], layoutHR);
285
 
286
  Plotly.newPlot("rr_chart", [{
287
+ x: timestamps,
288
+ y: rr,
289
+ name: "Respiratory Rate",
290
+ type: "scatter",
291
+ mode: "lines+markers"
292
+ }], layoutRR);
293
 
294
  Plotly.newPlot("spo2_chart", [{
295
+ x: timestamps,
296
+ y: spo2,
297
+ name: "Oxygen Saturation",
298
+ type: "scatter",
299
+ mode: "lines+markers"
300
+ }], layoutSpO2);
301
 
302
  Plotly.newPlot("bp_chart", [
303
+ {
304
+ x: timestamps,
305
+ y: sys,
306
+ name: "Systolic",
307
+ type: "scatter",
308
+ mode: "lines+markers"
309
+ },
310
+ {
311
+ x: timestamps,
312
+ y: dia,
313
+ name: "Diastolic",
314
+ type: "scatter",
315
+ mode: "lines+markers"
316
+ }
317
+ ], layoutBP);
318
  }
319
  </script>
320
  </body>
 
323
  return render_template_string(html)
324
 
325
 
326
+
327
  if __name__ == '__main__':
328
  app.run(host='0.0.0.0', port=7860)
329