diff --git a/src/nightserver.py b/src/nightserver.py index 22d6d3b..67c8899 100644 --- a/src/nightserver.py +++ b/src/nightserver.py @@ -4,9 +4,9 @@ import uuid app = Flask(__name__) # Vitals -vitalsHeartrate = -1 -vitalsOxygen = -1 -vitalsBodytemp = -1.0 +vitalsHeartrate = None +vitalsOxygen = None +vitalsBodytemp = None @app.route('/api/vitals/heartrate') def getVitalsHeartrate(): @@ -89,7 +89,7 @@ def setVitals(): return 'Information set successfully', 204 # Fitness -fitnessSteps = -1 +fitnessSteps = None @app.route('/api/fitness/steps') def getSteps(): @@ -220,8 +220,8 @@ def resetCyberwareMalfunction(): return 'Not Implemented', 501 # Environment data -environmentTemperature = -1 -environmentHumidity = -1 +environmentTemperature = None +environmentHumidity = None @app.route('/api/environment') def getEnvironment(): diff --git a/src/templates/index.html b/src/templates/index.html index 46976fe..18cec3c 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -65,6 +65,10 @@ border: 1px solid #F00; /* TODO: Remove this later */ } + #environmentTemperature { + text-align: right; + } + /* Below are all Map styling */ #map { margin-right: 2px; @@ -183,7 +187,7 @@

K.A.T.I.E.

-

0°C

+

@@ -215,6 +219,7 @@ // TODO: Make baseUrl be set by Flask var baseUrl = "http://localhost:5000"; var vitalsUrl = baseUrl + "/api/vitals"; + var environmentUrl = baseUrl + "/api/environment"; // Malfunction Messages (human-friendly) malfunctionMessage = [ "API Malfunction" ] @@ -226,7 +231,6 @@ } function setVitals(vitalsData) { - //var data = JSON.parse(vitalsData) heartrate = vitalsData["0"]["heartrate"]; oxygen = vitalsData["0"]["oxygen"]; bodytemp = vitalsData["0"]["bodytemp"]; @@ -237,29 +241,49 @@ } function setVitalsHeartrate(heartrate) { - if(heartrate > 0) { - document.getElementById("heartrate").innerHTML = "

Heartrate: " + heartrate + " BPM

"; - } else { + if(heartrate === null) { document.getElementById("heartrate").innerHTML = ""; + } else { + document.getElementById("heartrate").innerHTML = "

Heartrate: " + heartrate + " BPM

"; } } function setVitalsOxygen(oxygen) { - if(oxygen > 0) { - document.getElementById("oxygen").innerHTML = "

Oxygen: " + oxygen + "% O2

"; - } else { + if(oxygen === null) { document.getElementById("oxygen").innerHTML = ""; + } else { + document.getElementById("oxygen").innerHTML = "

Oxygen: " + oxygen + "% O2

"; } } function setVitalsBodytemp(bodytemp) { - if(bodytemp > 0) { - document.getElementById("bodyTemperature").innerHTML = "

Body Temp: " + bodytemp + "°C

"; - } else { + if(bodytemp === null) { document.getElementById("bodyTemperature").innerHTML = ""; + } else { + document.getElementById("bodyTemperature").innerHTML = "

Body Temp: " + bodytemp + "°C

"; } } + function setEnvironment(environmentData) { + temperature = environmentData["0"]["temperature"]; + humidity = environmentData["0"]["humidity"]; + + setEnvironmentTemperature(temperature); + setEnvironmentHumidity(humidity); + } + + function setEnvironmentTemperature(temperature) { + if(temperature === null) { + document.getElementById("environmentTemperature").innerHTML = "

"; + } else { + document.getElementById("environmentTemperature").innerHTML = "

" + temperature + "°C"; + } + } + + function setEnvironmentHumidity(humidity) { + + } + function updateAll() { $.get(vitalsUrl, (data, status) => { if(status == "success") { @@ -268,6 +292,14 @@ displayMalfunction(malfunctionMessage[apiMalfunctionI] + ": " + status); } }); + + $.get(environmentUrl, (data, status) => { + if(status == "success") { + setEnvironment(data); + } else { + displayMalfunction(malfunctionMessage[apiMalfunctionI] + ": " + status); + } + }); //stopInterval(t) } var t=setInterval(updateAll, 1000)